Jump to content

Accelerated Video Playback: Difference between revisions

From NixOS Wiki
imported>Makefu
m add note for nixos-19.03
TLATER (talk | contribs)
m Add missing module args to he nvidia config example
 
(38 intermediate revisions by 16 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).
<languages/>
<translate>
<!--T:1-->
Accelerated video playback in NixOS is generally done by adding relevant packages to {{nixos:option|hardware.graphics.extraPackages}}.
</translate>


This is done by adding relevant <code>libva</code>-related packages to the <code>hardware.opengl.extraPackages</code> option.
<translate>
== Installation == <!--T:18-->
</translate>
<translate>
=== Intel === <!--T:19-->
</translate>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  hardware.graphics = {
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver # For Broadwell (2014) or newer processors. LIBVA_DRIVER_NAME=iHD
      intel-vaapi-driver # For older processors. LIBVA_DRIVER_NAME=i965
    ];
  };
  environment.sessionVariables = { LIBVA_DRIVER_NAME = "iHD"; }; # Optionally, set the environment variable
}
</nowiki>}}
<translate>
<!--T:2-->
Note, <code>intel-vaapi-driver</code> still performs better for browsers (gecko/chromium based) on newer Skylake (2015) processors.<ref>https://github.com/intel/media-driver/issues/1024</ref>
</translate>


Additionally, the <code>vaapiIntel</code> package can be overriden to enable [https://github.com/01org/intel-hybrid-driver Intel's Hybrid Driver].
<translate>
<!--T:3-->
For 32-bit support, use
</translate> {{nixos:option|hardware.graphics.extraPackages32}}:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];
}
</nowiki>}}
<translate>
=== AMD === <!--T:4-->


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.
<!--T:5-->
AMD configuration (at least for Ryzen 5 iGPUs) works out of the box:
</translate>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  hardware.graphics.enable = true;
}
</nowiki>}}


Sample configuration:
<translate>
=== NVIDIA ===


  {
NVIDIA do not officially support accelerated video playback on Linux. A third-party implementation exists, but does not support Chrome<ref>https://github.com/elFarto/nvidia-vaapi-driver#chrome</ref>, and has significant limitations compared to the other implementations<ref>https://github.com/elFarto/nvidia-vaapi-driver#codec-support</ref>.
    ...
    nixpkgs.config.packageOverrides = pkgs: {
      vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
    };
    hardware.opengl = {
      enable = true;
      extraPackages = with pkgs; [
        vaapiIntel
        vaapiVdpau
        libvdpau-va-gl
        intel-media-driver # only available starting nixos-19.03 or the current nixos-unstable
      ];
    };
    ...
  }
 


== Prepared Hardware configuration ==
NVIDIA users with a separate iGPU should generally prefer to use their iGPU for this, and therefore look to the above Intel and AMD sections instead.
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]


Users with only an NVIDIA GPU can attempt to use the third party implementation; the package is added to <code>hardware.graphics.extraPackages</code> by default, but it requires some additional setup to be useful<ref>https://github.com/elFarto/nvidia-vaapi-driver#configuration</ref>:
</translate>


== Applications ==
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, lib, ...}: {
  environment.variables.LIBVA_DRIVER_NAME = "nvidia"


===Chromium===
  # If used with Firefox
Needs a patch for VA-API support, see [https://github.com/NixOS/nixpkgs/issues/21481 nixpkgs#21481] for current status.
  environment.variables.MOZ_DISABLE_RDD_SANDBOX = "1";


===MPV===
  programs.firefox.preferences = let
@Mic92 needed the following configuration in <code>~/.mpv/config</code>
    ffVersion = config.programs.firefox.package.version;
for mpv to use hardware acceleration for VP9 on Intel Broadwell:
  in {
    "media.ffmpeg.vaapi.enabled" = lib.versionOlder ffVersion "137.0.0";
    "media.hardware-video-decoding.force-enabled" = lib.versionAtLeast ffVersion "137.0.0";
    "media.rdd-ffmpeg.enabled" = lib.versionOlder ffVersion "97.0.0";


<syntaxHighlight>
    "gfx.x11-egl.force-enabled" = true;
hwdec=vaapi
    "widget.dmabuf.force-enabled" = true;
 
    # Set this to true if your GPU supports AV1.
    #
    # This can be determined by reading the output of the
    # `vainfo` command, after the driver is enabled with
    # the environment variable.
    "media.av1.enabled" = false;
  };
}
</nowiki>}}
<translate>
 
== Testing your configuration == <!--T:6-->
 
