[Libav-user] Possible bug in transcoding.c example
Nikolai Lineckiy
nikolai.lineckiy at yandex.ru
Mon Dec 25 10:41:39 EET 2017
Hi. Recently I needed to write transcoder based on ffmpeg libraries. I started with transcoding.c example and soon noticed that result video files are not playable in Apple's QuickTime player. I found out that issue was in following piece of code in function open_output_file:
/* Third parameter can be used to pass settings to encoder */
ret = avcodec_open2(enc_ctx, encoder, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot open video encoder for stream #%u\n", i);
return ret;
}
ret = avcodec_parameters_from_context(out_stream->codecpar, enc_ctx);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to copy encoder parameters to output stream #%u\n", i);
return ret;
}
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
The problem was in assigning AV_CODEC_FLAG_GLOBAL_HEADER to encoder flags: if I set it before calling avcodec_open2, QuickTime handles result files normally. Otherwise it refuses to play video stream.
I'm not an experienced ffmpeg hacker, so I need your opinion on this. Is this really a bug or am I missing something?
More information about the Libav-user
mailing list