russelltg / wl-screenrec

High performance wlroots screen recording, featuring hardware encoding
Apache License 2.0
266 stars 9 forks source link

Screen rec doesn't work on my system even with --no-hw #24

Closed LamprosPitsillos closed 10 months ago

LamprosPitsillos commented 10 months ago

Errors

❯ wl-screenrec 
Using output eDP-1
[h264_vaapi @ 0x55b0b21dafc0] No usable encoding profile found.
failed to open encoder in low_power mode (Function not implemented), trying non low_power mode. if you have an intel iGPU, set enable_guc=2 in the i915 module to use the fixed function encoder

[h264_vaapi @ 0x55b0b21db380] No usable encoding profile found.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ffmpeg::Error(38: Function not implemented)', src/main.rs:929:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
stack backtrace:
   0:     0x55b0b0643261 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h63269f8f54853ab3
   1:     0x55b0b066b4ef - core::fmt::write::h250dd3fc350bbada
   2:     0x55b0b064e471 - std::io::Write::write_fmt::h0fd841d7fefd9302
   3:     0x55b0b0643065 - std::sys_common::backtrace::print::hc99c547a903c74f7
   4:     0x55b0b0656447 - std::panicking::default_hook::{{closure}}::h5bbb3f780658c969
   5:     0x55b0b06561b2 - std::panicking::default_hook::h1946653929a625f2
   6:     0x55b0b065681c - std::panicking::rust_panic_with_hook::h8216316e1970270b
   7:     0x55b0b0643557 - std::panicking::begin_panic_handler::{{closure}}::h45b7865605f63cc8
   8:     0x55b0b0643346 - std::sys_common::backtrace::__rust_end_short_backtrace::h2efe3248368b98bf
   9:     0x55b0b0656542 - rust_begin_unwind
  10:     0x55b0b0591323 - core::panicking::panic_fmt::h90a1387c4eee835e
  11:     0x55b0b05910e3 - core::result::unwrap_failed::h45eef99f88d7b5bc
  12:     0x55b0b05ab249 - wl_screenrec::State::start_if_output_probe_complete::h136037ffaf6e5040
  13:     0x55b0b05a867c - <wl_screenrec::State as wayland_client::event_queue::Dispatch<wayland_protocols::xdg::xdg_output::zv1::generated::client::zxdg_output_v1::ZxdgOutputV1,u32>>::event::h7832b92a1a7ec7d5
  14:     0x55b0b05b58eb - wayland_client::event_queue::queue_callback::hd312658b1346c15c
  15:     0x55b0b05b61fb - wayland_client::event_queue::EventQueue<State>::dispatching_impl::h7ebc7e08b8fa341e
  16:     0x55b0b05b66fb - wayland_client::event_queue::EventQueue<State>::blocking_dispatch::h6c48090710bd30a2
  17:     0x55b0b05ad9ce - wl_screenrec::main::h2918bc8ebd69d25e
  18:     0x55b0b05bb433 - std::sys_common::backtrace::__rust_begin_short_backtrace::he2639b501e921d43
  19:     0x55b0b05bb709 - std::rt::lang_start::{{closure}}::hfd22811629113a75
  20:     0x55b0b06414e7 - std::rt::lang_start_internal::h8ab23524475b2279
  21:     0x55b0b05b16e5 - main
  22:     0x7f0ed883dace - __libc_start_call_main
  23:     0x7f0ed883db89 - __libc_start_main@@GLIBC_2.34
  24:     0x55b0b0591705 - _start
  25:                0x0 - <unknown>
❯ wl-screenrec --no-hw            
Using output eDP-1
[libx264 @ 0x56202b46fac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x56202b46fac0] profile Constrained Baseline, level 5.0, 4:2:0, 8-bit
Failed to screencopy!
[libx264 @ 0x56202b46fac0] final ratefactor: 12.71

Info

wl-screenrec 0.1.0

OS: NixOS 23.11.20230810.ce5e4a6 (Tapir) x86_64
Host: Aspire E5-576G (V1.43)
Kernel: 6.1.44
Display: 1920x1080 @ 60Hz
WM: Hyprland (Wayland)
CPU: Intel(R) Core(TM) i5-8250U (8) @ 3.4 GHz
GPU 1: Intel UHD Graphics 620
GPU 2: NVIDIA GeForce MX150

