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;
MOVMuxContext *mov = NULL;
mov = (MOVMuxContext *)outFormatCtx->priv_data;
mov->flags |= FF_MOV_FLAG_FASTSTART;
source
share