LizardByte / Sunshine

Self-hosted game stream host for Moonlight.
http://app.lizardbyte.dev/Sunshine/
GNU General Public License v3.0
19.72k stars 955 forks source link

Unable to decode AV1 stream generated by NVENC on sunshine linux in capable hardware #3331

Closed LuisB79 closed 2 weeks ago

LuisB79 commented 2 weeks ago

Is there an existing issue for this?

Is your issue described in the documentation?

Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

Sunshine on arch produces an AV1 stream that it's not able to be decoded on a snapdragon 8 gen 3 soc, no matter what resolution is set or what framerate is set

Expected Behavior

Sunshine on arch producing an AV1 stream that's able to decode on snapdragon 8 gen 3 soc.

Additional Context

I installed as per the documentation instructions, this is not the aur package. On windows the stream is being produced by nvenc and it's able to be decoded on the same hardware One noticeable difference is that in windows there's a message saying "NvEnc: created encoder AV1 p1 two-pass rfi", where as in linux there isn't one

Settings on arch X11 NVFBC as capture NVENC as encoder

Client moonlight-android running on a zfold 6 Client works fine with h265 or h264

related: https://github.com/moonlight-stream/moonlight-android/issues/1434

Host Operating System

Linux

Operating System Version

Arch

Architecture

amd64/x86_64

Sunshine commit or version

Version v2024.1025.12635

Package

Linux - LizardByte/pacman-repo

GPU Type

Nvidia

GPU Model

4080 mobile

GPU Driver/Mesa Version

565.57.01

Capture Method

NvFBC (Linux)

Config

qp = 24
upnp = enabled
resolutions = [
    1920x1080
]
encoder = nvenc
capture = nvfbc

Apps

No response

Relevant log output

