NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.94k stars 13.96k forks source link

mpv vaapi support #331756

Closed eqfae closed 2 months ago

eqfae commented 2 months ago

Describe the bug

A clear and concise description of what the bug is. 不能使用vaapi 只能vaapi-copy screenshot-2024-08-02--19:39:54

Steps To Reproduce

Steps to reproduce the behavior:

  1. Setting hwdec=vaapi in mpv.conf will

    [   0.369][d][dyn_menu] commit menu items: menu-data
    [   0.370][v][vo/gpu-next] Assuming 165.000000 FPS for display sync.
    [   0.370][v][vd] Container reported FPS: 23.976024
    [   0.370][v][vd] Codec list:
    [   0.370][v][vd]     hevc - HEVC (High Efficiency Video Coding)
    [   0.370][v][vd]     hevc_v4l2m2m (hevc) - V4L2 mem2mem HEVC decoder wrapper
    [   0.370][v][vd]     hevc_cuvid (hevc) - Nvidia CUVID HEVC decoder
    [   0.370][v][vd] Opening decoder hevc
    [   0.370][v][vd] Looking at hwdec hevc-vaapi...
    [   0.370][v][vo/gpu-next] Loading hwdec drivers for format: 'vaapi'
    [   0.370][v][vo/gpu-next] Loading hwdec driver 'vaapi'
    [   0.370][v][vo/gpu-next/vaapi] libplacebo dmabuf interop requires support for PL_HANDLE_DMA_BUF import.
    [   0.370][v][vo/gpu-next/vaapi] VAAPI hwdec only works with OpenGL or Vulkan backends.
    [   0.370][v][vo/gpu-next] Loading failed.
    [   0.370][v][vd] Could not create device.
    [   0.370][v][vd] Using software decoding.
    [   0.371][v][vd] Detected 12 logical cores.

    Poor -copy performance Loses frames in high bitrate videos.

  2. mpv.conf

    hwdec=vaapi
    gpu-context=wayland
[   0.000][d][file] resize stream to 131072 bytes, drop 0 bytes
[   0.000][d][file] Stream opened successfully.
[   0.000][e][cplayer] Error parsing option gpu-api (option parameter could not be parsed)
[   0.000][e][cplayer] /home/xt/.config/mpv/mpv.conf:15: setting option gpu-api='d3d11' failed.
[   0.000][e][cplayer] Error parsing option window-corners (option not found)
[   0.000][e][cplayer] /home/xt/.config/mpv/mpv.conf:70: setting option window-corners='roundsmall' failed.
[   0.000][v][cplayer] Applying profile 'default'...

Expected behavior

Play using vaapi

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

I have used alpine mpv's, they are vaapi and the context is shown as wayland instead of waylandvk

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.43, NixOS, 24.11 (Vicuna), 24.11.20240731.9f918d6`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"nixos-24.05"`
 - nixpkgs: `/nix/store/7v6l2v247fmdgfpbs3w91mf6rinai4yk-source`

Add a :+1: reaction to issues you find important.

kira-bruneau commented 2 months ago

Mpv vaapi support works fine for me. Did you install the drivers? See https://wiki.nixos.org/wiki/Accelerated_Video_Playback.

You can also use https://github.com/NixOS/nixos-hardware if you want to simplify your hardware config. The intel-based profiles will automatically install vaapi drivers.

eqfae commented 2 months ago

Mpv vaapi support works fine for me. Did you install the drivers? See https://wiki.nixos.org/wiki/Accelerated_Video_Playback.

You can also use https://github.com/NixOS/nixos-hardware if you want to simplify your hardware config. The intel-based profiles will automatically install vaapi drivers.

{ pkgs, ... }:

{

# nixpkgs.config.packageOverrides = pkgs: {
#    intel-vaapi-driver = pkgs.intel-vaapi-driver.override { enableHybridCodec = true; };
 # };

  # https://nixos.wiki/wiki/AMD_GPU
  # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/amd/default.nix
  services.xserver.enable = true;  
  services.xserver.videoDrivers = [ "modesetting" ];
  hardware.amdgpu.initrd.enable = true;

  # Enable OpenGL
  hardware.graphics = {
    enable = true;
    enable32Bit = true;
    extraPackages = with pkgs; [
      mesa
    ];
    extraPackages32 = with pkgs.pkgsi686Linux; [
      mesa
    ];
  };
}

    ...
    packages = with pkgs; [
      mpv
      firefox-esr
      #lx-music-desktop
      #vscode
      #lutris
      #wineWowPackages.staging
      #winetricks
    #proton-ge-bin
    #protontricks
    _64gram
    #obsidian
    #obs-studio
    ];
vo=gpu
gpu-api=d3d11
hwdec=vaapi
gpu-context=wayland

or

gpu-context=wayland

or

vo=gpu
# gpu-api=d3d11
# hwdec=vaapi
gpu-context=wayland

Playing with sound but no video

In win vk mode I can only use -copy as well, although I haven't tried it in a long time, but to run on non-copy you should need to "gpu-context=wayland" work

gpu-context=x11vk gpu-context=x11 The former remains -copy and the latter falls back to waylandvk.

eqfae commented 2 months ago

Mpv vaapi support works fine for me. Did you install the drivers? See https://wiki.nixos.org/wiki/Accelerated_Video_Playback.

You can also use https://github.com/NixOS/nixos-hardware if you want to simplify your hardware config. The intel-based profiles will automatically install vaapi drivers.