❯ vainfo     
Trying display: wayland
libva info: VA-API version 1.19.0
libva info: Trying to open /run/opengl-driver/lib/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib32/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/i386-linux-gnu/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /run/opengl-driver/lib/dri/i965_drv_video.so
libva info: Trying to open /usr/lib/dri/i965_drv_video.so
libva info: Trying to open /usr/lib32/dri/i965_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Trying to open /usr/lib/i386-linux-gnu/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
russelltg commented 10 months ago

Yep, your vaapi setup is broken. Follow you distribution's guide on how to do that. I believe @Shinyzenith uses wl-screenrec on nix, but not certain

Shinyzenith commented 10 months ago

https://github.com/Shinyzenith/nix-dotfiles/commit/2c65848e6fea545eb7a02b4f661aa905ea9c87dd

LamprosPitsillos commented 10 months ago

After using the config from @Shinyzenith i get this output from vainfo , but still get the same errors.... I will try

 nixpkgs.config.packageOverrides = pkgs: {
    vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
  };

and see if this fixes anything. EDIT: It didn't change anything...

❯ vainfo      
Trying display: wayland
libva info: VA-API version 1.19.0
libva info: Trying to open /run/opengl-driver/lib/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_19
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.19 (libva 2.19.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 23.1.6 ()
vainfo: Supported profile and entrypoints
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileNone                   : VAEntrypointStats
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointFEI
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointFEI
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointFEI
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointFEI
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD

Full vainfo -a https://gist.github.com/LamprosPitsillos/87d7eaa4472f1f4d80c708cef5e78c1e

Here is the output in case its not the same and i missed something

❯ RUST_BACKTRACE=full wl-screenrec
Using output eDP-1
[h264_vaapi @ 0x55dd81e26fc0] No usable encoding profile found.
failed to open encoder in low_power mode (Function not implemented), trying non low_power mode. if you have an intel iGPU, set enable_guc=2 in the i915 module to use the fixed function encoder
[h264_vaapi @ 0x55dd81e27380] No usable encoding profile found.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ffmpeg::Error(38: Function not implemented)', src/main.rs:929:26
stack backtrace:
   0:     0x55dd8014c261 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h63269f8f54853ab3
   1:     0x55dd801744ef - core::fmt::write::h250dd3fc350bbada
   2:     0x55dd80157471 - std::io::Write::write_fmt::h0fd841d7fefd9302
   3:     0x55dd8014c065 - std::sys_common::backtrace::print::hc99c547a903c74f7
   4:     0x55dd8015f447 - std::panicking::default_hook::{{closure}}::h5bbb3f780658c969
   5:     0x55dd8015f1b2 - std::panicking::default_hook::h1946653929a625f2
   6:     0x55dd8015f81c - std::panicking::rust_panic_with_hook::h8216316e1970270b
   7:     0x55dd8014c557 - std::panicking::begin_panic_handler::{{closure}}::h45b7865605f63cc8
   8:     0x55dd8014c346 - std::sys_common::backtrace::__rust_end_short_backtrace::h2efe3248368b98bf
   9:     0x55dd8015f542 - rust_begin_unwind
  10:     0x55dd8009a323 - core::panicking::panic_fmt::h90a1387c4eee835e
  11:     0x55dd8009a0e3 - core::result::unwrap_failed::h45eef99f88d7b5bc
  12:     0x55dd800b4249 - wl_screenrec::State::start_if_output_probe_complete::h136037ffaf6e5040
  13:     0x55dd800b167c - <wl_screenrec::State as wayland_client::event_queue::Dispatch<wayland_protocols::xdg::xdg_output::zv1::generated::client::zxdg_output_v1::ZxdgOutputV1,u32>>::event::h7832b92a1a7ec7d5
  14:     0x55dd800be8eb - wayland_client::event_queue::queue_callback::hd312658b1346c15c
  15:     0x55dd800bf1fb - wayland_client::event_queue::EventQueue<State>::dispatching_impl::h7ebc7e08b8fa341e
  16:     0x55dd800bf6fb - wayland_client::event_queue::EventQueue<State>::blocking_dispatch::h6c48090710bd30a2
  17:     0x55dd800b69ce - wl_screenrec::main::h2918bc8ebd69d25e
  18:     0x55dd800c4433 - std::sys_common::backtrace::__rust_begin_short_backtrace::he2639b501e921d43
  19:     0x55dd800c4709 - std::rt::lang_start::{{closure}}::hfd22811629113a75
  20:     0x55dd8014a4e7 - std::rt::lang_start_internal::h8ab23524475b2279
  21:     0x55dd800ba6e5 - main
  22:     0x7f28cc83dace - __libc_start_call_main
  23:     0x7f28cc83db89 - __libc_start_main@@GLIBC_2.34
  24:     0x55dd8009a705 - _start
  25:                0x0 - <unknown>
Shinyzenith commented 10 months ago

That config was specific to my Intel hardware, the nix wiki explains it in more detail incase you're on some other vendor.

LamprosPitsillos commented 10 months ago

I am also on intel hardware and the wiki suggested the same settings as in your config .The wiki really didn't help much.

❯ vdpauinfo                                
display: :1   screen: 0
Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory
Error creating VDPAU device: 1

I did try following the Arch Wiki and vdpauinfo gives me the above error.

LamprosPitsillos commented 10 months ago

After following the NVIDIA wiki page on NixOS i have the following info.

❯ vdpauinfo 
display: :1   screen: 0
GPU at BusId 0x1 doesn't have a supported video decoder
Error creating VDPAU device: 1
❯ RUST_BACKTRACE=full wl-screenrec 
Using output eDP-1
[AVHWFramesContext @ 0x55c3b13db7c0] Failed to create surface: 14 (the requested RT Format is not supported).
[AVHWFramesContext @ 0x55c3b13db7c0] Unable to allocate a surface from internal buffer pool.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ffmpeg::Error(12: Cannot allocate memory)', src/main.rs:875:14
stack backtrace:
   0:     0x55c3af6f2261 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h63269f8f54853ab3
   1:     0x55c3af71a4ef - core::fmt::write::h250dd3fc350bbada
   2:     0x55c3af6fd471 - std::io::Write::write_fmt::h0fd841d7fefd9302
   3:     0x55c3af6f2065 - std::sys_common::backtrace::print::hc99c547a903c74f7
   4:     0x55c3af705447 - std::panicking::default_hook::{{closure}}::h5bbb3f780658c969
   5:     0x55c3af7051b2 - std::panicking::default_hook::h1946653929a625f2
   6:     0x55c3af70581c - std::panicking::rust_panic_with_hook::h8216316e1970270b
   7:     0x55c3af6f2557 - std::panicking::begin_panic_handler::{{closure}}::h45b7865605f63cc8
   8:     0x55c3af6f2346 - std::sys_common::backtrace::__rust_end_short_backtrace::h2efe3248368b98bf
   9:     0x55c3af705542 - rust_begin_unwind
  10:     0x55c3af640323 - core::panicking::panic_fmt::h90a1387c4eee835e
  11:     0x55c3af6400e3 - core::result::unwrap_failed::h45eef99f88d7b5bc
  12:     0x55c3af659f80 - wl_screenrec::State::start_if_output_probe_complete::h136037ffaf6e5040
  13:     0x55c3af65767c - <wl_screenrec::State as wayland_client::event_queue::Dispatch<wayland_protocols::xdg::xdg_output::zv1::generated::client::zxdg_output_v1::ZxdgOutputV1,u32>>::event::h7832b92a1a7ec7d5
  14:     0x55c3af6648eb - wayland_client::event_queue::queue_callback::hd312658b1346c15c
  15:     0x55c3af6651fb - wayland_client::event_queue::EventQueue<State>::dispatching_impl::h7ebc7e08b8fa341e
  16:     0x55c3af6656fb - wayland_client::event_queue::EventQueue<State>::blocking_dispatch::h6c48090710bd30a2
  17:     0x55c3af65c9ce - wl_screenrec::main::h2918bc8ebd69d25e
  18:     0x55c3af66a433 - std::sys_common::backtrace::__rust_begin_short_backtrace::he2639b501e921d43
  19:     0x55c3af66a709 - std::rt::lang_start::{{closure}}::hfd22811629113a75
  20:     0x55c3af6f04e7 - std::rt::lang_start_internal::h8ab23524475b2279
  21:     0x55c3af6606e5 - main
  22:     0x7ff9e9a3dace - __libc_start_call_main
  23:     0x7ff9e9a3db89 - __libc_start_main@@GLIBC_2.34
  24:     0x55c3af640705 - _start
  25:                0x0 - <unknown>
❯ nvidia-smi
Sat Aug 26 12:33:04 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.86.05              Driver Version: 535.86.05    CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce MX150           Off | 00000000:01:00.0 Off |                  N/A |
| N/A   46C    P8              N/A / ERR! |      4MiB /  2048MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1009      G   ...3r2c4p61wm-xorg-server-21.1.8/bin/X        4MiB |
+---------------------------------------------------------------------------------------+
russelltg commented 10 months ago

wl-screenrec doesn't use vdpau, so that output isn't relevant. I'm not aware of anyone who's been able to get this working on Nvidia, but it should work well ok your Intel GPU. Can I get the output of wl-screenrec -vvv?

You may want to try passing your Intel GPU specially with '--dri-device'

LamprosPitsillos commented 10 months ago
❯ wl-screenrec -vvv
error: the argument '--verbose' cannot be used multiple times

Usage: wl-screenrec [OPTIONS]

For more information, try '--help'.

~ 
❯ wl-screenrec -v  
Using output eDP-1
[file @ 0x55895548dbc0] Setting default whitelist 'file,crypto,data'
[AVHWDeviceContext @ 0x55895548de40] libva: VA-API version 1.19.0
[AVHWDeviceContext @ 0x55895548de40] libva: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
[AVHWDeviceContext @ 0x55895548de40] libva: Found init function __vaDriverInit_1_0
[AVHWDeviceContext @ 0x55895548de40] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x55895548de40] Initialised VAAPI connection: version 1.19
[AVHWDeviceContext @ 0x55895548de40] Format 0x3231564e -> nv12.
[AVHWDeviceContext @ 0x55895548de40] Format 0x30313050 -> p010le.
[AVHWDeviceContext @ 0x55895548de40] Format 0x32313050 -> unknown.
[AVHWDeviceContext @ 0x55895548de40] Format 0x36313050 -> unknown.
[AVHWDeviceContext @ 0x55895548de40] VAAPI driver: VA-API NVDEC driver [egl backend].
[AVHWDeviceContext @ 0x55895548de40] Driver not found in known nonstandard list, using standard behaviour.
[AVHWFramesContext @ 0x5589559a7680] Failed to create surface: 14 (the requested RT Format is not supported).
[AVHWFramesContext @ 0x5589559a7680] Unable to allocate a surface from internal buffer pool.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ffmpeg::Error(12: Cannot allocate memory)', src/main.rs:875:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[AVIOContext @ 0x55895548df40] Statistics: 0 bytes written, 0 seeks, 0 writeouts
russelltg commented 10 months ago

