Search code examples
c++ffmpegmp4

How to use ffmpeg faststart flag programmatically?


I try to convert videos for playback on Android using H264, AAC codecs and mp4 container. Video plays normaly with non-system players. But system player shows error "Can't play this video". I found out that the problem is in moov atom, which is writed in the end of the file. When I use "-movflags +faststart" ffmeg flag to convert video, it plays normal, but when I try to do that programmatically, it gives no result. I use following code:

av_dict_set( &dict, "movflags", "faststart", 0 );
ret = avformat_write_header( ofmt_ctx, &dict );

Solution

  • This code works fine:

    av_dict_set( &dict, "movflags", "faststart", 0 );
    ret = avformat_write_header( ofmt_ctx, &dict );
    

    But problem is not solved. I still can't play converted videos on Android devices.