Skip to content

Commit beb18f6

Browse files
committed
Resolve deprecation warning with newer FFmpeg
1 parent 44101ca commit beb18f6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

libminiscope/videowriter.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,27 @@ void VideoWriter::initializeInternal()
238238
// set codec parameters
239239
d->cctx->codec_id = codecId;
240240
d->cctx->codec_type = AVMEDIA_TYPE_VIDEO;
241-
if (vcodec->pix_fmts != nullptr)
242-
d->cctx->pix_fmt = vcodec->pix_fmts[0];
243241
d->cctx->time_base = av_inv_q(d->fps);
244242
d->cctx->width = d->width;
245243
d->cctx->height = d->height;
246244
d->cctx->framerate = d->fps;
247245
d->cctx->workaround_bugs = FF_BUG_AUTODETECT;
248246

247+
#if LIBAVCODEC_VERSION_MAJOR >= 61
248+
const enum AVPixelFormat *fmts = nullptr;
249+
ret = avcodec_get_supported_config(d->cctx, nullptr, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void **)&fmts, nullptr);
250+
if (ret < 0 || fmts == nullptr) {
251+
std::cerr << "Failed to get supported pixel formats for codec " << vcodec->name << ": " << ret;
252+
d->cctx->pix_fmt = AV_PIX_FMT_YUV420P;
253+
} else {
254+
d->cctx->pix_fmt = fmts[0];
255+
}
256+
#else
257+
d->cctx->pix_fmt = AV_PIX_FMT_YUV420P;
258+
if (vcodec->pix_fmts != nullptr)
259+
d->cctx->pix_fmt = vcodec->pix_fmts[0];
260+
#endif
261+
249262
// We must set time_base on the stream as well, otherwise it will be set to default values for some container
250263
// formats. See https://projects.blender.org/blender/blender/commit/b2e067d98ccf43657404b917b13ad5275f1c96e2 for
251264
// details.

0 commit comments

Comments
 (0)