View Full Version : Starting to play mp4 before end of encoding

10th April 2011, 12:45

I am writing a server software that creates an mp4 file (using ffmpeg libraries) and starts downloading it immediately to the player, before the encoder finishes the encoding.The intention is that the player will be able to start playing before the encoding ends. When I did this with an flv file, it worked fine. Now that I'm doing it with an mp4 file, it didn't work...

It seems that an mp4 file cannot be played until the encoder has finished encoding.
If I understand correctly, there are several problems:

1. The moov chunk should be in the beginning of the file - this can be fixed.
2. Every chunk should have its size in the beginning of the chunk, including the mdat chunk. So the total size of encoded packets should be known before I start delivering them.
3. The moov chunk contains offsets and sizes of all the packets in the stream (stsz, stco chunks) which should also be available before delivering the encoded data.

Is there a way to create a valid mp4 which can start playing before the encoding ends?
If so is it possible with ffmpeg or any other public software?

Thanks and regards

VFR maniac
11th April 2011, 07:58
If you start to play a movie from the very head, it can be done with movie fragments feature.
[ftyp][moov+mdat]-[moof+mdat]-[moof+mdat]- ...
Basically, data offsets and timelines are provided by each movie fragment (moof box), however what codec is used in the streams is answered by stsd box in moov box, so you need parse at least this moov box at the first.

Movie fragments feature is implemented by GPAC and Bento4 AFAIK.
Ffmpeg and libav support only reading side, so you can't use them as movie fragment writer.
GPAC supports aggressively movie fragments (I don't know this is buggy or not now. The last time I saw, the implementation is buggy around media duration).
They are adding gradually DASH (Dynamic Adaptive Streaming over HTTP) feature.
The discussion of DASH have been continued to publish by MPEG.

Well, I am also working implementation of movie fragments feature for my project, this will be push soon.

11th April 2011, 08:48
Well, I am also working implementation of movie fragments feature for my project, this will be push soon.

You mean L-SMASH? Are there any plans on making a standalone cli version (like mp4box for GPAC)? The last time I looked I only saw the patched x264cli.

11th April 2011, 11:31
Thanks for the answer!
Seems interesting - I'll try it.
Does anyone know if iPhone can play a fragmented mp4?