From 74981b1d362ec911a4f8a5e2ea59a919e788582c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 2 Feb 2020 16:28:22 -0800 Subject: [PATCH] FFmpeg: Fix crash when -strict -2 is needed for vcodec or container --- CHANGES | 1 + src/feature/ffmpeg/ffmpeg-encoder.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index f3d498f4c..a2faa02f8 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Emulation fixes: Other fixes: - Core: Fix race condition initializing thread proxy - Core: Fix integer overflow in ELF loading + - FFmpeg: Fix crash when -strict -2 is needed for vcodec or container - Qt: Only dynamically reset video scale if a game is running - Qt: Fix race condition with proxied video events - Qt: Fix color selection in asset view (fixes mgba.io/i/1648) diff --git a/src/feature/ffmpeg/ffmpeg-encoder.c b/src/feature/ffmpeg/ffmpeg-encoder.c index b327925a3..04ab843b3 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.c +++ b/src/feature/ffmpeg/ffmpeg-encoder.c @@ -445,8 +445,11 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { encoder->sinkFrame = avcodec_alloc_frame(); #endif } - - if (avcodec_open2(encoder->video, vcodec, 0) < 0) { + AVDictionary* opts = 0; + av_dict_set(&opts, "strict", "-2", 0); + int res = avcodec_open2(encoder->video, vcodec, &opts); + av_dict_free(&opts); + if (res < 0) { FFmpegEncoderClose(encoder); return false; } @@ -466,7 +469,11 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { #endif } - if (avio_open(&encoder->context->pb, outfile, AVIO_FLAG_WRITE) < 0 || avformat_write_header(encoder->context, 0) < 0) { + AVDictionary* opts = 0; + av_dict_set(&opts, "strict", "-2", 0); + bool res = avio_open(&encoder->context->pb, outfile, AVIO_FLAG_WRITE) < 0 || avformat_write_header(encoder->context, &opts) < 0; + av_dict_free(&opts); + if (res) { FFmpegEncoderClose(encoder); return false; }