From 17461b5d114ffe6bdeb3251d2591f7e7e8589c47 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Sat, 1 Feb 2020 11:22:41 +0800 Subject: [PATCH] ffmpeg: Correctly set pixel format While YUV420P is widely used, not all encoders accept it (e.g. Intel QSV only accepts NV12). We should use the codec's preferred pixel format instead as we need to rescale the frame anyway. --- src/core/dumping/ffmpeg_backend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/dumping/ffmpeg_backend.cpp b/src/core/dumping/ffmpeg_backend.cpp index 2e7ecbba5..f3c3e236a 100644 --- a/src/core/dumping/ffmpeg_backend.cpp +++ b/src/core/dumping/ffmpeg_backend.cpp @@ -126,7 +126,7 @@ bool FFmpegVideoStream::Init(AVFormatContext* format_context, AVOutputFormat* ou codec_context->time_base.num = 1; codec_context->time_base.den = 60; codec_context->gop_size = 12; - codec_context->pix_fmt = AV_PIX_FMT_YUV420P; + codec_context->pix_fmt = codec->pix_fmts ? codec->pix_fmts[0] : AV_PIX_FMT_YUV420P; if (output_format->flags & AVFMT_GLOBALHEADER) codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;