How to set moov atom position when encoding video using ffmpeg in C ++

I encode some h264 video into mp4 container using ffmpeg in C ++. But as a result of the video, put the moov atom (or metadata?) At the end of the video file, this is bad for Internet streaming. So how can I set the position of the moov atom to the front?

+4
source share
2 answers

You need to use the faststart ffmpeg flag to place the moov atom at the beginning of the MP4 file . The flag is explained here . Programmatically, you need to set a flag in the context of the output, here is an example code and its work for me,

AVFormatContext *outFormatCtx;

// Write MOOV atom at the begining of the MP4 file
MOVMuxContext *mov = NULL;

mov = (MOVMuxContext *)outFormatCtx->priv_data;
mov->flags |= FF_MOV_FLAG_FASTSTART;
+2
source

MOVMuxContext . API . - AVDictionary:

AVDictionary* options = nullptr;
av_dict_set( &options, "movflags", "faststart", 0 );
avio_open2(..., &options);
+2

All Articles