ALVR icon indicating copy to clipboard operation
ALVR copied to clipboard

Linux NVENC Encoder requires B Frame support for any hardware.

Open MrBlackGoo opened this issue 10 months ago • 14 comments

I meet with exactly same problem, and really beg for help. I have GeForce GTX 1650 and same issue with B Frames appears every time I try to use NVENC codec (ALVR version 20.5.0). I tried to change settings, add some b_ref_mode parameter there, but nothing helps. I checked FFMPEG simple encoding of a media file through the console using NVENC and I got exactly same warning ("B frames as references are not supported") and then the error "Provided device doesn't support required NVENC features". But if add "-b_ref_mode 0" encoding works perfectly fine.

After some research I tried to uninstall and recompile ffmpeg from its sources, changing default settings for using B Frames to False. This experiment was successful. It works nice but as long as I actually use "ffmpeg" from the console. ALVR, sadly completely ignore this changes as it keeps throwing same warning and the error every time. I even changed text of the warning, to check if ALVR using it or not, but ALVR didn't show any my changes at all. I tried to use ALVR AppImage and tar version (tar version refuse to see headset without "libx264.so.163" in "lib" folder), but both seems don't even use ffmpeg I recompiled. My custom ffmpeg located at "/usr/local/bin", and I do not have any other ffmpeg installed (except libs, which I can't remove for multimedia software like "Haruna Media Player" and etc )

What do I miss? How to force ALVR do not use B Frames for NVENC codec?

Originally posted by @MrBlackGoo in https://github.com/alvr-org/ALVR/discussions/1947#discussioncomment-8265041

Description

Tried to use NVENC encoder with GTX 1080 TI but ALVR kept reporting that HW accelerated B Frames are not supported which then results in SteamVR throwing an error cancelling the stream.

Apparently, to disable B frames, one can pass b_ref_mode=0 to ffmpeg to skip B Frames but is this possible to do with ALVR? I've tried a few options (like setting frame strategies, frame counts, etc., to 0) but the error still persisted.

Can one disable B frames or is this a critical features (i.e., if it is not supported, then NVENC cannot be used)? If one can disable B frames, how can I configure ALVR to disable B frames?

Thanks. https://github.com/alvr-org/ALVR/discussions/1947?ysclid=lrn8n2l3hs578002232#discussion-6023020

This issue still remains not fixed at the ALVR 20.7.0. (Additionally I would mention that newest tar version works fine without "lib" folder, but still don't work with B Frames by same reason as mentioned in the original post.)

General Troubleshooting

  • [x] I carefully followed the instructions in the README and successfully completed the setup wizard
  • [x] I read the ALVR Wikis here and here

Environment

Hardware

CPU: Intel Xeon E3-1270 V2 (8) @ 3.900GHz

GPU: NVIDIA GeForce GTX 1650

Installation

ALVR Version: 20.7.0

Install Type:

  • [ ] Packaged (exe, deb, rpm, etc)
  • [x] Portable (zip)
  • [ ] Source

OS Name and Version Kubuntu 23.10 x86_64

MrBlackGoo avatar Apr 06 '24 16:04 MrBlackGoo

Having this problem too. Would be great to have an option to set -b_ref_mode to 0 in the app.

mediastacks avatar Apr 07 '24 09:04 mediastacks

On Linux, ALVR bundles ffmpeg during compilation, first downloading ffmpeg sources from the internet and applying patches found in alvr/xtask/patches/*.patch. To have any change you want to make to ffmpeg apply to ALVR, you'd need to make a .patch file and stick it where the others are, then recompile ALVR. If you look in alvr/server/cpp/platform/linux/EncodePipelineNvEnc.cpp you'll see how the encoder is set up, and see that it relies on CUDA. Does the GTX 1650 even support CUDA?

Xaphiosis avatar Apr 08 '24 07:04 Xaphiosis

My GPU got CUDA cores. It seems like many people on Linux have a problem with that b_ref_mode, so maybe it's a great idea to add an option to disable that parameter in the next release, if possible.

mediastacks avatar Apr 08 '24 11:04 mediastacks

On Linux, ALVR bundles ffmpeg during compilation, first downloading ffmpeg sources from the internet and applying patches found in alvr/xtask/patches/*.patch. To have any change you want to make to ffmpeg apply to ALVR, you'd need to make a .patch file and stick it where the others are, then recompile ALVR. If you look in alvr/server/cpp/platform/linux/EncodePipelineNvEnc.cpp you'll see how the encoder is set up, and see that it relies on CUDA. Does the GTX 1650 even support CUDA?

Thank you, @Xaphiosis for the advice. But I am not a true programmer to edit and compile ALVR's source code by myself. I am just an simple user, and all that I ask is to add some option for the ALVR that would to turn off usage of the B Frame feature for the NVENC codec, same as @mediastacks mentioned. Simple switch that we could turn on and off, would be enough to solve the issue. Thank you again for help!

MrBlackGoo avatar Apr 13 '24 20:04 MrBlackGoo

I gave this a shot, see https://github.com/Xaphiosis/ALVR/releases/tag/nightly-no_b_ref_mode It's pretty much the nightly from last night with @nowrep's patch so you two can try it out (I've tested it but can't actually tell you if it will work for you since I'm on a 3090). See the release notes, and make sure you use the right client (included) so you don't get a protocol mismatch.

If this works for you, we can take it further towards making it an option.

(note that the AppImage is only there to aid in debugging, currently there is no official appimage for v20.7.1)

Xaphiosis avatar Apr 15 '24 09:04 Xaphiosis

I gave this a shot, see https://github.com/Xaphiosis/ALVR/releases/tag/nightly-no_b_ref_mode It's pretty much the nightly from last night with @nowrep's patch so you two can try it out (I've tested it but can't actually tell you if it will work for you since I'm on a 3090). See the release notes, and make sure you use the right client (included) so you don't get a protocol mismatch.

If this works for you, we can take it further towards making it an option.

(note that the AppImage is only there to aid in debugging, currently there is no official appimage for v20.7.1)

Thank you so much, it worked for me!

It still throws these error popups upon connecting to the headset, but that doesn't affect functionality, I guess. ERROR Encoder: Undefined constant or missing '(' in 'high' ERROR Encoder: Unable to parse option value "high"

mediastacks avatar Apr 16 '24 08:04 mediastacks

Was it the appimage or the tar.gz that worked for you? Also would be good to hear from @MrBlackGoo ... the ERROR Encoder might be an older version of nvenc/cuda than what was linked against, but I dunno. My libffmpeg-nvenc-dev says it's version 11.1.5.1-1 and my nvidia-smi says Driver Version: 550.54.14 CUDA Version: 12.4

Xaphiosis avatar Apr 16 '24 10:04 Xaphiosis

Was it the appimage or the tar.gz that worked for you? Also would be good to hear from @MrBlackGoo ... the ERROR Encoder might be an older version of nvenc/cuda than what was linked against, but I dunno. My libffmpeg-nvenc-dev says it's version 11.1.5.1-1 and my nvidia-smi says Driver Version: 550.54.14 CUDA Version: 12.4

I tried AppImage only since I don't feel qualified enough to build from source :)

mediastacks avatar Apr 16 '24 18:04 mediastacks

The tar.gz is not the source, it's supposed to be a portable archive (appimage was removed in most recent ALVR release). If you decompress it somewhere, you should see that alvr_streamer_linux/bin/alvr_dashboard is runnable. Could you try it as well please? It handles packing headers differently and might address the Undefined constant or missing '(' in 'high' stuff. I can probably add this workaround for the next release, but that might not have an appimage either.

Xaphiosis avatar Apr 16 '24 21:04 Xaphiosis

@Xaphiosis, I am sorry for the late answer. Had no time to test the version you sent until now. Thank you for your efforts, the fix works as intended! Not sure exactly how lack of using B Frames affects performance or things at newer graphic cards. So I would suggest to add this fix as an option in settings menu, to be sure that it will not backfire. Thank you for your hard work of making VR possible for everyone, even at the Linux! ^^

It still throws these error popups upon connecting to the headset, but that doesn't affect functionality, I guess. ERROR Encoder: Undefined constant or missing '(' in 'high' ERROR Encoder: Unable to parse option value "high"

I get same not critical errors when try to use new ALVR version (both the one you sent and the 20.7.0), but it happen too quick and not affect the session after that.

MrBlackGoo avatar Apr 20 '24 09:04 MrBlackGoo

Thanks @MrBlackGoo for checking that out. I wish I knew what the issues are with that x264 encoder profile setting (that's the "high" you're seeing). Could you let me know if there's any difference between the AppImage and the tar.gz when it comes to those encoder errors?

I think ALVR doesn't use B-frames at all... after double-checking what B-frames actually are, it occurred to me that they stand for bi-directional, i.e. using info from previous and subsequent frames. As you can imagine, this doesn't happen in a low-latency streaming application without being able to access to the future. So P-frames only, hence no effect on outcome for ALVR. I put up a PR, it's been approved, but I don't have write permission so presumably someone will merge it before next release.

Xaphiosis avatar Apr 20 '24 10:04 Xaphiosis

Drive by comment - I can confirm that I had the same issue with GTX 1080 Ti, and the nightly build shared in https://github.com/alvr-org/ALVR/issues/2064#issuecomment-2056413327 resolved it for me. Thank you for the fix @Xaphiosis!

chekunkov avatar Apr 20 '24 17:04 chekunkov

Thanks @MrBlackGoo for checking that out. I wish I knew what the issues are with that x264 encoder profile setting (that's the "high" you're seeing). Could you let me know if there's any difference between the AppImage and the tar.gz when it comes to those encoder errors?

As I mentioned in previous comment, I tried to use tar.gz of the ALVR v20.7.0 (as AppImage no longer exists), and got same error appearing when I tried to use x264 codec because I had no choice (as NVENC (because of B Frames) and AV1 (because of AMD only) doesn't work for me at 20.7.0).

MrBlackGoo avatar Apr 21 '24 06:04 MrBlackGoo

Thanks @MrBlackGoo for checking that out. I wish I knew what the issues are with that x264 encoder profile setting (that's the "high" you're seeing). Could you let me know if there's any difference between the AppImage and the tar.gz when it comes to those encoder errors?

As I mentioned in previous comment, I tried to use tar.gz of the ALVR v20.7.0 (as AppImage no longer exists), and got same error appearing when I tried to use x264 codec because I had no choice (as NVENC (because of B Frames) and AV1 (because of AMD only) doesn't work for me at 20.7.0).

Ah no, I meant alvr_streamer_linux.tar.gz in the release I made (there's both an AppImage and a tar.gz, and I want someone to tell me whether unpacking the tar.gz and running it still results in those Undefined constant or missing '(' in 'high' errors). I do understand that 20.7.0/1 release isn't going to work for you.

I guess is doesn't matter that much now. The fix for this issue (the B frame refs) is merged now, so next release should pick it up, and maybe you only need a newer version of libnvidia-encode or something to deal with the x264 profiles (I've got libnvidia-encode-550 550.54.15 for what it's worth).

Xaphiosis avatar Apr 21 '24 13:04 Xaphiosis

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 22 '24 00:06 github-actions[bot]