Class StandardMp4Writer
- java.lang.Object
-
- org.mp4parser.streaming.output.mp4.DefaultBoxes
-
- org.mp4parser.streaming.output.mp4.StandardMp4Writer
-
- All Implemented Interfaces:
Closeable,AutoCloseable,SampleSink
public class StandardMp4Writer extends DefaultBoxes implements SampleSink
Creates an MP4 file with ftyp, mdat+, moov order. A very special property of this variant is that it written sequentially. You can start transferring the data while thesinkreceives it. (in contrast to typical implementations which need random access to write length fields at the beginning of the file)
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<StreamingTrack,Queue<org.mp4parser.streaming.output.mp4.StandardMp4Writer.ChunkContainer>>chunkBuffersBuffers segements until it's time for a segment to be written.protected Map<StreamingTrack,Long>chunkNumbersprotected Map<StreamingTrack,CountDownLatch>congestionControlprotected DatecreationTimeprotected Map<StreamingTrack,Long>nextChunkCreateStartTimeContains the start time of the next segment in line that will be created.protected Map<StreamingTrack,Long>nextChunkWriteStartTimeContains the start time of the next segment in line that will be written.protected Map<StreamingTrack,Long>nextSampleStartTimeContains the next sample's start time.static ObjectOBJprotected Map<StreamingTrack,List<StreamingSample>>sampleBuffersBuffers the samples per track until there are enough samples to form a Segment.protected Map<StreamingTrack,Long>sampleNumbersprotected WritableByteChannelsinkprotected List<StreamingTrack>sourceprotected Map<StreamingTrack,TrackBox>trackBoxes
-
Constructor Summary
Constructors Constructor Description StandardMp4Writer(List<StreamingTrack> source, WritableByteChannel sink)
-
Method Summary
Modifier and Type Method Description voidacceptSample(StreamingSample streamingSample, StreamingTrack streamingTrack)Adds a samples to the SampleSink.voidclose()Free all resources blocked and interrupts the process of writing the output.protected BoxcreateMdhd(StreamingTrack streamingTrack)protected BoxcreateMoov()protected BoxcreateMvhd()protected booleanisChunkReady(StreamingTrack streamingTrack, StreamingSample next)Tests if the currently received samples for a given track are already a 'chunk' as we want to have it.protected voidwrite(WritableByteChannel out, Box... boxes)protected voidwriteChunkContainer(org.mp4parser.streaming.output.mp4.StandardMp4Writer.ChunkContainer chunkContainer)-
Methods inherited from class org.mp4parser.streaming.output.mp4.DefaultBoxes
createDinf, createFtyp, createMdia, createMdiaHdlr, createMinf, createStbl, createTkhd, createTrak
-
-
-
-
Field Detail
-
OBJ
public static final Object OBJ
-
sink
protected final WritableByteChannel sink
-
source
protected List<StreamingTrack> source
-
creationTime
protected Date creationTime
-
congestionControl
protected Map<StreamingTrack,CountDownLatch> congestionControl
-
nextChunkCreateStartTime
protected Map<StreamingTrack,Long> nextChunkCreateStartTime
Contains the start time of the next segment in line that will be created.
-
nextChunkWriteStartTime
protected Map<StreamingTrack,Long> nextChunkWriteStartTime
Contains the start time of the next segment in line that will be written.
-
nextSampleStartTime
protected Map<StreamingTrack,Long> nextSampleStartTime
Contains the next sample's start time.
-
sampleBuffers
protected Map<StreamingTrack,List<StreamingSample>> sampleBuffers
Buffers the samples per track until there are enough samples to form a Segment.
-
trackBoxes
protected Map<StreamingTrack,TrackBox> trackBoxes
-
chunkBuffers
protected Map<StreamingTrack,Queue<org.mp4parser.streaming.output.mp4.StandardMp4Writer.ChunkContainer>> chunkBuffers
Buffers segements until it's time for a segment to be written.
-
chunkNumbers
protected Map<StreamingTrack,Long> chunkNumbers
-
sampleNumbers
protected Map<StreamingTrack,Long> sampleNumbers
-
-
Constructor Detail
-
StandardMp4Writer
public StandardMp4Writer(List<StreamingTrack> source, WritableByteChannel sink)
-
-
Method Detail
-
close
public void close() throws IOExceptionDescription copied from interface:SampleSinkFree all resources blocked and interrupts the process of writing the output. An implementation should flush all samples that have not yet been written and write the file footer - if exists - before actually freeing the resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSampleSink- Throws:
IOException- if closing fails
-
createMoov
protected Box createMoov()
-
createMvhd
protected Box createMvhd()
- Specified by:
createMvhdin classDefaultBoxes
-
write
protected void write(WritableByteChannel out, Box... boxes) throws IOException
- Throws:
IOException
-
isChunkReady
protected boolean isChunkReady(StreamingTrack streamingTrack, StreamingSample next)
Tests if the currently received samples for a given track are already a 'chunk' as we want to have it. The next sample will not be part of the chunk will be added to the fragment buffer later.- Parameters:
streamingTrack- track to testnext- the lastest samples- Returns:
- true if a chunk is to b e created.
-
writeChunkContainer
protected void writeChunkContainer(org.mp4parser.streaming.output.mp4.StandardMp4Writer.ChunkContainer chunkContainer) throws IOException- Throws:
IOException
-
acceptSample
public void acceptSample(StreamingSample streamingSample, StreamingTrack streamingTrack) throws IOException
Description copied from interface:SampleSinkAdds a samples to the SampleSink. This might or might not cause writing the sample any output stream or channel. Once this method is called theStreamingTrackmust be ready and accept calls to any method.- Specified by:
acceptSamplein interfaceSampleSink- Throws:
IOException- if writing (or reading) fails.
-
createMdhd
protected Box createMdhd(StreamingTrack streamingTrack)
- Specified by:
createMdhdin classDefaultBoxes
-
-