<!--T:7-->
You can test your configuration by running: <code>nix-shell -p libva-utils --run vainfo</code>
</translate>
<translate>
<!--T:8-->
See [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Arch Linux wiki#Hardware video acceleration] for more information.
</translate>
<translate>
== Applications == <!--T:9-->
</translate>
<translate>
<!--T:10-->
=== Chromium ===
See [[Chromium#Accelerated_video_playback]].
</translate>
<translate>
=== Firefox === <!--T:11-->
 
<!--T:12-->
See [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Arch Linux wiki#Firefox].
</translate>
<!--T:13-->
<translate>
=== MPV === <!--T:20-->
</translate>
<translate>
<!--T:21-->
You can place the following configuration in {{ic|~/.config/mpv/mpv.conf}}:
</translate>
<!--T:14-->
<syntaxHighlight lang=ini>
hwdec=auto-safe
vo=gpu
vo=gpu
hwdec-codecs=all
profile=gpu-hq
gpu-context=wayland ; On wayland only
</syntaxHighlight>
</syntaxHighlight>


This is based on the [https://wiki.archlinux.org/index.php/Mpv#Hardware_decoding archlinux MPV article].
<!--T:15-->
<translate>
<!--T:22-->
See [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux wiki#mpv].
</translate>
<translate>
<!--T:16-->
== Also see ==
* [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki#Hardware video acceleration].
* [https://github.com/NixOS/nixos-hardware nixos-hardware] has example configurations for various types of hardware.
</translate>


===Other===
[[Category:Video]]
See the [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Application_support Arch Linux wiki].

Latest revision as of 09:06, 28 August 2025

Accelerated video playback in NixOS is generally done by adding relevant packages to hardware.graphics.extraPackages.

Installation

Intel

❄︎ /etc/nixos/configuration.nix
{
  hardware.graphics = {
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver # For Broadwell (2014) or newer processors. LIBVA_DRIVER_NAME=iHD
      intel-vaapi-driver # For older processors. LIBVA_DRIVER_NAME=i965
    ];
  };
  environment.sessionVariables = { LIBVA_DRIVER_NAME = "iHD"; }; # Optionally, set the environment variable
}

Note, intel-vaapi-driver still performs better for browsers (gecko/chromium based) on newer Skylake (2015) processors.[1]

For 32-bit support, use hardware.graphics.extraPackages32:

❄︎ /etc/nixos/configuration.nix
{
  hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ];
}

AMD

AMD configuration (at least for Ryzen 5 iGPUs) works out of the box:

❄︎ /etc/nixos/configuration.nix
{
  hardware.graphics.enable = true;
}

NVIDIA

NVIDIA do not officially support accelerated video playback on Linux. A third-party implementation exists, but does not support Chrome[2], and has significant limitations compared to the other implementations[3].

NVIDIA users with a separate iGPU should generally prefer to use their iGPU for this, and therefore look to the above Intel and AMD sections instead.

Users with only an NVIDIA GPU can attempt to use the third party implementation; the package is added to hardware.graphics.extraPackages by default, but it requires some additional setup to be useful[4]:

❄︎ /etc/nixos/configuration.nix
{ config, lib, ...}: {
  environment.variables.LIBVA_DRIVER_NAME = "nvidia"

  # If used with Firefox
  environment.variables.MOZ_DISABLE_RDD_SANDBOX = "1";

  programs.firefox.preferences = let
    ffVersion = config.programs.firefox.package.version;
  in {
    "media.ffmpeg.vaapi.enabled" = lib.versionOlder ffVersion "137.0.0";
    "media.hardware-video-decoding.force-enabled" = lib.versionAtLeast ffVersion "137.0.0";
    "media.rdd-ffmpeg.enabled" = lib.versionOlder ffVersion "97.0.0";

    "gfx.x11-egl.force-enabled" = true;
    "widget.dmabuf.force-enabled" = true;

    # Set this to true if your GPU supports AV1.
    #
    # This can be determined by reading the output of the
    # `vainfo` command, after the driver is enabled with
    # the environment variable.
    "media.av1.enabled" = false;
  };
}

Testing your configuration

You can test your configuration by running: nix-shell -p libva-utils --run vainfo See Arch Linux wiki#Hardware video acceleration for more information.

Applications

Chromium

See Chromium#Accelerated_video_playback.

Firefox

See Arch Linux wiki#Firefox.

MPV

You can place the following configuration in ~/.config/mpv/mpv.conf:

hwdec=auto-safe
vo=gpu
profile=gpu-hq
gpu-context=wayland ; On wayland only

See Arch Linux wiki#mpv.

Also see