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

obs-ffmpeg: Linux NVENC texture encoder #10133

Merged
merged 1 commit into from
Mar 31, 2024

Conversation

derrod
Copy link
Member

@derrod derrod commented Jan 24, 2024

Description

WIP NVENC texture encoder for Linux, based on software encoder introduced in #10122 and OpenGL texture encoding libobs changes in #8312.

This PR really is just the last commit.

Superseedes/closes #4974

Motivation and Context

Gotta go fast.

How Has This Been Tested?

OBS Flatpak on openSUSE Tumbleweed with NVIDIA 545 drivers.

Types of changes

  • New feature (non-breaking change which adds functionality)

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.

@derrod derrod added Seeking Testers Build artifacts on CI Linux Affects Linux labels Jan 24, 2024
@derrod derrod changed the title Nvenc linux texture encoder obs-ffmpeg: Linux NVENC texture encoder (attempt 2) Jan 24, 2024
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from ddfba60 to 09f93f4 Compare January 24, 2024 03:06
@ryzendew
Copy link

Does it have av1?

@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 3 times, most recently from 867e42f to 88b01a6 Compare January 26, 2024 04:36
@derrod
Copy link
Member Author

derrod commented Jan 26, 2024

Short AV1 clip recorded using the Flatpak build on openSUSE with the new texture sharing encoder:

control_nvenc_av1.mp4

@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 3 times, most recently from 68fdadf to 3ab4df1 Compare January 27, 2024 02:50
@derrod
Copy link
Member Author

derrod commented Jan 27, 2024

With #8312 merged I'll take this out of draft. It works and the PR can now be reviewed independently.

@derrod derrod marked this pull request as ready for review January 27, 2024 02:51
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from 3ab4df1 to 98a52ef Compare January 27, 2024 03:02
@derrod derrod changed the title obs-ffmpeg: Linux NVENC texture encoder (attempt 2) obs-ffmpeg: Linux NVENC texture encoder Jan 27, 2024
@kkartaltepe
Copy link
Collaborator

Fallback encoders dont appear to be private and can be seen in the options, also the default encoder doesnt fallback and just fails with an error when using the wrong gpu. (couldnt actually get obs to load on the gpu atm so ill test the working path later).

@derrod
Copy link
Member Author

derrod commented Jan 29, 2024

Fallback encoders dont appear to be private and can be seen in the options, also the default encoder doesnt fallback and just fails with an error when using the wrong gpu. (couldnt actually get obs to load on the gpu atm so ill test the working path later).

Yep, I haven't implemented an automatic fallback yet so I left the non-texture encoders visible. Gotta figure out how to determine if OBS and the CUDA context run on the same GPU.

@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from 98a52ef to 739388b Compare January 30, 2024 03:17
@derrod
Copy link
Member Author

derrod commented Jan 30, 2024

Updated with a commit adding a check on startup to see if mapping an OpenGL texture created by the OBS graphics context succeeds on any CUDA device. If not, only fallback encoders will be supported, otherwise the CUDA device where mapping succeeded will be used when starting a texture encoder.

This also hides the fallback encoders by default on Linux as well.

@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 5 times, most recently from f614193 to b99a1b3 Compare January 31, 2024 05:51
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from b99a1b3 to a5d154a Compare January 31, 2024 23:30
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 8 times, most recently from 31363d8 to 6e1f0e5 Compare February 8, 2024 21:32
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 2 times, most recently from 38593ed to 840c342 Compare February 14, 2024 02:48
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch 2 times, most recently from 823fb04 to f758db4 Compare February 25, 2024 01:18
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from f758db4 to 79e8e5a Compare March 8, 2024 23:15
@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from 79e8e5a to 701ba0b Compare March 9, 2024 16:51
@Lain-B Lain-B self-assigned this Mar 16, 2024
@Bleuzen
Copy link

Bleuzen commented Mar 17, 2024

Did some more testing, this time with recording. There is a noticeable change in the bitrates used. I set up OBS with and without this patch the same way and used a VLC source with the same lossless video playing for reproducible input

For example when recording NVENC H264 in Simple Mode / "High Quality, Medium File Size"...

Current OBS:

With this PR:

Same with HEVC

Before:

After:

~ 75 % increase in file size

Also in "Advanced" Output Mode with same CQP Levels

Didn't really expect that, not sure if this is supposed to happen or a bug

@tt2468
Copy link
Member

tt2468 commented Mar 17, 2024

Did some more testing, this time with recording. There is a noticeable change in the bitrates used. I set up OBS with and without this patch the same way and used a VLC source with the same lossless video playing for reproducible input

For example when recording NVENC H264 in Simple Mode / "High Quality, Medium File Size"...

Current OBS:

With this PR:

Same with HEVC

Before:

After:

~ 75 % increase in file size

Also in "Advanced" Output Mode with same CQP Levels

Didn't really expect that, not sure if this is supposed to happen or a bug

The encoder implementations are different, but nothing should have been touched in relation to the bitrate regulation. That's likely just a pre-existing difference between the ffmpeg and texture encoders.

In order to get useful results, this texture encoder PR must be tested against the current texture encoder available on Windows.

@ochilan
Copy link

ochilan commented Mar 18, 2024

@Bleuzen Could you provide details about each of the resulting files, for example using a tool like "mediainfo"? I wonder if there are unintended technical differences like e.g. chroma subsampling (4:2:0 vs. 4:4:4).

@realnc
Copy link

realnc commented Mar 19, 2024

Applied on top of 30.1.0 and it works fine for me. I can record AV1 with NVENC and it's fast too!

Now if we only had CQ support instead of CQP, that would make OBS the perfect capture tool for image quality.

@ochilan
Copy link

ochilan commented Mar 19, 2024

The encoder implementations are different, but nothing should have been touched in relation to the bitrate regulation. That's likely just a pre-existing difference between the ffmpeg and texture encoders.

In order to get useful results, this texture encoder PR must be tested against the current texture encoder available on Windows.

I was curious and compared stock OBS 30.1 under Linux, stock 30.1 under Windows, and 30.1 + texture encoder under Linux (H.264, CQP 20, with as similar settings as possible). The resulting file sizes were:

Stock 30.1 Linux: 109.1 MiB
Stock 30.1 Windows: 149 MiB
Patched 30.1 Linux: 147.5 MiB

So there seems to be a difference before and after the patch under Linux, but the larger file size is actually comparable to what the Windows version already produces.

(As far as I could tell, the metadata of all videos is identical by the way, except for the video bitrates.)

@derrod
Copy link
Member Author

derrod commented Mar 20, 2024

I'm not sure if there are any differences with CQP handling in FFmpeg vs OBS, but I also don't think that's worth investigating/worrying about at this time. For now we don't want to break anything on the Windows side, but this PR is a stepping stone to a larger rework that may change things.

@derrod derrod force-pushed the nvenc-linux-texture-encoder branch from 701ba0b to 9726308 Compare March 28, 2024 21:05
@Lain-B Lain-B force-pushed the nvenc-linux-texture-encoder branch from 9726308 to 989af07 Compare March 31, 2024 09:13
@Lain-B Lain-B merged commit 3a10355 into obsproject:master Mar 31, 2024
14 checks passed
@derrod derrod deleted the nvenc-linux-texture-encoder branch March 31, 2024 09:53
@RytoEX RytoEX added this to the OBS Studio (Next Version) milestone Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Affects Linux Seeking Testers Build artifacts on CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants