Append video frames to mp4 while playing

Go To


I need to append video frames taken from stream to existing mp4 file. I found that I need to use mdat and stco atom to update chunks table. Is it posible to append new frames/chunks at all? I need to do this in ios app.

2012-04-04 17:04
by Sergey Zenchenko


Such appending is possible, but it may not be practical -- especially if you are wanting to add one frame at a time.

MP4 is very much a "baked" format that is difficult to modify after it has been generated. This is because the structural data in the "moov" box contains file offsets to important media data in the "mdat" box. If the moov box is positioned before the mdat box (common to allow progressive download), then any data added to the moov box (i.e. references to new keyframes in your appended video) will push the mdat box further away. Not only would you have to rewrite the file, but you'd need to update all the file offsets accordingly. (Perhaps there are some clever tricks for keeping the moov box size constant...) If the mdat box is positioned first, the operation would still be awkward because you'd need to copy the moov box into memory, append your new video to the end of the mdat, update moov fields accordingly, and append the new moov box.

If you can gather all new video frames, and at the end of the recording add them during a rewrite operation, this may be workable. You could also look into Fragmented MP4 (using "moof" boxes), but I'm not sure how widespread the support for reading such files is.

2012-04-25 16:44
by David Simmons