Jump to content

Accelerated Video Playback/zh: Difference between revisions

From NixOS Wiki
Ardenet (talk | contribs)
Created page with "== 安装 =="
Ardenet (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
NixOS 中的加速视频播放通常是通过向 {{nixos:option|hardware.opengl.extraPackages}} 添加相关包来完成的。
NixOS 中的视频播放加速通常是通过向 {{nixos:option|hardware.graphics.extraPackages}} 添加相关包来完成的。


<span id="Installation"></span>
<span id="Installation"></span>
== 安装 ==
== 安装 ==
<div lang="en" dir="ltr" class="mw-content-ltr">
=== Intel ===
=== Intel ===
</div>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
Line 19: Line 17:
}
}
</nowiki>}}
</nowiki>}}
<div lang="en" dir="ltr" class="mw-content-ltr">
注意,<code>intel-vaapi-driver</code> 在较新的 Skylake (2015) 处理器上对于浏览器(基于 gecko/chromium)仍然表现更好。<ref>https://github.com/intel/media-driver/issues/1024</ref>
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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
对于 32 位支持,请使用 {{nixos:option|hardware.graphics.extraPackages32}}:
For 32-bit support, use
</div> {{nixos:option|hardware.graphics.extraPackages32}}:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
Line 31: Line 25:
}
}
</nowiki>}}
</nowiki>}}
<div lang="en" dir="ltr" class="mw-content-ltr">
=== AMD ===
=== AMD ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
AMD 相关硬件(至少对于 Ryzen 5 iGPU 系列)支持开箱即用:
AMD configuration (at least for Ryzen 5 iGPUs) works out of the box:
</div>
{{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">
== Testing your configuration ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
=== NVIDIA ===
You can test your configuration by running: <code>nix-shell -p libva-utils --run vainfo</code>
 
</div>
NVIDIA 官方并未支持 Linux 上的视频播放加速。虽然存在第三方实现,但不支持 Chrome<ref>https://github.com/elFarto/nvidia-vaapi-driver#chrome</ref>,并且与其他实现<ref>https://github.com/elFarto/nvidia-vaapi-driver#codec-support</ref>相比存在显著限制。
<div lang="en" dir="ltr" class="mw-content-ltr">
 
See [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Arch Linux wiki#Hardware video acceleration] for more information.
拥有独立 iGPU 的 NVIDIA 用户通常应该更喜欢使用他们的 iGPU 来实现此目的,因此请参考上面的 Intel 和 AMD 部分。
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
仅具有 NVIDIA GPU 的用户可以尝试使用第三方实现;默认情况下,添加软件包到 <code>hardware.graphics.extraPackages</code>,但之后需要进行一些额外的设置才能使用<ref>https://github.com/elFarto/nvidia-vaapi-driver#configuration</ref>:
== Applications ==
 
</div>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
<div lang="en" dir="ltr" class="mw-content-ltr">
{ 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>
== 测试您的配置 ==
 
您可以通过运行以下命令来测试您的配置:<code>nix-shell -p libva-utils --run vainfo</code>
有关更多信息,请参阅 [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Arch Linux wiki 的硬件视频加速]
<span id="Applications"></span>
== 应用 ==
=== Chromium ===
=== Chromium ===
See [[Chromium#Accelerated_video_playback]].
请参阅 [[Special:MyLanguage/Chromium#Accelerated_video_playback|Chromium 视频加速]].
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
=== Firefox ===
=== Firefox ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
请参阅 [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Arch Linux wiki Firefox 部分].
See [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Arch Linux wiki#Firefox].
</div>
<!--T:13-->
<!--T:13-->
<div lang="en" dir="ltr" class="mw-content-ltr">
=== MPV ===
=== MPV ===
</div>
您可以将以下配置放在 {{ic|~/.config/mpv/mpv.conf}} 中:
<div lang="en" dir="ltr" class="mw-content-ltr">
You can place the following configuration in {{ic|~/.config/mpv/mpv.conf}}:
</div>
<!--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>


<!--T:15-->
<!--T:15-->
<div lang="en" dir="ltr" class="mw-content-ltr">
请参阅 [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux wiki mpv 部分].
See [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux wiki#mpv].
== 另请参阅 ==
</div>
* [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki 的硬件视频加速]
<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://github.com/NixOS/nixos-hardware nixos-hardware] 包含各种硬件类型的示例配置。
== 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.
</div>


[[Category:Video]]
[[Category:Video]]

Latest revision as of 09:24, 8 October 2025

NixOS 中的视频播放加速通常是通过向 hardware.graphics.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 官方并未支持 Linux 上的视频播放加速。虽然存在第三方实现,但不支持 Chrome[2],并且与其他实现[3]相比存在显著限制。

拥有独立 iGPU 的 NVIDIA 用户通常应该更喜欢使用他们的 iGPU 来实现此目的,因此请参考上面的 Intel 和 AMD 部分。

仅具有 NVIDIA GPU 的用户可以尝试使用第三方实现;默认情况下,添加软件包到 hardware.graphics.extraPackages,但之后需要进行一些额外的设置才能使用[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 视频加速.

Firefox

请参阅 Arch Linux wiki 的 Firefox 部分.

MPV

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

hwdec=auto

请参阅 Arch Linux wiki 的 mpv 部分.

另请参阅