trace: evaluation warning: The option `hardware.opengl.enable' defined in `/nix/store/r26x43qclvxcgsgbx9pc8gy0pw3bmhjc-source/opengl.nix' has been renamed to `hardware.graphics.enable'.
trace: evaluation warning: i18n.inputMethod.enabled will be removed in a future release. Please use .type, and .enable = true instead
[   0.427][v][vo/gpu-next] Loading hwdec drivers for format: 'vaapi'
[   0.427][v][vo/gpu-next] Loading hwdec driver 'vaapi'
[   0.427][v][vo/gpu-next/vaapi] libplacebo dmabuf interop requires support for PL_HANDLE_DMA_BUF import.
[   0.427][v][vo/gpu-next/vaapi] VAAPI hwdec only works with OpenGL or Vulkan backends.
[   0.427][v][vo/gpu-next] Loading failed.
[   0.427][v][vd] Could not create device.
[   0.427][v][vd] Looking at hwdec hevc-nvdec-copy...
[   0.427][e][ffmpeg] AVHWDeviceContext: Cannot load libcuda.so.1
[   0.427][e][ffmpeg] AVHWDeviceContext: Could not dynamically load CUDA
[   0.427][v][vd] Could not create device.
[   0.427][v][vd] Looking at hwdec hevc-vaapi-copy...
[   0.427][v][vaapi] libva: VA-API version 1.22.0
[   0.427][v][vaapi] libva: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
[   0.430][v][vaapi] libva: Found init function __vaDriverInit_1_22
[   0.442][v][vaapi] libva: va_openDriver() returns 0
[   0.442][v][vaapi] Initialized VAAPI: version 1.22
[   0.442][d][ffmpeg] AVHWDeviceContext: VAAPI driver: Mesa Gallium driver 24.1.4 for AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.54, 6.6.43).
[   0.442][d][ffmpeg] AVHWDeviceContext: Driver not found in known nonstandard list, using standard behaviour.
[   0.442][v][vd] Trying hardware decoding via hevc-vaapi-copy.
[   0.446][v][vd] Selected codec: HEVC (High Efficiency Video Coding)

[   0.434][v][vo/gpu-next/cuda] Failed to load CUDA symbols
[   0.434][v][vo/gpu-next] Loading failed.
[   0.434][v][vd] Could not create device.
[   0.434][v][vd] Looking at hwdec hevc-vaapi...
[   0.434][v][vo/gpu-next] Loading hwdec drivers for format: 'vaapi'
[   0.434][v][vo/gpu-next] Loading hwdec driver 'vaapi'
[   0.434][v][vo/gpu-next/vaapi] libplacebo dmabuf interop requires support for PL_HANDLE_DMA_BUF import.
[   0.434][v][vo/gpu-next/vaapi] VAAPI hwdec only works with OpenGL or Vulkan backends.
[   0.434][v][vo/gpu-next] Loading failed.
[   0.434][v][vd] Could not create device.
[   0.434][v][vd] Looking at hwdec hevc-nvdec-copy...
[   0.434][e][ffmpeg] AVHWDeviceContext: Cannot load libcuda.so.1
[   0.434][e][ffmpeg] AVHWDeviceContext: Could not dynamically load CUDA
[   0.434][v][vd] Could not create device.
[   0.434][v][vd] Looking at hwdec hevc-vaapi-copy...
[   0.435][v][vaapi] libva: VA-API version 1.22.0
[   0.435][v][vaapi] libva: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
[   0.437][v][vaapi] libva: Found init function __vaDriverInit_1_22
[   0.450][v][vaapi] libva: va_openDriver() returns 0
[   0.450][v][vaapi] Initialized VAAPI: version 1.22
[   0.450][d][ffmpeg] AVHWDeviceContext: VAAPI driver: Mesa Gallium driver 24.1.4 for AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.54, 6.6.43).
[   0.450][d][ffmpeg] AVHWDeviceContext: Driver not found in known nonstandard list, using standard behaviour.
[   0.450][v][vd] Trying hardware decoding via hevc-vaapi-copy.
eqfae commented 2 months ago
  services.xserver.enable = true;  
  services.xserver.videoDrivers = [ "modesetting" ];
  hardware.amdgpu.initrd.enable = true;
 #  https://github.com/NixOS/nixpkgs/issues/221535#issuecomment-1473815585
  environment.variables = {
    # VAAPI and VDPAU config for accelerated video.
    # See https://wiki.archlinux.org/index.php/Hardware_video_acceleration
    "VDPAU_DRIVER" = "radeonsi";
    "LIBVA_DRIVER_NAME" = "radeonsi";
  };

  # amd显卡驱动 驱动可能默认配置了 无需手动

  # Enable OpenGL
#  hardware.graphics = {
#    enable = true;
 #   enable32Bit = true;
  #  extraPackages = with pkgs; [
   #   mesa
    #];
   # extraPackages32 = with pkgs.pkgsi686Linux; [
    #  mesa
    #];
  #};

The graphics driver seems to be the best configuration by default so I deleted a little bit These listed configurations can be deleted? But it's already working, so I'm not testing it anymore. 图片

❯ nix-shell -p libva-utils --run vainfo
Trying display: wayland
libva info: VA-API version 1.22.0
libva info: User environment variable requested driver 'radeonsi'
libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_22
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: Mesa Gallium driver 24.1.4 for AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.54, 6.6.43)
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
      VAProfileNone                   : VAEntrypointVideoProc