[libav-api] Muxing video encoded with x264 and faac

FG home at fgda.pl
Wed Aug 28 20:52:19 CEST 2013


There was no response to my question but I have found the culprit
on my own. I'll post it here for posterity. The playback problems
were all caused by wrong initialization order. A silly mistake.
I have originally opened the codecs before setting their flags:

     av_dict_set(&voptions, "profile", "baseline", 0);
     if (avcodec_open2(vctx, vcodec, &voptions) < 0) exit(7);
     if (avcodec_open2(actx, acodec, 0) < 0) exit(8);
     if (avio_open(&ctx->pb, filename, AVIO_FLAG_WRITE) < 0) exit(9);

     outformat->video_codec = vcodec->id;
     outformat->audio_codec = acodec->id;

     if (ctx->oformat->flags & AVFMT_GLOBALHEADER) {
         vctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
         actx->flags |= CODEC_FLAG_GLOBAL_HEADER;
     }


The correct order, however, is the following one:

     outformat->video_codec = vcodec->id;
     outformat->audio_codec = acodec->id;

     if (ctx->oformat->flags & AVFMT_GLOBALHEADER) {
         vctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
         actx->flags |= CODEC_FLAG_GLOBAL_HEADER;
     }

     av_dict_set(&voptions, "profile", "baseline", 0);
     if (avcodec_open2(vctx, vcodec, &voptions) < 0) exit(7);
     if (avcodec_open2(actx, acodec, 0) < 0) exit(8);
     if (avio_open(&ctx->pb, filename, AVIO_FLAG_WRITE) < 0) exit(9);


After this modification the playback problems have vanished.




More information about the libav-api mailing list