Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs: Add OBS_ENCODER_CAP_SCALING cap #10951

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

tt2468
Copy link
Member

@tt2468 tt2468 commented Jul 6, 2024

Description

Adds a new encoder cap which tells libobs that rather than scaling video frames in software, the encoder is capable of scaling them via its own (presumably more efficient) means.

An encoder may implement this cap by comparing the VOI of its assigned video_t and the results of obs_encoder_get_width/height(). If the width/height values differ, then the encoder is being asked by libobs to self-scale, and the resolution in VOI will be the raw frame size, with the ...get_width/height() being the intended output resolution of the encoder.

It is important to note that GPU rescaling mode will take priority over self-scaling. If GPU rescaling is enabled, the encoder will never be asked to self-scale.

Motivation and Context

This is useful for discrete hardware encoders, where they might have fixed-function video scaling logic that is highly efficient and fast. Additionally, this feature allows a hardware device which is encoding a full ABR ladder of tracks to be smart and only copy a video frame from GPU -> Host -> Device once for the entire ladder, rather than once for every track.

How Has This Been Tested?

Tested with a plugin of mine for the MA35D card. Frames received by the encoder are the normal output resolution of OBS, regardless of what the "scaled" size is (this change does not make the UI aware of self-scaling, so this requires custom encoder management).

Ubuntu 22.04

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Documentation (a change to documentation pages)

Checklist:

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

@tt2468 tt2468 added the New Feature New feature or plugin label Jul 6, 2024
@Lain-B Lain-B added this to the OBS Studio 31 milestone Jul 6, 2024
@tt2468 tt2468 force-pushed the feature/encoder-cap-self-scale branch from 6f8366e to 3dc97f1 Compare August 3, 2024 06:29
libobs/obs-encoder.h Outdated Show resolved Hide resolved
This logic would previously have written any changed scale resolution
set by the encoder in the `.get_video_info` callback back to the
encoder, however this functionality was "broken" by
20d8779. In reality, this would have
never worked with texture encoders or with GPU rescaling enabled, and
probably would have had odd side effects for CPU rescaling, too. It's
best just to remove this functionality.
Adds a new encoder cap which tells libobs that rather than scaling
video frames in software, the encoder is capable of scaling them via
its own (presumably more efficient) means.

An encoder may implement this cap by comparing the VOI of its assigned
`video_t` and the results of `obs_encoder_get_width/height()`. If the
width/height values differ, then the encoder is being asked by libobs
to self-scale, and the resolution in VOI will be the raw frame size,
with the `...get_width/height()` being the intended output resolution
of the encoder.

It is important to note that GPU rescaling mode will take priority
over self-scaling. If GPU rescaling is enabled, the encoder will never
be asked to self-scale.

This is useful for discrete hardware encoders, where they might have
fixed-function video scaling logic that is highly efficient and fast.
Additionally, this feature allows a hardware device which is encoding
a full ABR ladder of tracks to be smart and only copy a video frame
from GPU -> Host -> Device once for the entire ladder, rather than
once for every track.
@tt2468 tt2468 force-pushed the feature/encoder-cap-self-scale branch from 3dc97f1 to 9a309c3 Compare August 11, 2024 00:26
@tt2468 tt2468 changed the title libobs: Add OBS_ENCODER_CAP_SELF_SCALE cap libobs: Add OBS_ENCODER_CAP_SCALING cap Aug 11, 2024
Copy link
Member

@derrod derrod left a comment

Choose a reason for hiding this comment

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

Seems fine to me now.

@RytoEX RytoEX merged commit 16f0bb6 into obsproject:master Aug 23, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature New feature or plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants