@Override protected void _parseDetails(ByteBuffer content) { while (content.remaining() >= 4) { trackIds = Mp4Arrays.copyOfAndAppend(trackIds, new long[]{IsoTypeReader.readUInt32(content)}); } }
protected Box[] createFragment(StreamingTrack streamingTrack, List<StreamingSample> samples) { nextFragmentCreateStartTime.get(streamingTrack); tfraOffsets.put(streamingTrack, Mp4Arrays.copyOfAndAppend(tfraOffsets.get(streamingTrack), bytesWritten)); tfraTimes.put(streamingTrack, Mp4Arrays.copyOfAndAppend(tfraTimes.get(streamingTrack), nextFragmentCreateStartTime.get(streamingTrack))); LOG.trace("Container created"); Box moof = createMoof(streamingTrack, samples); LOG.trace("moof created"); Box mdat = createMdat(samples); LOG.trace("mdat created"); if (LOG.isDebugEnabled()) { double duration = nextSampleStartTime.get(streamingTrack) - nextFragmentCreateStartTime.get(streamingTrack); LOG.debug("created fragment for " + streamingTrack + " of " + (duration / streamingTrack.getTimescale()) + " seconds"); } return new Box[]{moof, mdat}; }
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(8); dataSource.read((ByteBuffer) byteBuffer.rewind()); byteBuffer.position(6); dataReferenceIndex = IsoTypeReader.readUInt16(byteBuffer); byte[] namespaceBytes = new byte[0]; int read; while ((read = Channels.newInputStream(dataSource).read()) != 0) { namespaceBytes = Mp4Arrays.copyOfAndAppend(namespaceBytes, (byte) read); } namespace = Utf8.convert(namespaceBytes); byte[] schemaLocationBytes = new byte[0]; while ((read = Channels.newInputStream(dataSource).read()) != 0) { schemaLocationBytes = Mp4Arrays.copyOfAndAppend(schemaLocationBytes, (byte) read); } schemaLocation = Utf8.convert(schemaLocationBytes); byte[] auxiliaryMimeTypesBytes = new byte[0]; while ((read = Channels.newInputStream(dataSource).read()) != 0) { auxiliaryMimeTypesBytes = Mp4Arrays.copyOfAndAppend(auxiliaryMimeTypesBytes, (byte) read); } auxiliaryMimeTypes = Utf8.convert(auxiliaryMimeTypesBytes); initContainer(dataSource, contentSize - (header.remaining() + namespace.length() + schemaLocation.length() + auxiliaryMimeTypes.length() + 3), boxParser); }
protected void writeChunkContainer(ChunkContainer chunkContainer) throws IOException { TrackBox tb = trackBoxes.get(chunkContainer.streamingTrack); ChunkOffsetBox stco = Path.getPath(tb, "mdia[0]/minf[0]/stbl[0]/stco[0]"); assert stco != null; stco.setChunkOffsets(Mp4Arrays.copyOfAndAppend(stco.getChunkOffsets(), bytesWritten + 8)); write(sink, chunkContainer.mdat); }
chunkOffsetBox.setChunkOffsets(Mp4Arrays.copyOfAndAppend(chunkOffsetBox.getChunkOffsets(), offset));
/** * {@inheritDoc} */ public long[] sampleNumbers(Track track) { long[] segmentStartSamples = new long[]{1}; long[] sampleDurations = track.getSampleDurations(); long[] syncSamples = track.getSyncSamples(); long timescale = track.getTrackMetaData().getTimescale(); double time = 0; for (int i = 0; i < sampleDurations.length; i++) { time += (double) sampleDurations[i] / timescale; if (time >= fragmentLength && (syncSamples == null || Arrays.binarySearch(syncSamples, i + 1) >= 0)) { if (i > 0) { segmentStartSamples = Mp4Arrays.copyOfAndAppend(segmentStartSamples, i + 1); } time = 0; } } return segmentStartSamples; } }
sampleDurations = Mp4Arrays.copyOfAndAppend(sampleDurations, startTime - mediaTimestampUs); samples.add(EMPTY_SAMPLE); sampleDurations = Mp4Arrays.copyOfAndAppend(sampleDurations, endTime - startTime); VTTCueBox vttCueBox = new VTTCueBox(); if (settings != null) {
pictureOrderCounts = Mp4Arrays.copyOfAndAppend(pictureOrderCounts, picOrderCntMsb + picOrderCountLsb); prevPicOrderCntLsb = picOrderCountLsb; prevPicOrderCntMsb = picOrderCntMsb; pictureOrderCounts = Mp4Arrays.copyOfAndAppend(pictureOrderCounts, samples.size());
refIndex++; syncSampleTimes = Mp4Arrays.copyOfAndAppend(syncSampleTimes, refTime);
protected Box createMvhd() { MovieHeaderBox mvhd = new MovieHeaderBox(); mvhd.setVersion(1); mvhd.setCreationTime(creationTime); mvhd.setModificationTime(creationTime); long[] timescales = new long[0]; long maxTrackId = 0; double duration = 0; for (StreamingTrack streamingTrack : source) { duration = Math.max((double) nextSampleStartTime.get(streamingTrack) / streamingTrack.getTimescale(), duration); timescales = Mp4Arrays.copyOfAndAppend(timescales, streamingTrack.getTimescale()); maxTrackId = Math.max(streamingTrack.getTrackExtension(TrackIdTrackExtension.class).getTrackId(), maxTrackId); } mvhd.setTimescale(Mp4Math.lcm(timescales)); mvhd.setDuration((long) (Mp4Math.lcm(timescales) * duration)); // find the next available trackId mvhd.setNextTrackId(maxTrackId + 1); return mvhd; }
stbl.addBox(stss); stss.setSampleNumber(Mp4Arrays.copyOfAndAppend(stss.getSampleNumber(), sampleNumber)); stsz.setSampleSizes(Mp4Arrays.copyOfAndAppend(stsz.getSampleSizes(), sampleSizes));
protected Box createMvhd() { MovieHeaderBox mvhd = new MovieHeaderBox(); mvhd.setVersion(1); mvhd.setCreationTime(creationTime); mvhd.setModificationTime(creationTime); mvhd.setDuration(0);//no duration in moov for fragmented movies long[] timescales = new long[0]; long maxTrackId = 0; for (StreamingTrack streamingTrack : source) { timescales = Mp4Arrays.copyOfAndAppend(timescales, streamingTrack.getTimescale()); maxTrackId = Math.max(streamingTrack.getTrackExtension(TrackIdTrackExtension.class).getTrackId(), maxTrackId); } mvhd.setTimescale(Mp4Math.lcm(timescales)); // find the next available trackId mvhd.setNextTrackId(maxTrackId + 1); return mvhd; }
long time_code = (last_sync_point * vop_time_increment_resolution + (vop_time_increment % vop_time_increment_resolution)); if (last_time_code != -1) { decodingTimes = Mp4Arrays.copyOfAndAppend(decodingTimes, new long[]{time_code - last_time_code}); decodingTimes = Mp4Arrays.copyOfAndAppend(decodingTimes, new long[]{decodingTimes[decodingTimes.length - 1]});
syncSamples = Mp4Arrays.copyOfAndAppend(syncSamples, sampleNumber);
@Override protected void _parseDetails(ByteBuffer content) { while (content.remaining() >= 4) { trackIds = Mp4Arrays.copyOfAndAppend(trackIds, new long[]{IsoTypeReader.readUInt32(content)}); } }
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(8); dataSource.read((ByteBuffer) byteBuffer.rewind()); byteBuffer.position(6); dataReferenceIndex = IsoTypeReader.readUInt16(byteBuffer); byte[] namespaceBytes = new byte[0]; int read; while ((read = Channels.newInputStream(dataSource).read()) != 0) { namespaceBytes = Mp4Arrays.copyOfAndAppend(namespaceBytes, (byte) read); } namespace = Utf8.convert(namespaceBytes); byte[] schemaLocationBytes = new byte[0]; while ((read = Channels.newInputStream(dataSource).read()) != 0) { schemaLocationBytes = Mp4Arrays.copyOfAndAppend(schemaLocationBytes, (byte) read); } schemaLocation = Utf8.convert(schemaLocationBytes); byte[] auxiliaryMimeTypesBytes = new byte[0]; while ((read = Channels.newInputStream(dataSource).read()) != 0) { auxiliaryMimeTypesBytes = Mp4Arrays.copyOfAndAppend(auxiliaryMimeTypesBytes, (byte) read); } auxiliaryMimeTypes = Utf8.convert(auxiliaryMimeTypesBytes); initContainer(dataSource, contentSize - (header.remaining() + namespace.length() + schemaLocation.length() + auxiliaryMimeTypes.length() + 3), boxParser); }
chunkOffsetBox.setChunkOffsets(Mp4Arrays.copyOfAndAppend(chunkOffsetBox.getChunkOffsets(), offset));
sampleDurations = Mp4Arrays.copyOfAndAppend(sampleDurations, startTime - mediaTimestampUs); samples.add(EMPTY_SAMPLE); sampleDurations = Mp4Arrays.copyOfAndAppend(sampleDurations, endTime - startTime); VTTCueBox vttCueBox = new VTTCueBox(); if (settings != null) {
/** * {@inheritDoc} */ public long[] sampleNumbers(Track track) { long[] segmentStartSamples = new long[]{1}; long[] sampleDurations = track.getSampleDurations(); long[] syncSamples = track.getSyncSamples(); long timescale = track.getTrackMetaData().getTimescale(); double time = 0; for (int i = 0; i < sampleDurations.length; i++) { time += (double) sampleDurations[i] / timescale; if (time >= fragmentLength && (syncSamples == null || Arrays.binarySearch(syncSamples, i + 1) >= 0)) { if (i > 0) { segmentStartSamples = Mp4Arrays.copyOfAndAppend(segmentStartSamples, i + 1); } time = 0; } } return segmentStartSamples; } }
pictureOrderCounts = Mp4Arrays.copyOfAndAppend(pictureOrderCounts, picOrderCntMsb + picOrderCountLsb); prevPicOrderCntLsb = picOrderCountLsb; prevPicOrderCntMsb = picOrderCntMsb; pictureOrderCounts = Mp4Arrays.copyOfAndAppend(pictureOrderCounts, samples.size());