[2024-10-26 20:29:26.392]: Info: Sunshine version: v2024.1025.12635
[2024-10-26 20:29:26.392]: Info: Package Publisher: LizardByte
[2024-10-26 20:29:26.392]: Info: Publisher Website: https://app.lizardbyte.dev
[2024-10-26 20:29:26.392]: Info: Get support: https://app.lizardbyte.dev/support
[2024-10-26 20:29:26.417]: Info: System tray created
[2024-10-26 20:29:26.835]: Info: Found [1] outputs
[2024-10-26 20:29:26.835]: Info: Virtual Desktop: 2560x1440
[2024-10-26 20:29:26.835]: Info: XrandR: available
[2024-10-26 20:29:26.835]: Info: -- Output --
[2024-10-26 20:29:26.835]: Info:   Resolution: 2560x1440
[2024-10-26 20:29:26.835]: Info:   Offset: 0x0
[2024-10-26 20:29:26.855]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:26.870]: Warning: Gamepad ds5 is disabled due to Permission denied
[2024-10-26 20:29:26.870]: Info: Trying encoder [nvenc]
[2024-10-26 20:29:26.870]: Info: Screencasting with NvFBC
[2024-10-26 20:29:26.971]: Info: Creating encoder [h264_nvenc]
[2024-10-26 20:29:26.971]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:26.971]: Info: Color depth: 8-bit
[2024-10-26 20:29:26.971]: Info: Color range: JPEG
[2024-10-26 20:29:27.321]: Info: Creating encoder [hevc_nvenc]
[2024-10-26 20:29:27.321]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:27.321]: Info: Color depth: 8-bit
[2024-10-26 20:29:27.321]: Info: Color range: JPEG
[2024-10-26 20:29:27.582]: Info: Creating encoder [av1_nvenc]
[2024-10-26 20:29:27.582]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:27.582]: Info: Color depth: 8-bit
[2024-10-26 20:29:27.582]: Info: Color range: JPEG
[2024-10-26 20:29:27.862]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:27.862]: Info: Screencasting with NvFBC
[2024-10-26 20:29:27.964]: Info: Creating encoder [hevc_nvenc]
[2024-10-26 20:29:27.964]: Info: Color coding: SDR (Rec. 709)
[2024-10-26 20:29:27.964]: Info: Color depth: 10-bit
[2024-10-26 20:29:27.964]: Info: Color range: JPEG
[2024-10-26 20:29:27.984]: Error: cuda::cuda_t doesn't support any format other than AV_PIX_FMT_NV12
[2024-10-26 20:29:28.224]: Info: Creating encoder [av1_nvenc]
[2024-10-26 20:29:28.224]: Info: Color coding: SDR (Rec. 709)
[2024-10-26 20:29:28.224]: Info: Color depth: 10-bit
[2024-10-26 20:29:28.224]: Info: Color range: JPEG
[2024-10-26 20:29:28.246]: Error: cuda::cuda_t doesn't support any format other than AV_PIX_FMT_NV12
[2024-10-26 20:29:28.504]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:28.504]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024-10-26 20:29:28.504]: Info: 
[2024-10-26 20:29:28.504]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2024-10-26 20:29:28.504]: Info: 
[2024-10-26 20:29:28.504]: Info: Found H.264 encoder: h264_nvenc [nvenc]
[2024-10-26 20:29:28.504]: Info: Found HEVC encoder: hevc_nvenc [nvenc]
[2024-10-26 20:29:28.504]: Info: Found AV1 encoder: av1_nvenc [nvenc]
[2024-10-26 20:29:28.506]: Info: Adding avahi service [REDACTED]
[2024-10-26 20:29:28.507]: Info: Configuration UI available at [https://localhost:47990]
[2024-10-26 20:29:29.477]: Info: Avahi service [REDACTED] successfully established.
[2024-10-26 20:29:36.512]: Warning: Couldn't discover any IPv4 UPNP devices
[2024-10-26 20:29:38.413]: Info: Trying encoder [nvenc]
[2024-10-26 20:29:38.413]: Info: Screencasting with NvFBC
[2024-10-26 20:29:38.570]: Info: Creating encoder [h264_nvenc]
[2024-10-26 20:29:38.570]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:38.570]: Info: Color depth: 8-bit
[2024-10-26 20:29:38.570]: Info: Color range: JPEG
[2024-10-26 20:29:38.831]: Info: Creating encoder [hevc_nvenc]
[2024-10-26 20:29:38.831]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:38.831]: Info: Color depth: 8-bit
[2024-10-26 20:29:38.831]: Info: Color range: JPEG
[2024-10-26 20:29:39.093]: Info: Creating encoder [av1_nvenc]
[2024-10-26 20:29:39.093]: Info: Color coding: SDR (Rec. 601)
[2024-10-26 20:29:39.093]: Info: Color depth: 8-bit
[2024-10-26 20:29:39.093]: Info: Color range: JPEG
[2024-10-26 20:29:39.373]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:39.373]: Info: Screencasting with NvFBC
[2024-10-26 20:29:39.483]: Info: Creating encoder [hevc_nvenc]
[2024-10-26 20:29:39.483]: Info: Color coding: SDR (Rec. 709)
[2024-10-26 20:29:39.483]: Info: Color depth: 10-bit
[2024-10-26 20:29:39.483]: Info: Color range: JPEG
[2024-10-26 20:29:39.504]: Error: cuda::cuda_t doesn't support any format other than AV_PIX_FMT_NV12
[2024-10-26 20:29:39.743]: Info: Creating encoder [av1_nvenc]
[2024-10-26 20:29:39.743]: Info: Color coding: SDR (Rec. 709)
[2024-10-26 20:29:39.743]: Info: Color depth: 10-bit
[2024-10-26 20:29:39.743]: Info: Color range: JPEG
[2024-10-26 20:29:39.767]: Error: cuda::cuda_t doesn't support any format other than AV_PIX_FMT_NV12
[2024-10-26 20:29:40.024]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:40.024]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024-10-26 20:29:40.024]: Info: 
[2024-10-26 20:29:40.024]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2024-10-26 20:29:40.024]: Info: 
[2024-10-26 20:29:40.024]: Info: Found H.264 encoder: h264_nvenc [nvenc]
[2024-10-26 20:29:40.024]: Info: Found HEVC encoder: hevc_nvenc [nvenc]
[2024-10-26 20:29:40.024]: Info: Found AV1 encoder: av1_nvenc [nvenc]
[2024-10-26 20:29:40.024]: Info: Executing [Desktop]
[2024-10-26 20:29:40.172]: Info: New streaming session started [active sessions: 1]
[2024-10-26 20:29:40.207]: Info: CLIENT CONNECTED
[2024-10-26 20:29:40.502]: Info: Found [1] outputs
[2024-10-26 20:29:40.502]: Info: Virtual Desktop: 2560x1440
[2024-10-26 20:29:40.502]: Info: XrandR: available
[2024-10-26 20:29:40.502]: Info: -- Output --
[2024-10-26 20:29:40.502]: Info:   Resolution: 2560x1440
[2024-10-26 20:29:40.502]: Info:   Offset: 0x0
[2024-10-26 20:29:40.523]: Error: Couldn't release NvFBC context from current thread: 
[2024-10-26 20:29:40.523]: Info: Screencasting with NvFBC
[2024-10-26 20:29:40.630]: Info: Creating encoder [av1_nvenc]
[2024-10-26 20:29:40.630]: Info: Color coding: SDR (Rec. 709)
[2024-10-26 20:29:40.630]: Info: Color depth: 8-bit
[2024-10-26 20:29:40.630]: Info: Color range: MPEG
[2024-10-26 20:29:40.647]: Info: Setting default sink to: [sink-sunshine-stereo]
[2024-10-26 20:29:40.648]: Info: Found default monitor by name: sink-sunshine-stereo.monitor
[2024-10-26 20:29:40.660]: Info: Opus initialized: 48 kHz, 2 channels, 512 kbps (total), LOWDELAY
[2024-10-26 20:29:45.660]: Info: Opening UI from system tray
[2024-10-26 20:29:45.668]: Info: Opened url [https://localhost:47990]
[2024-10-26 20:29:46.924]: Info: Web UI: [127.0.0.1] -- not authorized
[2024-10-26 20:30:12.727]: Info: CLIENT DISCONNECTED
cgutman commented 2 weeks ago

I think I narrowed down the problem to the presence of Padding OBUs. It seems like Qualcomm did not test their decoder with AV1 bitstreams containing padding OBUs (common for CBR encoding, but not otherwise).

We don't have control of padding OBUs for all encoders (notably not FFmpeg NVENC or VAAPI), but we might be able to strip them off after each encoded frame.

LuisB79 commented 2 weeks ago

I think I narrowed down the problem to the presence of Padding OBUs. It seems like Qualcomm did not test their decoder with AV1 bitstreams containing padding OBUs (common for CBR encoding, but not otherwise).

We don't have control of padding OBUs for all encoders (notably not FFmpeg NVENC or VAAPI), but we might be able to strip them off after each encoded frame.

Does padding obus are also present when a stream is created in the windows app?, because i can decode the stream on the android client when the stream is created in windows, i was thinking that maybe it was something with a color space mismatch, or something nvenc specific, also i noticed that in line 344 of nvenc.cpp theres a ? sign and the android logs said something along the lines of "[v4lav1DL_26] ? is not a supported pixel format!"

cgutman commented 2 weeks ago

Does padding obus are also present when a stream is created in the windows app?

No, because our standalone NVENC implementation used on Windows disables padding OBUs. The bitstream produced in both cases is completely valid, but Qualcomm's decoder does not properly implement the AV1 specification and fails to decode a valid bitstream if it contains padding OBUs.

I confirmed the issue was only the padding OBUs by patching FFmpeg to avoid setting NV_ENC_CONFIG_AV1::enableBitstreamPadding = 1. This was enough to enable my Fold 6 to decode the stream successfully.

LuisB79 commented 2 weeks ago

Does padding obus are also present when a stream is created in the windows app?

No, because our standalone NVENC implementation used on Windows disables padding OBUs. The bitstream produced in both cases is completely valid, but Qualcomm's decoder does not properly implement the AV1 specification and fails to decode a valid bitstream if it contains padding OBUs.

I confirmed the issue was only the padding OBUs by patching FFmpeg to avoid setting NV_ENC_CONFIG_AV1::enableBitstreamPadding = 1. This was enough to enable my Fold 6 to decode the stream successfully.

Great!, should i add something to the sunshine.conf file? or will a new version of sunshine be released to take into account OBUs on qualcom devices?

LuisB79 commented 2 weeks ago

Also, is it possible to make a bugreport to qualcom or samsung?

ReenigneArcher commented 2 weeks ago

Great!, should i add something to the sunshine.conf file?

There's no config option for this. It will be fixed in a future release.