[Libav-user] How to create fragmented mp4

Szanto Cosmin cosmin.szanto at vitheia.com
Mon Jun 13 16:28:02 CEST 2016


Hi,

  I'm trying to create a mp4 fragmented file. I managed to convert a
file using the ffmpeg command:
   
    ffmpeg -re -i in.mp4 -f mp4 -movflags frag_keyframe+empty_moov out.mp4

  But I cannot set frag_keyframe and empty_moov options to my context
using C++:

    AVOutputFormat* outputFormat = av_guess_format("mp4", 0, 0);
    if (!outputFormat) {
      return false;
    }

    context =  avformat_alloc_context();
    if (!context) {
      return false;
    }

    AVFormatContext* outputFormat->video_codec = AV_CODEC_ID_H264;
    context->oformat = outputFormat;

    int ret = 0;
    if (ret = av_opt_set(context, "movflags", "+empty_moov", 0) != 0) {
     // This fails with ret 1
    }

  I also tried to pass this flags with a dict to avformat_write_header

    if (av_dict_set(&options, "movflags", "+frag_keyframe+empty_moov",
0) < 0) {
      std::cout << "av_dict_set empty_moov failed" << std::endl;
      return;
    }

    ret = avformat_write_header(context, &options);

  This works but I believe that it does not have effect because if i run
the ffmpeg command the output file is significantly larger.
  Do you know what is the correct way of creating a mp4 with the
necessary files or where can I find documentation/examples?
 

Thanks,

Cosmin


More information about the Libav-user mailing list