[Libav-user] newb mp4 question

Dan Haddix dan6992 at hotmail.com
Thu Oct 6 00:38:06 CEST 2011

MP4 files contain something called a MOOV atom, which contains vital information about the file that is needed for playback. The MOOV atom is not written until you call av_write_trailer. And even then it's written to the very end of the file which makes it so you can't stream the file. There is another chunk of code in FFmpeg called QTFastStart which moves the MOOV atom to the start of the file, which in turn makes it possible to stream the file, but you still need a finished file before you can call it. So it's really only meant for streaming complete files from a server to a player.

If you need to remux and stream in realtime then you'd be better off using another format. Transport streams are the best for streaming. They have no header or footer and can be picked up at any point in the stream without issue. This is why broadcasters use TS for digital TV signals.


> Date: Wed, 5 Oct 2011 22:18:24 +0000
> From: atlithorn at gmail.com
> To: libav-user at ffmpeg.org
> Subject: [Libav-user] newb mp4 question
> Hi, I'm trying to remux an flv muxed aac stream using the mp4 muxer.
> (movenc.c). It works fine so long as I call av_write_trailer.
> Problem is I also need to remux live (long running) streams, how would
> I go about that. Currently a skeleton of my code looks like this
> init_input
> init_output
> do{
>   av_init_packet(&ipacket)
>   av_read_frame(iFormatCtx, &ipacket);
>   if(packet.stream_index == audioStrem){
>     av_init_packet(&opacket);
>     copy stuff around, code borrowed from ffmpeg.c
>     av_write_frame(oFormatCtx, &opacket);
>     av_free_packet(&opacket);
>   }
>   av_free_packet(&ipacket);
> }while(stuff is incoming);
> av_write_trailer(oFormatCtx);
> I was hoping I could buffer av_write_frame calls and write out to a
> client but the client can't understand the file without the trailer it
> seems. I'm new to this stuff so I was hoping someone could point me in
> the right direction.
> Before you ask, I am streaming to the Android MediaPlayer so my format
> options are a little limited.
> Thanks,
> Atli.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20111005/44b1ea9b/attachment.html>

More information about the Libav-user mailing list