FFmpeg: Fix crash when -strict -2 is needed for vcodec or container

This commit is contained in:
Vicki Pfau 2020-02-02 16:28:22 -08:00
parent 0fe93dd5d2
commit 74981b1d36
2 changed files with 11 additions and 3 deletions

View File

@ -10,6 +10,7 @@ Emulation fixes:
Other fixes: Other fixes:
- Core: Fix race condition initializing thread proxy - Core: Fix race condition initializing thread proxy
- Core: Fix integer overflow in ELF loading - 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: Only dynamically reset video scale if a game is running
- Qt: Fix race condition with proxied video events - Qt: Fix race condition with proxied video events
- Qt: Fix color selection in asset view (fixes mgba.io/i/1648) - Qt: Fix color selection in asset view (fixes mgba.io/i/1648)

View File

@ -445,8 +445,11 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
encoder->sinkFrame = avcodec_alloc_frame(); encoder->sinkFrame = avcodec_alloc_frame();
#endif #endif
} }
AVDictionary* opts = 0;
if (avcodec_open2(encoder->video, vcodec, 0) < 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); FFmpegEncoderClose(encoder);
return false; return false;
} }
@ -466,7 +469,11 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
#endif #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); FFmpegEncoderClose(encoder);
return false; return false;
} }