Jump to content

Accelerated Video Playback/zh: Difference between revisions

From NixOS Wiki
Ardenet (talk | contribs)
Created page with "== 另请参阅 == * [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki 的硬件视频加速]。 * [https://github.com/NixOS/nixos-hardware nixos-hardware] 包含各种硬件类型的示例配置。"
FuzzyBot (talk | contribs)
Updating to match new version of source page
Line 1: Line 1:
<languages/>
<languages/>
<div class="mw-translate-fuzzy">
NixOS 中的加速视频播放通常是通过向 {{nixos:option|hardware.opengl.extraPackages}} 添加相关包来完成的。
NixOS 中的加速视频播放通常是通过向 {{nixos:option|hardware.opengl.extraPackages}} 添加相关包来完成的。
</div>


<span id="Installation"></span>
<span id="Installation"></span>
Line 30: Line 32:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
   hardware.opengl.enable = true;
   hardware.graphics.enable = true;
}
}
</nowiki>}}
</nowiki>}}
<div lang="en" dir="ltr" class="mw-content-ltr">
=== NVIDIA ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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>.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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>:
</div>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ 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;
  };
}
</nowiki>}}
<span id="Testing_your_configuration"></span>
<span id="Testing_your_configuration"></span>
== 测试您的配置 ==
== 测试您的配置 ==
Line 50: Line 96:
<!--T:14-->
<!--T:14-->
<syntaxHighlight lang=ini>
<syntaxHighlight lang=ini>
hwdec=auto-safe
hwdec=auto
vo=gpu
profile=gpu-hq
gpu-context=wayland ; On wayland only
</syntaxHighlight>
</syntaxHighlight>



Revision as of 17:10, 7 October 2025

NixOS 中的加速视频播放通常是通过向 hardware.opengl.extraPackages 添加相关包来完成的。

安装

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
}

注意,intel-vaapi-driver 在较新的 Skylake (2015) 处理器上对于浏览器(基于 gecko/chromium)仍然表现更好。[1]

对于 32 位支持,请使用 hardware.graphics.extraPackages32:

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

AMD

AMD 相关硬件(至少对于 Ryzen 5 iGPU 系列)支持开箱即用:

❄︎ /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;
  };
}

测试您的配置

您可以通过运行以下命令来测试您的配置:nix-shell -p libva-utils --run vainfo 有关更多信息,请参阅Arch Linux wiki 的硬件视频加速

应用

Chromium

请参阅 Chromium#Accelerated_video_playback.

Firefox

请参阅 Arch Linux wiki 的 Firefox 部分.

MPV

您可以将以下配置放在 ~/.config/mpv/mpv.conf 中:

hwdec=auto

请参阅 Arch Linux wiki 的 mpv 部分.

另请参阅