OBS Studio Snap Uses Significantly More CPU For Encoding

I’ve found the OBS Snap using significantly higher resources for encoding under the same settings as the OBS package from the Ubuntu repositories. Currently on Ubuntu MATE 20.10, but I can replicate this on Ubuntu 20.10 and Xubuntu 20.10 as well.

OBS from repositories: OBS Studio - 26.0.2+dfsg1-1 (linux)
OBS Snap: OBS Studio - 26.0.2-modified (linux)

Recording at 2160p60 with x264 encoding in an MKV container. CRF 18 with the ultrafast preset.
The OBS Snap climbs up to ~87% CPU usage and the encoder gets overloaded, while the repository version stays around ~20%.

My system info:

System:    Kernel: 5.8.0-31-generic x86_64 bits: 64 compiler: gcc v: 10.2.0 Desktop: MATE 1.24.1 
           Distro: Ubuntu 20.10 (Groovy Gorilla) 
Machine:   Type: Desktop Mobo: Micro-Star model: MPG X570 GAMING PLUS (MS-7C37) v: 2.0 
           serial: <filter> UEFI: American Megatrends v: A.B0 date: 10/29/2020 
CPU:       Info: 8-Core model: AMD Ryzen 7 3800X bits: 64 type: MT MCP arch: Zen 2 L2 cache: 4096 KiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 140013 
           Speed: 4375 MHz min/max: N/A Core speeds (MHz): 1: 4375 2: 4374 3: 4375 4: 4375 5: 4375 
           6: 4385 7: 4373 8: 4375 9: 4373 10: 4375 11: 4375 12: 4375 13: 4375 14: 4374 15: 4368 
           16: 4374 
Graphics:  Device-1: AMD Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT] vendor: XFX Pine 
           driver: amdgpu v: kernel bus ID: 2f:00.0 
           Display: x11 server: X.Org 1.20.9 driver: amdgpu,ati 
           unloaded: fbdev,modesetting,radeon,vesa resolution: 3840x2160~60Hz 
           OpenGL: renderer: AMD Radeon RX 5700 XT (NAVI10 DRM 3.38.0 5.8.0-31-generic LLVM 11.0.0) 
           v: 4.6 Mesa 20.2.1 direct render: Yes 
Audio:     Device-1: AMD Navi 10 HDMI Audio driver: snd_hda_intel v: kernel bus ID: 2f:00.1 
           Device-2: AMD Starship/Matisse HD Audio vendor: Micro-Star MSI driver: snd_hda_intel 
           v: kernel bus ID: 31:00.4 
           Device-3: Logitech HD Pro Webcam C920 type: USB driver: snd-usb-audio,uvcvideo 
           bus ID: 1-2:3 
           Device-4: C-Media Blue Snowball type: USB driver: hid-generic,snd-usb-audio,usbhid 
           bus ID: 1-1:2 
           Device-5: Kingston HyperX 7.1 Audio type: USB driver: hid-generic,snd-usb-audio,usbhid 
           bus ID: 3-1:2 
           Sound Server: ALSA v: k5.8.0-31-generic 
Network:   Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet 
           vendor: Micro-Star MSI X570-A PRO driver: r8169 v: kernel port: d000 bus ID: 27:00.0 
           IF: enp39s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
Drives:    Local Storage: total: 2.27 TiB used: 88.62 GiB (3.8%) 
           ID-1: /dev/nvme0n1 vendor: Western Digital model: WDS500G3X0C-00SJG0 size: 465.76 GiB 
           ID-2: /dev/sda vendor: Western Digital model: WDS500G2B0A-00SM50 size: 465.76 GiB 
           ID-3: /dev/sdb vendor: Western Digital model: WDS500G2B0A-00SM50 size: 465.76 GiB 
           ID-4: /dev/sdc vendor: Western Digital model: WDS500G2B0A-00SM50 size: 465.76 GiB 
           ID-5: /dev/sdd vendor: Western Digital model: WDS500G2B0A-00SM50 size: 465.76 GiB 
