Skip to content

obs-ffmpeg: Fix B-frame offset calculation in AMF - #13762

Open
lexano-ivs wants to merge 1 commit into
obsproject:masterfrom
amazon-contributing:lexano/amd-b-frame
Open

obs-ffmpeg: Fix B-frame offset calculation in AMF#13762
lexano-ivs wants to merge 1 commit into
obsproject:masterfrom
amazon-contributing:lexano/amd-b-frame

Conversation

@lexano-ivs

@lexano-ivs lexano-ivs commented Aug 6, 2026

Copy link
Copy Markdown

AMF AVC and AV1 encoders support B-frames in more recent GPUs, however the enc->dts_offset was being incremented even when b-frames were set to 0.

For AVC, this caused IVS Stages to reject the stream because the offset is used to infer the presence of B-frames, which are not supported by IVS Stages (and WebRTC).

For AV1, the code is not needed and was removed. See below for details.

Description

For AVC, only increment the enc->dts_offset if the AMF encoder supports B-frames and b-frames are greater than 0.

For AV1, remove the dts_offset calculation from amf_av1_create_internal. This code was dead — convert_to_encoder_packet already excludes AV1 from the DTS subtraction (added in b2d83efcf, PR #10996), since AV1 handles frame reordering transparently and doesn't require decode-order delay compensation at the mux layer.

The AV1 dts_offset block was introduced in 1a2f8c284 (AMD AV1 B-frame support) as a mechanical copy of the AVC pattern without accounting for this exclusion. This aligns with the NVENC implementation (plugins/obs-nvenc/nvenc.c), which similarly guards its DTS adjustment with if (enc->codec != CODEC_AV1) and has no offset calculation in its AV1 path.

Motivation and Context

The original bug report at #13723 provides the details.

How Has This Been Tested?

I created an IVS Stage and reproduced the problem initially, then implemented the fix and tested on the same stage. There were no disconnects after the fix was in place.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

amf_int64 b_max = 0;

if (get_av1_property(enc, B_PIC_PATTERN, &b_frames) &&
get_av1_property(enc, MAX_CONSECUTIVE_BPICTURES, &b_max)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For AV1 this code shouldn't exist at all because it doesn't use frame-reordering. See also a similar change for NVIDIA here: #10996

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]: obsproject#10996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants