Accelerated Video Playback/zh: Difference between revisions
Appearance
No edit summary Tags: Mobile edit Mobile web edit |
Updating to match new version of source page Tags: Mobile edit Mobile web edit |
||
| Line 4: | Line 4: | ||
<span id="Installation"></span> | <span id="Installation"></span> | ||
== 安装 == | == 安装 == | ||
=== Intel === | === Intel === | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | |||
pkgs, | |||
... | |||
}: | |||
{ | { | ||
hardware.graphics = { | hardware.graphics = { | ||
| Line 14: | Line 21: | ||
]; | ]; | ||
}; | }; | ||
environment.sessionVariables = { LIBVA_DRIVER_NAME = "iHD"; }; # Optionally, set the environment variable | environment.sessionVariables = { | ||
LIBVA_DRIVER_NAME = "iHD"; | |||
}; # Optionally, set the environment variable | |||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
注意,<code>intel-vaapi-driver</code> 在较新的 Skylake (2015) 处理器上对于浏览器(基于 gecko/chromium)仍然表现更好。<ref>https://github.com/intel/media-driver/issues/1024</ref> | 注意,<code>intel-vaapi-driver</code> 在较新的 Skylake (2015) 处理器上对于浏览器(基于 gecko/chromium)仍然表现更好。<ref>https://github.com/intel/media-driver/issues/1024</ref> | ||
对于 32 位支持,请使用 {{nixos:option|hardware.graphics.extraPackages32}}: | 对于 32 位支持,请使用 {{nixos:option|hardware.graphics.extraPackages32}}: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | |||
pkgs, | |||
... | |||
}: | |||
{ | { | ||
hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ]; | hardware.graphics.extraPackages32 = with pkgs.pkgsi686Linux; [ intel-vaapi-driver ]; | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
=== AMD === | === AMD === | ||
AMD 相关硬件(至少对于 Ryzen 5 iGPU 系列)支持开箱即用: | AMD 相关硬件(至少对于 Ryzen 5 iGPU 系列)支持开箱即用: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { | ||
| Line 42: | Line 59: | ||
仅具有 NVIDIA GPU 的用户可以尝试使用第三方实现;默认情况下,添加软件包到 <code>hardware.graphics.extraPackages</code>,但之后需要进行一些额外的设置才能使用<ref>https://github.com/elFarto/nvidia-vaapi-driver#configuration</ref>: | 仅具有 NVIDIA GPU 的用户可以尝试使用第三方实现;默认情况下,添加软件包到 <code>hardware.graphics.extraPackages</code>,但之后需要进行一些额外的设置才能使用<ref>https://github.com/elFarto/nvidia-vaapi-driver#configuration</ref>: | ||
{{file| | {{file|3=<nowiki> | ||
{ config, lib, ...}: { | { | ||
environment.variables.LIBVA_DRIVER_NAME = "nvidia" | config, | ||
lib, | |||
... | |||
}: | |||
{ | |||
environment.variables.LIBVA_DRIVER_NAME = "nvidia"; | |||
# If used with Firefox | # If used with Firefox | ||
environment.variables.MOZ_DISABLE_RDD_SANDBOX = "1"; | environment.variables.MOZ_DISABLE_RDD_SANDBOX = "1"; | ||
programs.firefox.preferences = let | 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>}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
<span id="Testing_your_configuration"></span> | <span id="Testing_your_configuration"></span> | ||
| Line 73: | Line 98: | ||
您可以通过运行以下命令来测试您的配置:<code>nix-shell -p libva-utils --run vainfo</code> | 您可以通过运行以下命令来测试您的配置:<code>nix-shell -p libva-utils --run vainfo</code> | ||
有关更多信息,请参阅 [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Arch Linux wiki 的硬件视频加速]。 | 有关更多信息,请参阅 [https://wiki.archlinux.org/index.php/Hardware_video_acceleration#Verification Arch Linux wiki 的硬件视频加速]。 | ||
<span id="Applications"></span> | <span id="Applications"></span> | ||
== 应用 == | == 应用 == | ||
<span id="Chromium"></span> | |||
<div class="mw-translate-fuzzy"> | |||
=== Chromium === | === Chromium === | ||
请参阅 [[Special:MyLanguage/Chromium#Accelerated_video_playback|Chromium 视频加速]]. | 请参阅 [[Special:MyLanguage/Chromium#Accelerated_video_playback|Chromium 视频加速]]. | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
See [[Chromium#Accelerated_video_playback]]. | |||
</div> | |||
=== Firefox === | === Firefox === | ||
请参阅 [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Arch Linux wiki 的 Firefox 部分]. | 请参阅 [https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration Arch Linux wiki 的 Firefox 部分]. | ||
=== MPV === | === MPV === | ||
您可以将以下配置放在 {{ic|~/.config/mpv/mpv.conf}} 中: | 您可以将以下配置放在 {{ic|~/.config/mpv/mpv.conf}} 中: | ||
<syntaxHighlight lang=ini> | <syntaxHighlight lang=ini> | ||
hwdec=auto | hwdec=auto | ||
</syntaxHighlight> | </syntaxHighlight> | ||
请参阅 [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux wiki 的 mpv 部分]. | 请参阅 [https://wiki.archlinux.org/title/mpv#Hardware_video_acceleration Arch Linux wiki 的 mpv 部分]. | ||
<span id="Also_see"></span> | |||
<div class="mw-translate-fuzzy"> | |||
== 另请参阅 == | == 另请参阅 == | ||
* [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki 的硬件视频加速]。 | * [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki 的硬件视频加速]。 | ||
* [https://github.com/NixOS/nixos-hardware nixos-hardware] 包含各种硬件类型的示例配置。 | * [https://github.com/NixOS/nixos-hardware nixos-hardware] 包含各种硬件类型的示例配置。 | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
* [https://wiki.archlinux.org/index.php/Hardware_video_acceleration Arch Linux wiki#Hardware video acceleration]. | |||
* [https://wiki.gentoo.org/wiki/VAAPI Gentoo Wiki#VAAPI.] | |||
* [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 18:49, 15 August 2026
NixOS 中的视频播放加速通常是通过向 hardware.graphics.extraPackages 添加相关包来完成的。
安装
Intel
❄︎ /etc/nixos/configuration.nix
{
pkgs,
...
}:
{
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
{
pkgs,
...
}:
{
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 的硬件视频加速。
- nixos-hardware 包含各种硬件类型的示例配置。
- Arch Linux wiki#Hardware video acceleration.
- Gentoo Wiki#VAAPI.
- nixos-hardware has example configurations for various types of hardware.