obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

Encoder Group Resynchronisation

Open derrod opened this issue 1 year ago • 0 comments

Description

Adds a mechanism to resynchronise grouped encoders if keyframes are no longer aligned to the same PTS interval.

Resynchronisation works by determining a future PTS all encoders are expected to hit, and adding a flag to that frame instructing the encoder to force an IDR frame, thus starting a new GOP and bringing encoders back in-sync.

This PR adds a mechanism to adds the following on top of #10096:

  • OBS_ENCODER_CAP_FORCE_IDR to indicate that an encoder supports forcing IDR frames
  • Adds obs_frame_flags to encoder_frame/encoder_texture
    • Only OBS_FRAME_FORCE_IDR exists for now
  • Repurposes the existing check for frame misalignments to determine a future resync point
  • Implements forcing IDR frames for x264 and NVENC

Motivation and Context

With the goal of #10096 (included here) being to allow encoders to skip frames to avoid the death spiral after GPU stalls while being close to the maximum throughput, we need a means of resyncing encoders if frames are skipped.

While this PR only implements this feature for x264 and NVENC, all the other relevant encoders (QSV, AMF, VideoToolbox) also support forcing/requesting IDR frames.

How Has This Been Tested?

Has been tested in one form or another during my personal test streams going back to January.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

derrod avatar Jun 07 '24 14:06 derrod