You're using a old version of wl-screenrec (latest lets your provide -v multiple times).

Passing --dri-device /dev/dri/renderD128 or --dri-device /dev/dri/renderD129 to whichever is your Intel GPU should work.

You can figure out which is your intel GPU by matching paths in ls -la /dev/dri/by-path with lspci

LamprosPitsillos commented 10 months ago

You're using a old version of wl-screenrec (latest lets your provide -v multiple times).

❯ wl-screenrec --version
wl-screenrec 0.1.0

This is the version available in My repos unstable channel

❯ wl-screenrec --dri-device /dev/dri/renderD129 
Using output eDP-1
[h264_vaapi @ 0x558f13b0e000] Driver does not support any RC mode compatible with selected options (supported modes: CQP).
failed to open encoder in low_power mode (Invalid argument), trying non low_power mode. if you have an intel iGPU, set enable_guc=2 in the i915 module to use the fixed function encoder
1 fps
6 fps
8 fps
7 fps
8 fps
jk10 fps
8 fps
54 fps
^C%                                                                                           
~ took 8s 

For the first time , we got a recording!

russelltg commented 10 months ago

Actually it may work without that flag with an update, I added auto device detection through the Wayland protocols.

What OS are you on?

LamprosPitsillos commented 10 months ago

I am on NixOs Unstable Channel. wl-screenrec in their channel

russelltg commented 10 months ago

I see, I didn't realize someone packaged it on Nix. I should start versioning it properly considering it's packaged on Nix as well as BSD