public static SampleSizesBox createSampleSizesBox2(int[] sizes) { SampleSizesBox stsz = new SampleSizesBox(new Header(fourcc())); stsz.sizes = sizes; stsz.count = sizes.length; return stsz; }
public int getFrameCount() { SampleSizesBox stsz = findFirst(this, SampleSizesBox.class, "mdia", "minf", "stbl", "stsz"); return stsz.getDefaultSize() != 0 ? stsz.getCount() : stsz.getSizes().length; }
private static void appendSampleSizes(TrakBox trakBox1, TrakBox trakBox2) { SampleSizesBox stsz1 = trakBox1.getStsz(); SampleSizesBox stsz2 = trakBox2.getStsz(); if (stsz1.getDefaultSize() != stsz2.getDefaultSize()) throw new IllegalArgumentException("Can't append to track that has different default sample size"); SampleSizesBox stszr; if (stsz1.getDefaultSize() > 0) { stszr = SampleSizesBox.createSampleSizesBox(stsz1.getDefaultSize(), stsz1.getCount() + stsz2.getCount()); } else { stszr = SampleSizesBox.createSampleSizesBox2(addAllInt(stsz1.getSizes(), stsz2.getSizes())); } NodeBox.findFirstPath(trakBox1, NodeBox.class, Box.path("mdia.minf.stbl")).replace("stsz", stszr); }
if (stsz.getDefaultSize() > 0) { size = getFrameSize(); } else { sizes = copyOfRange(stsz.getSizes(), sampleNo, sampleNo + sampleCount);
private boolean matchSampleSizes(TrakBox trakBox1, TrakBox trakBox2) { SampleSizesBox stsz1 = NodeBox.findFirstPath(trakBox1, SampleSizesBox.class, Box.path("mdia.minf.stbl.stsz")); SampleSizesBox stsz2 = NodeBox.findFirstPath(trakBox1, SampleSizesBox.class, Box.path("mdia.minf.stbl.stsz")); return stsz1.getDefaultSize() == stsz2.getDefaultSize(); }
public FramesMP4DemuxerTrack(MovieBox mov, TrakBox trak, SeekableByteChannel input) { super(trak); this.input = input; this.movie = mov; SampleSizesBox stsz = findFirst(trak, SampleSizesBox.class, "mdia", "minf", "stbl", "stsz"); SyncSamplesBox stss = Box.findFirst(trak, SyncSamplesBox.class, "mdia", "minf", "stbl", "stss"); SyncSamplesBox stps = Box.findFirst(trak, SyncSamplesBox.class, "mdia", "minf", "stbl", "stps"); CompositionOffsetsBox ctts = Box.findFirst(trak, CompositionOffsetsBox.class, "mdia", "minf", "stbl", "ctts"); compOffsets = ctts == null ? null : ctts.getEntries(); if (stss != null) { syncSamples = stss.getSyncSamples(); } if(stps != null) { partialSync = stps.getSyncSamples(); } sizes = stsz.getSizes(); maxSize = stsz.getMaxSize(); }
public SampleSizesBox() { super(new Header(fourcc())); }
stbl.add(new SampleSizesBox(frameSize, totalFrames)); stbl.add(new TimeToSampleBox(new TimeToSampleEntry[] { new TimeToSampleEntry(totalFrames, frameDuration) })); stbl.add(new ChunkOffsets64Box(chunkOffsets.toArray()));
public static long getSampleOffset(int sample, SampleToChunkBox stsc, ChunkOffsetsBox stco, SampleSizesBox stsz) { int chunkBySample = getChunkBySample(sample, stco, stsc); int firstSampleAtChunk = getFirstSampleAtChunk(chunkBySample, stsc, stco); long offset = stco.getChunkOffsets()[chunkBySample - 1]; int[] sizes = stsz.getSizes(); for (int i = firstSampleAtChunk; i < sample; i++) { offset += sizes[i]; } return offset; }
public long getSampleCount() { return NodeBox.findFirst(this, SampleSizesBox.class, "mdia", "minf", "stbl", "stsz").getCount(); }
public SampleSizesBox getSampleSizes(List<Chunk> chunks) { int nSamples = 0, prevSize = chunks.get(0).getSampleSize(); for (Chunk chunk : chunks) { nSamples += chunk.getSampleCount(); if (prevSize == 0 && chunk.getSampleSize() != 0) throw new RuntimeException("Mixed sample sizes not supported"); } if (prevSize > 0) return SampleSizesBox.createSampleSizesBox(prevSize, nSamples); int[] sizes = new int[nSamples]; int startSample = 0; for (Chunk chunk : chunks) { arraycopy(chunk.getSampleSizes(), 0, sizes, startSample, chunk.getSampleCount()); startSample += chunk.getSampleCount(); } return SampleSizesBox.createSampleSizesBox2(sizes); }
stbl.add(SampleSizesBox.createSampleSizesBox(frameSize, totalFrames)); stbl.add(TimeToSampleBox .createTimeToSampleBox(new TimeToSampleEntry[] { new TimeToSampleEntry(totalFrames, frameDuration) }));
stbl.add(SampleSizesBox.createSampleSizesBox2(sampleSizes.toArray())); stbl.add(TimeToSampleBox.createTimeToSampleBox(sampleDurations.toArray(new TimeToSampleEntry[] {}))); stbl.add(ChunkOffsets64Box.createChunkOffsets64Box(chunkOffsets.toArray()));
if (stsz.getDefaultSize() > 0) { size = getFrameSize(); } else { sizes = copyOfRange(stsz.getSizes(), sampleNo, sampleNo + sampleCount);
private int getFrameSize() { int size = stsz.getDefaultSize(); Box box = stsd.getBoxes().get(sampleToChunk[s2cIndex].getEntry() - 1); if (box instanceof AudioSampleEntry) { return ((AudioSampleEntry) box).calcFrameSize(); } return size; }
public FramesMP4DemuxerTrack(MovieBox mov, TrakBox trak, SeekableByteChannel input) { super(trak); this.input = input; this.movie = mov; SampleSizesBox stsz = findFirst(trak, SampleSizesBox.class, "mdia", "minf", "stbl", "stsz"); SyncSamplesBox stss = Box.findFirst(trak, SyncSamplesBox.class, "mdia", "minf", "stbl", "stss"); SyncSamplesBox stps = Box.findFirst(trak, SyncSamplesBox.class, "mdia", "minf", "stbl", "stps"); CompositionOffsetsBox ctts = Box.findFirst(trak, CompositionOffsetsBox.class, "mdia", "minf", "stbl", "ctts"); compOffsets = ctts == null ? null : ctts.getEntries(); if (stss != null) { syncSamples = stss.getSyncSamples(); } if(stps != null) { partialSync = stps.getSyncSamples(); } sizes = stsz.getSizes(); maxSize = stsz.getMaxSize(); }
public SampleSizesBox() { super(new Header(fourcc())); }
stbl.add(new SampleSizesBox(frameSize, totalFrames)); stbl.add(new TimeToSampleBox(new TimeToSampleEntry[] { new TimeToSampleEntry(totalFrames, frameDuration) })); stbl.add(new ChunkOffsets64Box(chunkOffsets.toArray()));
public static ByteBuffer getSampleData(int sample, File file) throws IOException { MovieBox moov = MP4Util.parseMovie(file); MediaInfoBox minf = moov.getAudioTracks().get(0).getMdia().getMinf(); ChunkOffsetsBox stco = NodeBox.findFirstPath(minf, ChunkOffsetsBox.class, Box.path("stbl.stco")); SampleToChunkBox stsc = NodeBox.findFirstPath(minf, SampleToChunkBox.class, Box.path("stbl.stsc")); SampleSizesBox stsz = NodeBox.findFirstPath(minf, SampleSizesBox.class, Box.path("stbl.stsz")); long sampleOffset = getSampleOffset(sample, stsc, stco, stsz); MappedByteBuffer map = NIOUtils.mapFile(file); map.position((int) sampleOffset); map.limit(map.position() + stsz.getSizes()[sample]); return map; }
public long getSampleCount() { return NodeBox.findFirst(this, SampleSizesBox.class, "mdia", "minf", "stbl", "stsz").getCount(); }