From e657e62c2950d32f285387ef8950a2ea99673113 Mon Sep 17 00:00:00 2001 From: rhutsAMD <71274498+rhutsAMD@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:35:03 -0500 Subject: [PATCH] obs-ffmpeg: Fix issue with B-frames introducing motion blur If a user sets both AdaptiveMiniGOP=true and EnablePreAnalysis=true in the AMF/FFmpeg options field, AMF will adaptively insert B-pictures, and no longer uses the fixed B pattern. For a fixed B-frames pattern, it is expected that increasing B-frames can cause a quality drop for certain content such as with high motion. AdaptiveMiniGOP is recommended when using B-frames to improve the quality in such cases. AdaptiveMiniGOP is dependent on PreAnalysis which means that trying to enable it without having PreAnalysis turned ON will have no negative effect (AdaptiveMiniGOP won't be enabled). --- plugins/obs-ffmpeg/texture-amf.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/obs-ffmpeg/texture-amf.cpp b/plugins/obs-ffmpeg/texture-amf.cpp index 079f3487d..826d669de 100644 --- a/plugins/obs-ffmpeg/texture-amf.cpp +++ b/plugins/obs-ffmpeg/texture-amf.cpp @@ -1396,9 +1396,17 @@ static bool amf_avc_init(void *data, obs_data_t *settings) int64_t bf = obs_data_get_int(settings, "bf"); if (enc->bframes_supported) { - set_avc_property(enc, MAX_CONSECUTIVE_BPICTURES, 3); + set_avc_property(enc, MAX_CONSECUTIVE_BPICTURES, bf); set_avc_property(enc, B_PIC_PATTERN, bf); + /* AdaptiveMiniGOP is suggested for some types of content such + * as those with high motion. This only takes effect if + * Pre-Analysis is enabled. + */ + if (bf > 0) { + set_avc_property(enc, ADAPTIVE_MINIGOP, true); + } + } else if (bf != 0) { warn("B-Frames set to %lld but b-frames are not " "supported by this device",