From 65c625a382f6c956a7ad4ad009459fd7afb77a46 Mon Sep 17 00:00:00 2001 From: Alex Luccisano Date: Thu, 6 Aug 2026 11:38:49 -0400 Subject: [PATCH] obs-ffmpeg: Fix B-frame offset calculation in AMF AVC and AV1 encoders in AMF that support B-frames were incrementing `dts_offset` even when B-frames were set to 0. For AVC, adjust the `dts_offset` only when B-frames are supported and are greater than 0, and clamp to maximum supported. For AV1, remove the dts_offset code completely because it is being ignored anyway. AV1 handles B-frames and offsets differently; refer to [1] for details. [1]: https://github.com/obsproject/obs-studio/pull/10996 --- plugins/obs-ffmpeg/texture-amf.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/plugins/obs-ffmpeg/texture-amf.cpp b/plugins/obs-ffmpeg/texture-amf.cpp index b2eaddf94bbd51..58b19be65b5df8 100644 --- a/plugins/obs-ffmpeg/texture-amf.cpp +++ b/plugins/obs-ffmpeg/texture-amf.cpp @@ -1720,8 +1720,8 @@ static void amf_avc_create_internal(amf_base *enc, obs_data_t *settings) amf_int64 b_max = 0; if (get_avc_property(enc, B_PIC_PATTERN, &b_frames) && - get_avc_property(enc, MAX_CONSECUTIVE_BPICTURES, &b_max)) { - enc->dts_offset = b_frames + 1; + get_avc_property(enc, MAX_CONSECUTIVE_BPICTURES, &b_max) && b_frames > 0) { + enc->dts_offset = std::min(b_frames, b_max) + 1; } else { enc->dts_offset = 0; } @@ -2543,18 +2543,6 @@ static void amf_av1_create_internal(amf_base *enc, obs_data_t *settings) if (res == AMF_OK && p.type == AMF_VARIANT_INTERFACE) { enc->header = AMFBufferPtr(p.pInterface); } - - if (enc->bframes_supported) { - amf_int64 b_frames = 0; - amf_int64 b_max = 0; - - if (get_av1_property(enc, B_PIC_PATTERN, &b_frames) && - get_av1_property(enc, MAX_CONSECUTIVE_BPICTURES, &b_max)) { - enc->dts_offset = b_frames + 1; - } else { - enc->dts_offset = 0; - } - } } static void *amf_av1_create_texencode(obs_data_t *settings, obs_encoder_t *encoder)