[libav-api] mp4 faststart - viewing files while rendering

Adam Wilt adam at adamwilt.com
Thu Sep 19 21:28:09 CEST 2013

> I'd really like if it were possible for the user to /view the files while they are rendering...
> I have read up on the faststart mechanism, and the qt-faststart tool.

Faststart essentially moves the clip metadata, including frame-addressing info, to the start of the file, so that the file can start playing before it has been entirely read. But that alone isn't sufficient; you have to *create* that information and write it on-the-fly as you go.

When I worked for a broadcast video server company, we had our own, bespoke Quicktime library, and we needed to do a read-while-writing implementation to allow live editing of video streams. 

In general terms, we reserved enough space at the head of the file for the track tables with frame pointers (excuse my imprecise terminology; it's been a few years) for the longest duration file we allowed (the AVOption ‘-moov_size bytes’ may be the sort of thing you need for this, along with faststart). As we recorded the file, we'd periodically update the track tables with the current clip length and the addresses of all current frames; in essence we'd "finalize" or "close" the movie every few seconds. That was the key part: ‘-movflags empty_moov’ creates an emty moov, but you need update it with non-emty data as you go along, providing a consistent roadmap to the frames written so far.

In our implementation this only worked for intraframe-only, constant-bit-rate codecs like DV and uncompressed, where each frame stood alone and had a fixed size. It was easy to calculate offsets for each frame so we could rewrite the track tables quickly and easily. Long-GOP and VBR codecs were mot suitable for this sort of operation, at least in our implementation.

I know that other broadcast-oriented systems from server and asset-management providers now offer similar capabilities, so it's certainly possible, and it's not rocket science. However I don't know if the libav framework as it currently stands is capable of this sort of dynamic updating.

Adam Wilt
technical services: consulting / coding / camerawork
Mountain View CA USA

More information about the libav-api mailing list