Partition: ID-1: / size: 463.85 GiB used: 11.37 GiB (2.5%) fs: btrfs dev: /dev/nvme0n1p3 
           ID-2: /boot size: 945.6 MiB used: 214.4 MiB (22.7%) fs: ext4 dev: /dev/nvme0n1p2 
           ID-3: /home size: 463.85 GiB used: 11.37 GiB (2.5%) fs: btrfs dev: /dev/nvme0n1p3 
Swap:      ID-1: swap-1 type: zram size: 32.91 GiB used: 0 KiB (0.0%) dev: /dev/zram0 
Sensors:   System Temperatures: cpu: 50.8 C mobo: N/A gpu: amdgpu temp: 56.0 C 
           Fan Speeds (RPM): N/A gpu: amdgpu fan: 519 
Info:      Processes: 427 Uptime: 1h 06m Memory: 31.34 GiB used: 5.14 GiB (16.4%) Init: systemd 
           runlevel: 5 Compilers: gcc: 10.2.0 Packages: 2135 Shell: Bash v: 5.0.17 inxi: 3.1.07 

Output from OBS Snap in terminal while reproducing

The most likely culprit is that is that GPU offload of encoding is not working correctly. This could be one of two things:

  1. the OBS snap is missing the libraries or drivers necessary to perform the GPU encoding.

  2. snapd is blocking some access those drivers would need to function correctly.

There is mention of VA-API in the log you’ve posted, but it’s not clear whether it is being used or not. I’m not really sure what to suggest you try.

Assuming it is trying to use VA-API, there is the question of whether the drivers support encoding as well as decoding. Could you provide the output of the vainfo command?

2 Likes

The OBS snap also exposes an integrated vainfo, so please run: obs-studio.vainfo

In the log from OBS you shared @Schykle, I also see:

info: Initializing OpenGL...
/usr/share/libdrm/amdgpu.ids: No such file or directory

Which I can remedy in the snap using a layout.

2 Likes

It would be worthwhile comparing the output of vainfo and obs-studio.vainfo too, to see if they list different sets of encoders.

The encoders are represented by lines ending with VAEntrypointEncSlice*. Lines ending with VAEntrypointVLD are decoders, so if you only see those for the formats you’re interested in then that would explain why it isn’t offloading the encoding.

3 Likes

This is the output of obs-studio.vainfo

libva info: VA-API version 1.7.0
libva info: Trying to open /snap/obs-studio/1157/usr/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_7
/usr/share/libdrm/amdgpu.ids: No such file or directory
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Mesa Gallium driver 20.0.8 for AMD NAVI10 (DRM 3.38.0, 5.8.0-31-generic, LLVM 10.0.0)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc

And as @jamesh suggested, vainfo just in case.

libva info: VA-API version 1.8.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_8
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.8 (libva 2.8.0)
vainfo: Driver version: Mesa Gallium driver 20.2.1 for AMD Radeon RX 5700 XT (NAVI10, DRM 3.38.0, 5.8.0-31-generic, LLVM 11.0.0)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
1 Like

Thanks @Schykle. We’ve released obs-sudio revision 1171, you should have the update by now, but you can snap refresh obs-studio to be sure.

Revision 1171 adds a layout for /usr/share/libdrm/ which should clear up the /usr/share/libdrm/amdgpu.ids: No such file or directory errors. It is possible this might restore encoding performance, since vainfo looks correct on the host and inside in the snap.

Please retest the OBS encoding performance and report back :+1:

3 Likes

Unfortunately I’m still experiencing the same overloading issues with 1171. I removed and replaced the Snap as well just in case. Is there any particular kind of testing I can do to provide more detailed or useful output? (BTW, thanks for working on this!)

Do you know what codec OBS is trying to encode to? The outside-sandbox vainfo output shows an extra encoder compared to inside: VAProfileHEVCMain10. This is the HEVC Main10 profile, which may also be known as H.265.

This is a bit of a longshot, as I would have thought it would be more likely to default to H.264.

I set x264 software encoding to be used. I have no idea what it’d be doing under the hood though.

Well that’ll be why it’s not using hardware encoding (VAAPI)

That’s intentional. The same settings are used with the package from the repos. I’m not comparing VAAPI to CPU encoding.

1 Like