Difference between revisions of "Accelerated Video Playback"

From NixOS Wiki
Jump to: navigation, search
(chromium vaapi update)
(Corrected intel accelleration driver info. THe previously linked issue had nothing to do with vaapi-driver, only hybrid. Aso since vaapi-driver is now archived, and media supports a wider CPU range and is more moddern (and supports both Skylake and the older broadwell) it should be prioritised for new users. Finally... my skylake wouldn't get accelleration at all with vaapi driver, but did with media-driver)
 
(17 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
This page is meant to help with techniques for getting accelerated video playback working in NixOS. This is generally done via libva and vaapi (and sometimes vdpau).
 
This page is meant to help with techniques for getting accelerated video playback working in NixOS. This is generally done via libva and vaapi (and sometimes vdpau).
  
This is done by adding relevant <code>libva</code>-related packages to the <code>hardware.opengl.extraPackages</code> option.
+
This is done by adding relevant <code>libva</code>-related packages to the <code>hardware.opengl.extraPackages</code> (or <code>hardware.graphics.extraPackages</code> on unstable) option.
  
Additionally, the <code>vaapiIntel</code> package can be overriden to enable [https://github.com/01org/intel-hybrid-driver Intel's Hybrid Driver].
+
Intel users should enable <code>intel-media-driver</code> if their CPU is on the [https://github.com/intel/media-driver?tab=readme-ov-file#supported-platforms supported list] (Broadwell and newer). It can be used at runtime with <code>LIBVA_DRIVER_NAME=iHD mpv ...</code> for example, if you use Mic92's mpv settings below.
 +
 
 +
Other intel CPUs could enable the <code>intel-vaapi-driver</code>. This may have better results in some cases where the media driver doesn't work. However, this driver is unmaintained.
 +
 
 +
Additionally, the <code>intel-vaapi-driver</code> (previously <code>vaapiIntel</code>) package can be overridden to enable [https://github.com/01org/intel-hybrid-driver Intel's Hybrid Driver].
  
Intel users also can enable <code>intel-media-driver</code>. It can be used at runtime with <code>LIBVA_DRIVER_NAME=iHD mpv ...</code> for example, if you use Mic92's mpv settings below.
 
  
 
Sample configuration:
 
Sample configuration:
Line 12: Line 15:
 
   ...
 
   ...
 
   nixpkgs.config.packageOverrides = pkgs: {
 
   nixpkgs.config.packageOverrides = pkgs: {
     vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
+
     intel-vaapi-driver = pkgs.intel-vaapi-driver.override { enableHybridCodec = true; };
 
   };
 
   };
   hardware.opengl = {
+
   hardware.opengl = { # hardware.graphics since NixOS 24.11
 
     enable = true;
 
     enable = true;
 
     extraPackages = with pkgs; [
 
     extraPackages = with pkgs; [
       vaapiIntel
+
       intel-media-driver # LIBVA_DRIVER_NAME=iHD
       vaapiVdpau
+
       intel-vaapi-driver # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
 
       libvdpau-va-gl
 
       libvdpau-va-gl
      intel-media-driver # only available starting nixos-19.03 or the current nixos-unstable
 
 
     ];
 
     ];
 
   };
 
   };
 +
  environment.sessionVariables = { LIBVA_DRIVER_NAME = "iHD"; }; # Force intel-media-driver
 
   ...
 
   ...
 
}
 
}
 
</syntaxHighlight>
 
</syntaxHighlight>
 +
 +
32 bit example:
 +
<syntaxhighlight lang="nix">
 +
hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];
 +
</syntaxhighlight>
 +
On unstable:
 +
<syntaxhighlight lang="nix">
 +
hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];
 +
</syntaxhighlight>
  
 
== Prepared Hardware configuration ==
 
== Prepared Hardware configuration ==
 
Sometimes different opengl packages are required to achieve full performance. You can check different configuration repositories for similar hardware configuration:
 
Sometimes different opengl packages are required to achieve full performance. You can check different configuration repositories for similar hardware configuration:
 
* [https://github.com/NixOS/nixos-hardware The NixOS-Hardware Repository]
 
* [https://github.com/NixOS/nixos-hardware The NixOS-Hardware Repository]
 +
 +
== Testing your configuration ==
 +
 +
You can test your configuration by running: <code>nix-shell -p libva-utils --run vainfo</code>
 +
 +
See [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Hardware video acceleration: Verification (Arch Wiki)] for more information.
  
 
== Applications ==
 
== Applications ==
  
 
===Chromium===
 
===Chromium===
Chromium builds from nixpkgs now support vaapi by default. It can be disabled via a flag in about:config. (see: https://github.com/NixOS/nixpkgs/pull/57837 and https://github.com/NixOS/nixpkgs/commit/60e2d2ce2bd8c36c6e6f5152bea2d78ebab58f8b)
 
  
===MPV===
+
See [https://nixos.wiki/wiki/Chromium#Enable_GPU_accelerated_video_decoding_.28VA-API.29 Chromium].
@Mic92 needed the following configuration in <code>~/.mpv/config</code>
+
 
for mpv to use hardware acceleration for VP9 on Intel Broadwell:
+
=== Firefox ===
 +
 
 +
See [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Firefox#Hardware_video_acceleration (ArchWiki)].
 +
 
 +
===[[MPV]]===
 +
You can place the following configuration in <code>~/.config/mpv/mpv.conf</code>
 +
for mpv to use hardware acceleration for VP9 on Intel Broadwell (and probably later):
  
 
<syntaxHighlight lang=ini>
 
<syntaxHighlight lang=ini>
hwdec=vaapi
+
hwdec=auto-safe
 
vo=gpu
 
vo=gpu
hwdec-codecs=all
+
profile=gpu-hq
 
</syntaxHighlight>
 
</syntaxHighlight>
  
Line 52: Line 75:
 
</syntaxHighlight>
 
</syntaxHighlight>
  
This is based on the [https://wiki.archlinux.org/index.php/Mpv#Hardware_decoding archlinux MPV article].
+
This is based on the [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux mpv article].
  
 
===Other===
 
===Other===
 
See the [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Application_support Arch Linux wiki].
 
See the [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Application_support Arch Linux wiki].

Latest revision as of 08:33, 14 June 2025

This page is meant to help with techniques for getting accelerated video playback working in NixOS. This is generally done via libva and vaapi (and sometimes vdpau).

This is done by adding relevant libva-related packages to the hardware.opengl.extraPackages (or hardware.graphics.extraPackages on unstable) option.

Intel users should enable intel-media-driver if their CPU is on the supported list (Broadwell and newer). It can be used at runtime with LIBVA_DRIVER_NAME=iHD mpv ... for example, if you use Mic92's mpv settings below.

Other intel CPUs could enable the intel-vaapi-driver. This may have better results in some cases where the media driver doesn't work. However, this driver is unmaintained.

Additionally, the intel-vaapi-driver (previously vaapiIntel) package can be overridden to enable Intel's Hybrid Driver.


Sample configuration:

{
  ...
  nixpkgs.config.packageOverrides = pkgs: {
    intel-vaapi-driver = pkgs.intel-vaapi-driver.override { enableHybridCodec = true; };
  };
  hardware.opengl = { # hardware.graphics since NixOS 24.11
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver # LIBVA_DRIVER_NAME=iHD
      intel-vaapi-driver # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
      libvdpau-va-gl
    ];
  };
  environment.sessionVariables = { LIBVA_DRIVER_NAME = "iHD"; }; # Force intel-media-driver
  ...
}

32 bit example:

hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];

On unstable:

hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];

Prepared Hardware configuration

Sometimes different opengl packages are required to achieve full performance. You can check different configuration repositories for similar hardware configuration:

Testing your configuration

You can test your configuration by running: nix-shell -p libva-utils --run vainfo

See Hardware video acceleration: Verification (Arch Wiki) for more information.

Applications

Chromium

See Chromium.

Firefox

See Firefox#Hardware_video_acceleration (ArchWiki).

MPV

You can place the following configuration in ~/.config/mpv/mpv.conf for mpv to use hardware acceleration for VP9 on Intel Broadwell (and probably later):

hwdec=auto-safe
vo=gpu
profile=gpu-hq

With Wayland, you need to nudge mpv to do the right thing:

gpu-context=wayland

This is based on the Arch Linux mpv article.

Other

See the Arch Linux wiki.