DEV Community

vast cow
vast cow

Posted on

Setting Up and Troubleshooting FFmpeg + Intel QSV on Rocky Linux 9

If you want to accelerate FFmpeg H.264 / HEVC encoding using the integrated GPU in an Intel CPU, you can use Intel Quick Sync Video (QSV).

However, on Linux—especially on RHEL-based distributions such as Rocky Linux 9—simply seeing:

FFmpeg recognizes h264_qsv
Enter fullscreen mode Exit fullscreen mode

does not mean QSV will actually work.

In fact, on Rocky Linux 9, I encountered errors like the following:

[AVHWDeviceContext @ 0x562042595380] Failed to initialise VAAPI connection: -1 (unknown libva error).
[h264_qsv @ 0x56204258e140] Failed to create a VAAPI device.
Error initializing output stream 0:0
Enter fullscreen mode Exit fullscreen mode

Even when explicitly specifying the Intel GPU with -qsv_device, I got:

[AVHWDeviceContext @ 0x55ac9a494500] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
Failed to set value '/dev/dri/renderD128' for option 'qsv_device': Input/output error
Enter fullscreen mode Exit fullscreen mode

This article explains how to set up FFmpeg + QSV on Rocky Linux 9 and the order in which these types of errors should be isolated and diagnosed.


Understanding the Layers Required for QSV to Work

The first important point is that QSV is not a standalone FFmpeg feature.

On Linux, access to the Intel GPU conceptually passes through several layers:

FFmpeg
↓
QSV
↓
Intel Media SDK / oneVPL
↓
Intel Media Driver
↓
VA-API / libva
↓
/dev/dri/renderD128
↓
i915 / xe
↓
Intel GPU
Enter fullscreen mode Exit fullscreen mode

Therefore, even if:

ffmpeg -encoders | grep qsv
Enter fullscreen mode Exit fullscreen mode

shows:

h264_qsv
hevc_qsv
Enter fullscreen mode Exit fullscreen mode

that alone does not mean the GPU is actually usable.

For example, QSV will not work if there is a problem at any one of these points:

  • Linux does not detect the Intel GPU
  • nomodeset is configured
  • i915 / xe is not loaded
  • /dev/dri/renderD128 cannot be accessed
  • libva is missing
  • Intel Media Driver is missing or cannot be loaded
  • The Media SDK / oneVPL runtime does not match
  • FFmpeg itself was not built with QSV support

Therefore, the basic troubleshooting approach is to verify each layer from the bottom up.


1. Check Whether Linux Detects the Intel GPU

First, check the PCI devices.

lspci -nn | grep -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

In this environment, the result was:

00:02.0 VGA compatible controller [0300]:
Intel Corporation GeminiLake [UHD Graphics 605] [8086:3184] (rev 03)
Enter fullscreen mode Exit fullscreen mode

This confirms that the Intel UHD Graphics 605, i.e. the Gemini Lake GPU, is detected.

Next, check the kernel driver.

lspci -nnk | grep -A4 -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

The result in this case was:

00:02.0 VGA compatible controller [0300]: Intel Corporation GeminiLake [UHD Graphics 605] [8086:3184] (rev 03)
DeviceName: Onboard - Video
Subsystem: Elitegroup Computer Systems Device [1019:a94d]
Kernel driver in use: i915
Kernel modules: i915
Enter fullscreen mode Exit fullscreen mode

The important line here is:

Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

Gemini Lake uses i915.

On newer Intel GPUs, xe may be used depending on the configuration.

You can also verify this with:

lsmod | grep -E 'i915|xe'
Enter fullscreen mode Exit fullscreen mode

2. Remove nomodeset If It Is Configured

When using an Intel iGPU with QSV / VA-API, specifying nomodeset in the kernel boot options can prevent the GPU driver from initializing correctly and can make QSV unusable.

First, check the current kernel command line.

cat /proc/cmdline
Enter fullscreen mode Exit fullscreen mode

If it contains:

nomodeset
Enter fullscreen mode Exit fullscreen mode

remove it.

nomodeset disables Kernel Mode Setting (KMS). Because it interferes with the normal initialization of DRM/KMS drivers such as i915, which are used with Intel GPUs, it can prevent /dev/dri/renderD128 from being created or cause VA-API initialization to fail even if a GPU device appears to exist.

On Rocky Linux 9, check the GRUB configuration.

sudo grubby --info=ALL | grep args
Enter fullscreen mode Exit fullscreen mode

If nomodeset is configured, you can remove it from all kernel entries.

sudo grubby --update-kernel=ALL --remove-args="nomodeset"
Enter fullscreen mode Exit fullscreen mode

After changing the setting, reboot.

sudo reboot
Enter fullscreen mode Exit fullscreen mode

After rebooting, check again.

cat /proc/cmdline
Enter fullscreen mode Exit fullscreen mode

After confirming that nomodeset is gone, run:

lspci -nnk | grep -A4 -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

and confirm that it shows:

Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

Then check the DRM devices as well.

ls -l /dev/dri/
Enter fullscreen mode Exit fullscreen mode

At a minimum, confirm that entries such as:

card0
renderD128
Enter fullscreen mode Exit fullscreen mode

have been created.


3. Check /dev/dri/renderD128

Next, check the DRM devices.

ls -l /dev/dri/
Enter fullscreen mode Exit fullscreen mode

In this environment, the output was:

drwxr-xr-x. 2 root root         80 Aug  7 16:04 by-path
crw-rw----. 1 root video  226,   0 Aug  7 16:04 card0
crw-rw-rw-. 1 root render 226, 128 Aug  7 16:04 renderD128
Enter fullscreen mode Exit fullscreen mode

For server-side QSV and VA-API usage, the especially important device is:

/dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

Even on a server that is not running X11 or Wayland, hardware encoding is possible as long as renderD128 is accessible.

In other words:

No GUI = QSV cannot be used
Enter fullscreen mode Exit fullscreen mode

is not true.

QSV can also be used on headless servers.


4. Check Permissions on renderD128

A typical device node looks like this:

crw-rw---- 1 root render ... /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

In that case, add the user running FFmpeg to the render group.

sudo usermod -aG render $USER
Enter fullscreen mode Exit fullscreen mode

Depending on the environment, membership in video may also be required, so this is also acceptable:

sudo usermod -aG video,render $USER
Enter fullscreen mode Exit fullscreen mode

After logging in again, verify with:

id
Enter fullscreen mode Exit fullscreen mode

If FFmpeg is launched from a systemd service, the required permissions must be granted not to the login user, but to the user running the service.

The same point matters when using Jellyfin, Plex, or custom transcoding workflows combined with MediaMTX.

In this environment, the device permissions were:

crw-rw-rw-. 1 root render ... renderD128
Enter fullscreen mode Exit fullscreen mode

so a simple Unix permission problem was unlikely.


5. Enable EPEL and RPM Fusion

The standard Rocky Linux 9 repositories may not contain all packages needed for FFmpeg and the Intel Media Driver stack.

First, add EPEL.

sudo dnf install -y epel-release
Enter fullscreen mode Exit fullscreen mode

Then add RPM Fusion Free / Nonfree.

sudo dnf install -y \
https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm \
https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm
Enter fullscreen mode Exit fullscreen mode

Then update the system.

sudo dnf update -y
Enter fullscreen mode Exit fullscreen mode

6. Install Intel Media Driver

For relatively recent Intel GPUs, Intel Media Driver—the iHD driver—is used as the VA-API driver.

With Rocky Linux 9 + RPM Fusion, install:

sudo dnf install -y intel-media-driver
Enter fullscreen mode Exit fullscreen mode

Intel Media Driver provides the VA-API backend:

/usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

The Intel UHD Graphics 605 / Gemini Lake used here is also supported by Intel Media Driver.


7. Install libva and vainfo

vainfo is extremely useful for verifying VA-API operation.

sudo dnf install -y libva libva-utils
Enter fullscreen mode Exit fullscreen mode

After installation, run:

vainfo
Enter fullscreen mode Exit fullscreen mode

However, on a server without a GUI, it is more reliable to specify the DRM device explicitly.

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

If everything is working correctly, the output should look roughly like this:

libva info: VA-API version ...
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_...
libva info: va_openDriver() returns 0
vainfo: Driver version: Intel iHD driver ...
Enter fullscreen mode Exit fullscreen mode

8. Explicitly Set LIBVA_DRIVER_NAME=iHD

If automatic detection does not work correctly, you can explicitly specify the VA-API driver to use.

LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

If you want to set it persistently, you can also use:

export LIBVA_DRIVER_NAME=iHD
Enter fullscreen mode Exit fullscreen mode

9. Intel Media SDK vs. oneVPL

Several names appear around QSV:

Intel Media SDK
libmfx
oneVPL
libvpl
intel-vpl-gpu-rt
Enter fullscreen mode Exit fullscreen mode

Intel's newer software stack has transitioned from the legacy Intel Media SDK to oneVPL.

However, when deciding what to install for FFmpeg on Rocky Linux 9, it is important to check which API stack your FFmpeg build was compiled against.

For the RPM Fusion FFmpeg 5.1.10 used here:

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

showed that it had been built with:

--enable-libmfx
Enter fullscreen mode Exit fullscreen mode

And when checking:

rpm -qa | grep -Ei 'libva|intel-media|libmfx|vpl'
Enter fullscreen mode Exit fullscreen mode

the result was:

libva-2.22.0-1.el9.x86_64
intel-mediasdk-21.3.5-1.el9.x86_64
libva-utils-2.11.1-1.el9.x86_64
Enter fullscreen mode Exit fullscreen mode

In this environment, FFmpeg uses QSV through libmfx, i.e. Intel Media SDK.

Therefore, it is safer not to assume that "Rocky 9 always requires libvpl + intel-vpl-gpu-rt."

First, check the configure options shown by:

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

10. Install FFmpeg

Install FFmpeg from RPM Fusion.

sudo dnf install -y ffmpeg
Enter fullscreen mode Exit fullscreen mode

Verify it.

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

11. Check Whether FFmpeg Supports QSV

First, check the list of hardware acceleration methods.

ffmpeg -hwaccels
Enter fullscreen mode Exit fullscreen mode

For the FFmpeg build used here, the result was:

Hardware acceleration methods:
vdpau
cuda
vaapi
qsv
drm
opencl
vulkan
Enter fullscreen mode Exit fullscreen mode

Here, you can confirm:

vaapi
qsv
Enter fullscreen mode Exit fullscreen mode

Next, check the QSV encoders.

ffmpeg -hide_banner -encoders | grep -E 'qsv|vaapi'
Enter fullscreen mode Exit fullscreen mode

In this environment, the output was:

V..... h264_qsv     H.264 / AVC ... (Intel Quick Sync Video acceleration)
V....D h264_vaapi   H.264/AVC (VAAPI)
V..... hevc_qsv     HEVC (Intel Quick Sync Video acceleration)
V....D hevc_vaapi   H.265/HEVC (VAAPI)
V..... mjpeg_qsv    MJPEG (Intel Quick Sync Video acceleration)
V....D mjpeg_vaapi  MJPEG (VAAPI)
V..... mpeg2_qsv    MPEG-2 video (Intel Quick Sync Video acceleration)
V....D mpeg2_vaapi  MPEG-2 (VAAPI)
V....D vp8_vaapi    VP8 (VAAPI)
V....D vp9_vaapi    VP9 (VAAPI)
V..... vp9_qsv      VP9 video (Intel Quick Sync Video acceleration)
Enter fullscreen mode Exit fullscreen mode

Seeing h264_qsv in the list and actually being able to use the GPU are two different things.


12. Get vainfo Working First

When troubleshooting QSV, it is usually faster to get:

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

working first rather than repeatedly changing FFmpeg options.

In this environment, it returned:

libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
Enter fullscreen mode Exit fullscreen mode

Because the GPU was detected, i915 was in use, and /dev/dri/renderD128 existed, this narrowed the problem down to the libva / Intel Media Driver area.


13. Check Which RPM Provides iHD_drv_video.so

ls -l /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

Then use:

rpm -qf /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

to check which RPM provides the file.

If you do not know which RPM contains it, you can also search with:

dnf provides '*/iHD_drv_video.so'
Enter fullscreen mode Exit fullscreen mode

The expected provider is an intel-media-driver package.

sudo dnf install -y intel-media-driver
Enter fullscreen mode Exit fullscreen mode

One important point is that intel-mediasdk and intel-media-driver are different packages.


14. Check the Driver's Library Dependencies

ldd /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

If this output contains:

not found
Enter fullscreen mode Exit fullscreen mode

then a required dependency is missing.


15. Check Package Sources and Versions

rpm -qi libva libva-utils intel-mediasdk intel-media-driver
Enter fullscreen mode Exit fullscreen mode

Or use:

dnf repoquery --installed \
--qf '%{name} %{version}-%{release} %{repoid}' \
libva libva-utils intel-mediasdk intel-media-driver
Enter fullscreen mode Exit fullscreen mode

16. Explicitly Test with iHD

LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

If it is working correctly, the output should include:

Trying to open /usr/lib64/dri/iHD_drv_video.so
Found init function ...
va_openDriver() returns 0
Enter fullscreen mode Exit fullscreen mode

17. Run a Standalone QSV Test

Once vainfo works correctly, test QSV encoding using a generated test pattern that is unrelated to any input video.

ffmpeg \
-qsv_device /dev/dri/renderD128 \
-f lavfi \
-i testsrc2=size=1280x720:rate=30 \
-t 5 \
-c:v h264_qsv \
-global_quality 23 \
-f null -
Enter fullscreen mode Exit fullscreen mode

If this succeeds, you can conclude that the H.264 QSV encoding path is functioning.


18. Isolate the Problem with VAAPI Encoding

ffmpeg \
-vaapi_device /dev/dri/renderD128 \
-f lavfi \
-i testsrc2=size=1280x720:rate=30 \
-vf 'format=nv12,hwupload' \
-t 5 \
-c:v h264_vaapi \
-f null -
Enter fullscreen mode Exit fullscreen mode
VAAPI QSV Possible Cause
NG NG VA-API / Intel Media Driver / GPU device side
OK NG Media SDK / oneVPL / QSV runtime side
OK OK GPU stack is healthy. Investigate the original FFmpeg command
NG OK An unusual configuration that is normally uncommon

19. Encode H.264 with QSV

ffmpeg \
-qsv_device /dev/dri/renderD128 \
-i input.mp4 \
-c:v h264_qsv \
-global_quality 23 \
-c:a copy \
output.mp4
Enter fullscreen mode Exit fullscreen mode

20. Encode HEVC / H.265 with QSV

ffmpeg \
-qsv_device /dev/dri/renderD128 \
-i input.mp4 \
-c:v hevc_qsv \
-global_quality 25 \
-c:a copy \
output.mp4
Enter fullscreen mode Exit fullscreen mode

21. QSV Decode + QSV Encode

ffmpeg \
-qsv_device /dev/dri/renderD128 \
-hwaccel qsv \
-hwaccel_output_format qsv \
-i input.mp4 \
-c:v h264_qsv \
-global_quality 23 \
-c:a copy \
output.mp4
Enter fullscreen mode Exit fullscreen mode

For troubleshooting, it is easier to isolate problems by starting with CPU decode + QSV encode.


22. The yuv420pnv12 Warning Is Not a Fatal Error

Incompatible pixel format 'yuv420p' for codec 'h264_qsv',
auto-selecting format 'nv12'
Enter fullscreen mode Exit fullscreen mode

This is unrelated to the VA-API error discussed here.

If necessary, you can explicitly specify:

-pix_fmt nv12
Enter fullscreen mode Exit fullscreen mode

23. ALSA Thread message queue blocking Is Also a Separate Issue

If you see:

[alsa] Thread message queue blocking;
consider raising the thread_queue_size option
Enter fullscreen mode Exit fullscreen mode

specify something like:

-thread_queue_size 1024
Enter fullscreen mode Exit fullscreen mode

before the ALSA input.


24. Example Rocky Linux 9 Setup

sudo dnf install -y epel-release
sudo dnf install -y \
https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm \
https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm
sudo dnf install -y \
ffmpeg \
libva \
libva-utils \
intel-media-driver
Enter fullscreen mode Exit fullscreen mode

In an environment like this one where ffmpeg -version includes:

--enable-libmfx
Enter fullscreen mode Exit fullscreen mode

this package is also a candidate:

sudo dnf install -y intel-mediasdk
Enter fullscreen mode Exit fullscreen mode

For Gemini Lake + RPM Fusion FFmpeg 5.1.x, a straightforward starting configuration is roughly:

sudo dnf install -y \
ffmpeg \
libva \
libva-utils \
intel-media-driver \
intel-mediasdk
Enter fullscreen mode Exit fullscreen mode

25. Final Verification Checklist

# 0. nomodeset
cat /proc/cmdline

# 1. GPU / kernel driver
lspci -nnk | grep -A4 -Ei 'VGA|Display'

# 2. Kernel module
lsmod | grep -E 'i915|xe'

# 3. DRM
ls -l /dev/dri/

# 4. Intel Media Driver
rpm -q intel-media-driver

# 5. iHD driver
ls -l /usr/lib64/dri/iHD_drv_video.so
rpm -qf /usr/lib64/dri/iHD_drv_video.so

# 6. VA-API
LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128

# 7. FFmpeg HW acceleration
ffmpeg -hwaccels

# 8. QSV encoders
ffmpeg -hide_banner -encoders | grep _qsv

# 9. QSV decoders
ffmpeg -hide_banner -decoders | grep _qsv

# 10. QSV encode test
ffmpeg \
-qsv_device /dev/dri/renderD128 \
-f lavfi \
-i testsrc2=size=1280x720:rate=30 \
-t 5 \
-c:v h264_qsv \
-global_quality 23 \
-f null -
Enter fullscreen mode Exit fullscreen mode

The verification order is easiest to understand as follows:

Presence of nomodeset
↓
Intel GPU
↓
i915 / xe
↓
/dev/dri/renderD128
↓
VA-API / libva
↓
Intel Media Driver
↓
Media SDK / oneVPL
↓
FFmpeg
Enter fullscreen mode Exit fullscreen mode

What We Learned with Gemini Lake / UHD Graphics 605

On the actual system used here:

Intel Corporation GeminiLake [UHD Graphics 605]
Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

and /dev/dri/renderD128 was also present.

In addition, FFmpeg had been built with --enable-libmfx, recognized qsv / vaapi, and could list encoders such as h264_qsv, hevc_qsv, and vp9_qsv.

However:

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

returned:

Trying to open /usr/lib64/dri/iHD_drv_video.so
va_openDriver() returns -1
Trying to open /usr/lib64/dri/i965_drv_video.so
va_openDriver() returns -1
Enter fullscreen mode Exit fullscreen mode

The QSV test also failed with:

Failed to initialise VAAPI connection
Device creation failed
Enter fullscreen mode Exit fullscreen mode

This shows that the problem is not with FFmpeg encoding options, but with the VA-API / Intel Media Driver layer.

In this situation, investigate the Intel Media Driver installation and dependencies in this order:

rpm -qf /usr/lib64/dri/iHD_drv_video.so
ldd /usr/lib64/dri/iHD_drv_video.so
LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

Summary

When using FFmpeg + Intel QSV on Rocky Linux 9, seeing h264_qsv in ffmpeg -encoders does not mean the setup is complete.

The required layers are roughly as follows:

Component Requirement Role
Disable nomodeset Important Allows DRM/KMS to initialize correctly
Intel GPU Required Hardware
i915 / xe Required Kernel GPU driver
/dev/dri/renderD128 Required DRM render node
libva Important in Linux QSV environments VA-API
intel-media-driver Important for supported Intel GPUs iHD_drv_video.so
intel-mediasdk For libmfx-based setups Legacy QSV runtime
libvpl For oneVPL-based setups oneVPL dispatcher
intel-vpl-gpu-rt For supported newer-generation GPUs oneVPL GPU implementation
QSV-enabled FFmpeg Required h264_qsv / hevc_qsv, etc.

In particular, if you see:

Failed to initialise VAAPI connection
Failed to create a VAAPI device
Enter fullscreen mode Exit fullscreen mode

the fastest approach is to check:

cat /proc/cmdline
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

before changing encoding options.

If nomodeset is still present, remove it. If vainfo does not work correctly, fix the VA-API / Intel Media Driver problem first.

When building a QSV environment on Rocky Linux 9, keep the following layers in mind:

nomodeset
↓
GPU
↓
Kernel driver
↓
DRM
↓
VA-API
↓
Intel Media Driver
↓
Media SDK / oneVPL
↓
FFmpeg
Enter fullscreen mode Exit fullscreen mode

The most reliable setup method is to verify proper operation one layer at a time, from the bottom up.

Rocky Linux 9 で FFmpeg + Intel QSV を使うためのセットアップとトラブルシューティング

Intel CPU の内蔵 GPU を使って FFmpeg の H.264 / HEVC エンコードを高速化したい場合、Intel Quick Sync Video(QSV)が利用できます。

しかし Linux、特に Rocky Linux 9 のような RHEL 系ディストリビューションでは、

FFmpeg が h264_qsv を認識している
Enter fullscreen mode Exit fullscreen mode

だけでは QSV は動きません。

実際、今回 Rocky Linux 9 上で次のようなエラーに遭遇しました。

[AVHWDeviceContext @ 0x562042595380] Failed to initialise VAAPI connection: -1 (unknown libva error).
[h264_qsv @ 0x56204258e140] Failed to create a VAAPI device.
Error initializing output stream 0:0
Enter fullscreen mode Exit fullscreen mode

さらに -qsv_device で Intel GPU を明示しても、

[AVHWDeviceContext @ 0x55ac9a494500] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
Failed to set value '/dev/dri/renderD128' for option 'qsv_device': Input/output error
Enter fullscreen mode Exit fullscreen mode

となりました。

この記事では、Rocky Linux 9 で FFmpeg + QSV をセットアップする方法と、こうしたエラーをどの順番で切り分けるべきかをまとめます。


QSV が動くまでのレイヤを理解する

最初に重要なのは、QSV は FFmpeg 単体の機能ではないということです。

Linux では概念的に次のような複数のレイヤを通って Intel GPU にアクセスします。

FFmpeg
  ↓
QSV
  ↓
Intel Media SDK / oneVPL
  ↓
Intel Media Driver
  ↓
VA-API / libva
  ↓
/dev/dri/renderD128
  ↓
i915 / xe
  ↓
Intel GPU
Enter fullscreen mode Exit fullscreen mode

そのため、

ffmpeg -encoders | grep qsv
Enter fullscreen mode Exit fullscreen mode


h264_qsv
hevc_qsv
Enter fullscreen mode Exit fullscreen mode

が表示されても、それだけでは GPU が実際に使えることを意味しません。

例えば、

  • Intel GPU を Linux が認識していない
  • nomodeset が設定されている
  • i915 / xe がロードされていない
  • /dev/dri/renderD128 にアクセスできない
  • libva がない
  • Intel Media Driver がない、またはロードできない
  • Media SDK / oneVPL runtime が合っていない
  • FFmpeg 自体が QSV 対応でビルドされていない

といったどこか一箇所でも問題があると、QSV は動きません。

したがって、下から順番に確認していくのがトラブルシューティングの基本です。


1. Intel GPU を Linux が認識しているか確認する

まず PCI デバイスを確認します。

lspci -nn | grep -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

今回の環境では、

00:02.0 VGA compatible controller [0300]:
Intel Corporation GeminiLake [UHD Graphics 605] [8086:3184] (rev 03)
Enter fullscreen mode Exit fullscreen mode

となりました。

Intel UHD Graphics 605、つまり Gemini Lake の GPU が認識されています。

次に、カーネルドライバを確認します。

lspci -nnk | grep -A4 -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

今回の結果は、

00:02.0 VGA compatible controller [0300]: Intel Corporation GeminiLake [UHD Graphics 605] [8086:3184] (rev 03)
        DeviceName: Onboard - Video
        Subsystem: Elitegroup Computer Systems Device [1019:a94d]
        Kernel driver in use: i915
        Kernel modules: i915
Enter fullscreen mode Exit fullscreen mode

でした。

ここで重要なのは、

Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

です。

Gemini Lake では i915 が使われます。

最近の Intel GPU では構成によって xe が使われることもあります。

念のため、

lsmod | grep -E 'i915|xe'
Enter fullscreen mode Exit fullscreen mode

でも確認できます。


2. nomodeset を設定している場合は外す

Intel iGPU を QSV / VA-API で使用する場合、カーネルの起動オプションに nomodeset を指定していると、GPU ドライバが正常に初期化されず、QSV が使えない原因になることがあります。

まず現在のカーネルコマンドラインを確認します。

cat /proc/cmdline
Enter fullscreen mode Exit fullscreen mode

ここに、

nomodeset
Enter fullscreen mode Exit fullscreen mode

が含まれている場合は削除します。

nomodeset は Kernel Mode Setting(KMS)を無効化するオプションです。Intel GPU で使用する i915 などの DRM/KMS ドライバの正常な初期化を妨げるため、/dev/dri/renderD128 が生成されない、あるいは GPU デバイスが存在していても VA-API の初期化に失敗する原因になり得ます。

Rocky Linux 9 では GRUB の設定を確認します。

sudo grubby --info=ALL | grep args
Enter fullscreen mode Exit fullscreen mode

nomodeset が設定されている場合は、全カーネルエントリから削除できます。

sudo grubby --update-kernel=ALL --remove-args="nomodeset"
Enter fullscreen mode Exit fullscreen mode

設定後、再起動します。

sudo reboot
Enter fullscreen mode Exit fullscreen mode

再起動後、もう一度確認します。

cat /proc/cmdline
Enter fullscreen mode Exit fullscreen mode

nomodeset が消えていることを確認した上で、

lspci -nnk | grep -A4 -Ei 'VGA|Display'
Enter fullscreen mode Exit fullscreen mode

を実行し、

Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

となっていることを確認します。

続いて DRM デバイスも確認します。

ls -l /dev/dri/
Enter fullscreen mode Exit fullscreen mode

最低限、

card0
renderD128
Enter fullscreen mode Exit fullscreen mode

などが生成されていることを確認します。


3. /dev/dri/renderD128 を確認する

次に DRM デバイスを確認します。

ls -l /dev/dri/
Enter fullscreen mode Exit fullscreen mode

今回の環境では、

drwxr-xr-x. 2 root root         80 Aug  7 16:04 by-path
crw-rw----. 1 root video  226,   0 Aug  7 16:04 card0
crw-rw-rw-. 1 root render 226, 128 Aug  7 16:04 renderD128
Enter fullscreen mode Exit fullscreen mode

となっていました。

QSV や VA-API のサーバ用途で特に重要なのが、

/dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

です。

X11 や Wayland を起動していないサーバでも、renderD128 にアクセスできればハードウェアエンコードできます。

つまり、

GUI がない = QSV が使えない
Enter fullscreen mode Exit fullscreen mode

ではありません。

ヘッドレスサーバでも利用可能です。


4. renderD128 の権限を確認する

典型的には次のようになっています。

crw-rw---- 1 root render ... /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

この場合、FFmpeg を実行するユーザーを render グループへ追加します。

sudo usermod -aG render $USER
Enter fullscreen mode Exit fullscreen mode

環境によっては video も必要になるため、

sudo usermod -aG video,render $USER
Enter fullscreen mode Exit fullscreen mode

としても構いません。

再ログイン後、

id
Enter fullscreen mode Exit fullscreen mode

で確認します。

systemd サービスから FFmpeg を起動する場合には、ログインユーザーではなくサービスを実行しているユーザーに権限が必要です。

Jellyfin、Plex、MediaMTX と組み合わせた独自トランスコード処理などでも、この点には注意が必要です。

今回の環境では、

crw-rw-rw-. 1 root render ... renderD128
Enter fullscreen mode Exit fullscreen mode

だったため、単純な Unix パーミッション不足である可能性は低い状態でした。


5. EPEL と RPM Fusion を有効にする

Rocky Linux 9 の標準リポジトリだけでは FFmpeg や Intel Media Driver 周辺のパッケージが不足する場合があります。

まず EPEL を追加します。

sudo dnf install -y epel-release
Enter fullscreen mode Exit fullscreen mode

続いて RPM Fusion Free / Nonfree を追加します。

sudo dnf install -y \
  https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm \
  https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm
Enter fullscreen mode Exit fullscreen mode

その後更新しておきます。

sudo dnf update -y
Enter fullscreen mode Exit fullscreen mode

6. Intel Media Driver をインストールする

Intel の比較的新しい GPU では、VA-API ドライバとして Intel Media Driver、つまり iHD ドライバを使用します。

Rocky Linux 9 + RPM Fusion なら、

sudo dnf install -y intel-media-driver
Enter fullscreen mode Exit fullscreen mode

をインストールします。

Intel Media Driver は VA-API バックエンドとなる、

/usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

を提供します。

今回使用した Intel UHD Graphics 605 / Gemini Lake も Intel Media Driver の対象です。


7. libva と vainfo をインストールする

VA-API の動作確認には vainfo が非常に便利です。

sudo dnf install -y libva libva-utils
Enter fullscreen mode Exit fullscreen mode

インストール後、

vainfo
Enter fullscreen mode Exit fullscreen mode

を実行します。

ただし GUI のないサーバでは、DRM デバイスを明示したほうが確実です。

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

正常なら、概ね次のようになります。

libva info: VA-API version ...
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_...
libva info: va_openDriver() returns 0

vainfo: Driver version: Intel iHD driver ...
Enter fullscreen mode Exit fullscreen mode

8. LIBVA_DRIVER_NAME=iHD で明示する

自動判定がうまくいかない場合には、使用する VA-API ドライバを明示できます。

LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

恒久的に指定したければ、

export LIBVA_DRIVER_NAME=iHD
Enter fullscreen mode Exit fullscreen mode

としても構いません。


9. Intel Media SDK と oneVPL の違い

QSV 周りでは、

Intel Media SDK
libmfx
oneVPL
libvpl
intel-vpl-gpu-rt
Enter fullscreen mode Exit fullscreen mode

といった名前が登場します。

Intel の新しいソフトウェアスタックは、従来の Intel Media SDK から oneVPL へ移行しています。

ただし Rocky Linux 9 の FFmpeg で何を入れるべきかは、使用している FFmpeg がどちらに対してビルドされているか確認することが重要です。

今回使用した RPM Fusion の FFmpeg 5.1.10 は、

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

を見ると、

--enable-libmfx
Enter fullscreen mode Exit fullscreen mode

でビルドされていました。

そして実際に、

rpm -qa | grep -Ei 'libva|intel-media|libmfx|vpl'
Enter fullscreen mode Exit fullscreen mode

を確認すると、

libva-2.22.0-1.el9.x86_64
intel-mediasdk-21.3.5-1.el9.x86_64
libva-utils-2.11.1-1.el9.x86_64
Enter fullscreen mode Exit fullscreen mode

となっていました。

この環境では FFmpeg が libmfx、つまり Intel Media SDK 経由の QSV を使用する構成です。

したがって、「Rocky 9 なら必ず libvpl + intel-vpl-gpu-rt をインストールする」と考えないほうが安全です。

まず、

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

の configure オプションを確認してください。


10. FFmpeg をインストールする

RPM Fusion から FFmpeg を入れます。

sudo dnf install -y ffmpeg
Enter fullscreen mode Exit fullscreen mode

確認します。

ffmpeg -version
Enter fullscreen mode Exit fullscreen mode

11. FFmpeg が QSV 対応か確認する

まずハードウェアアクセラレーション一覧を確認します。

ffmpeg -hwaccels
Enter fullscreen mode Exit fullscreen mode

今回の FFmpeg では、

Hardware acceleration methods:
vdpau
cuda
vaapi
qsv
drm
opencl
vulkan
Enter fullscreen mode Exit fullscreen mode

となっていました。

ここで、

vaapi
qsv
Enter fullscreen mode Exit fullscreen mode

が確認できます。

次に QSV エンコーダを確認します。

ffmpeg -hide_banner -encoders | grep -E 'qsv|vaapi'
Enter fullscreen mode Exit fullscreen mode

今回の環境では、

V..... h264_qsv     H.264 / AVC ... (Intel Quick Sync Video acceleration)
V....D h264_vaapi   H.264/AVC (VAAPI)
V..... hevc_qsv     HEVC (Intel Quick Sync Video acceleration)
V....D hevc_vaapi   H.265/HEVC (VAAPI)
V..... mjpeg_qsv    MJPEG (Intel Quick Sync Video acceleration)
V....D mjpeg_vaapi  MJPEG (VAAPI)
V..... mpeg2_qsv    MPEG-2 video (Intel Quick Sync Video acceleration)
V....D mpeg2_vaapi  MPEG-2 (VAAPI)
V....D vp8_vaapi    VP8 (VAAPI)
V....D vp9_vaapi    VP9 (VAAPI)
V..... vp9_qsv      VP9 video (Intel Quick Sync Video acceleration)
Enter fullscreen mode Exit fullscreen mode

となりました。

h264_qsv が一覧にあることと、実際に GPU が使用できることは別問題です。


12. まず vainfo を正常にする

QSV のトラブルシューティングでは、いきなり FFmpeg のオプションを変更し続けるより、

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

を最初に正常化したほうが早いです。

今回の環境では、

libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
Enter fullscreen mode Exit fullscreen mode

となっていました。

GPU は認識され、i915 も使用され、/dev/dri/renderD128 も存在しているため、問題は libva / Intel Media Driver 付近にあると切り分けられます。


13. iHD_drv_video.so がどの RPM に含まれるか確認する

ls -l /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

さらに、

rpm -qf /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

で、どの RPM が提供しているファイルか確認できます。

RPM が分からなければ、

dnf provides '*/iHD_drv_video.so'
Enter fullscreen mode Exit fullscreen mode

でも検索できます。

期待するのは intel-media-driver 系の RPM です。

sudo dnf install -y intel-media-driver
Enter fullscreen mode Exit fullscreen mode

ここで注意したいのが intel-mediasdkintel-media-driver は別物だということです。


14. ドライバの依存ライブラリを確認する

ldd /usr/lib64/dri/iHD_drv_video.so
Enter fullscreen mode Exit fullscreen mode

ここに、

not found
Enter fullscreen mode Exit fullscreen mode

があれば、その依存ライブラリが不足しています。


15. パッケージの出所とバージョンも確認する

rpm -qi libva libva-utils intel-mediasdk intel-media-driver
Enter fullscreen mode Exit fullscreen mode

または、

dnf repoquery --installed \
  --qf '%{name} %{version}-%{release} %{repoid}' \
  libva libva-utils intel-mediasdk intel-media-driver
Enter fullscreen mode Exit fullscreen mode

を使用します。


16. iHD を明示してテストする

LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

正常なら、

Trying to open /usr/lib64/dri/iHD_drv_video.so
Found init function ...
va_openDriver() returns 0
Enter fullscreen mode Exit fullscreen mode

となります。


17. QSV 単体テストをする

vainfo が正常になったら、入力動画とは無関係なテスト映像で QSV エンコードを確認します。

ffmpeg \
  -qsv_device /dev/dri/renderD128 \
  -f lavfi \
  -i testsrc2=size=1280x720:rate=30 \
  -t 5 \
  -c:v h264_qsv \
  -global_quality 23 \
  -f null -
Enter fullscreen mode Exit fullscreen mode

これが成功すれば H.264 QSV エンコード経路が動作していると判断できます。


18. VAAPI エンコードでも切り分ける

ffmpeg \
  -vaapi_device /dev/dri/renderD128 \
  -f lavfi \
  -i testsrc2=size=1280x720:rate=30 \
  -vf 'format=nv12,hwupload' \
  -t 5 \
  -c:v h264_vaapi \
  -f null -
Enter fullscreen mode Exit fullscreen mode
VAAPI QSV 考えられる原因
NG NG VA-API / Intel Media Driver / GPU デバイス側
OK NG Media SDK / oneVPL / QSV runtime 側
OK OK GPU スタックは正常。元の FFmpeg コマンドを調査
NG OK 通常はあまりない特殊な構成

19. QSV で H.264 をエンコードする

ffmpeg \
  -qsv_device /dev/dri/renderD128 \
  -i input.mp4 \
  -c:v h264_qsv \
  -global_quality 23 \
  -c:a copy \
  output.mp4
Enter fullscreen mode Exit fullscreen mode

20. HEVC / H.265 を QSV でエンコードする

ffmpeg \
  -qsv_device /dev/dri/renderD128 \
  -i input.mp4 \
  -c:v hevc_qsv \
  -global_quality 25 \
  -c:a copy \
  output.mp4
Enter fullscreen mode Exit fullscreen mode

21. QSV decode + QSV encode

ffmpeg \
  -qsv_device /dev/dri/renderD128 \
  -hwaccel qsv \
  -hwaccel_output_format qsv \
  -i input.mp4 \
  -c:v h264_qsv \
  -global_quality 23 \
  -c:a copy \
  output.mp4
Enter fullscreen mode Exit fullscreen mode

トラブルシューティングでは、まず CPU decode + QSV encode から始めるほうが切り分けやすくなります。


22. yuv420pnv12 の警告は致命的エラーではない

Incompatible pixel format 'yuv420p' for codec 'h264_qsv',
auto-selecting format 'nv12'
Enter fullscreen mode Exit fullscreen mode

これは今回の VA-API エラーとは別問題です。

必要なら、

-pix_fmt nv12
Enter fullscreen mode Exit fullscreen mode

を指定できます。


23. ALSA の Thread message queue blocking も別問題

[alsa] Thread message queue blocking;
consider raising the thread_queue_size option
Enter fullscreen mode Exit fullscreen mode

が出る場合は ALSA 入力の前に、

-thread_queue_size 1024
Enter fullscreen mode Exit fullscreen mode

などを指定します。


24. Rocky Linux 9 のセットアップ例

sudo dnf install -y epel-release

sudo dnf install -y \
  https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm \
  https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm

sudo dnf install -y \
  ffmpeg \
  libva \
  libva-utils \
  intel-media-driver
Enter fullscreen mode Exit fullscreen mode

今回のように ffmpeg -version に、

--enable-libmfx
Enter fullscreen mode Exit fullscreen mode

がある環境では、

sudo dnf install -y intel-mediasdk
Enter fullscreen mode Exit fullscreen mode

も候補になります。

Gemini Lake + RPM Fusion FFmpeg 5.1 系であれば、概ね、

sudo dnf install -y \
  ffmpeg \
  libva \
  libva-utils \
  intel-media-driver \
  intel-mediasdk
Enter fullscreen mode Exit fullscreen mode

という構成から始めるのが分かりやすいでしょう。


25. 最終確認チェックリスト

# 0. nomodeset
cat /proc/cmdline

# 1. GPU / kernel driver
lspci -nnk | grep -A4 -Ei 'VGA|Display'

# 2. Kernel module
lsmod | grep -E 'i915|xe'

# 3. DRM
ls -l /dev/dri/

# 4. Intel Media Driver
rpm -q intel-media-driver

# 5. iHD driver
ls -l /usr/lib64/dri/iHD_drv_video.so
rpm -qf /usr/lib64/dri/iHD_drv_video.so

# 6. VA-API
LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128

# 7. FFmpeg HW acceleration
ffmpeg -hwaccels

# 8. QSV encoders
ffmpeg -hide_banner -encoders | grep _qsv

# 9. QSV decoders
ffmpeg -hide_banner -decoders | grep _qsv

# 10. QSV encode test
ffmpeg \
  -qsv_device /dev/dri/renderD128 \
  -f lavfi \
  -i testsrc2=size=1280x720:rate=30 \
  -t 5 \
  -c:v h264_qsv \
  -global_quality 23 \
  -f null -
Enter fullscreen mode Exit fullscreen mode

確認順序は次のように考えると分かりやすくなります。

nomodeset の有無
↓
Intel GPU
↓
i915 / xe
↓
/dev/dri/renderD128
↓
VA-API / libva
↓
Intel Media Driver
↓
Media SDK / oneVPL
↓
FFmpeg
Enter fullscreen mode Exit fullscreen mode

今回の Gemini Lake / UHD Graphics 605 で分かったこと

今回の実機では、

Intel Corporation GeminiLake [UHD Graphics 605]
Kernel driver in use: i915
Enter fullscreen mode Exit fullscreen mode

であり、/dev/dri/renderD128 も存在していました。

さらに FFmpeg は --enable-libmfx 付きで、qsv / vaapi を認識し、h264_qsvhevc_qsvvp9_qsv なども列挙できました。

しかし、

vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

では、

Trying to open /usr/lib64/dri/iHD_drv_video.so
va_openDriver() returns -1

Trying to open /usr/lib64/dri/i965_drv_video.so
va_openDriver() returns -1
Enter fullscreen mode Exit fullscreen mode

となっていました。

QSV テストでも、

Failed to initialise VAAPI connection
Device creation failed
Enter fullscreen mode Exit fullscreen mode

となりました。

このことから、問題は FFmpeg のエンコードオプションではなく、VA-API / Intel Media Driver 層にあると切り分けられます。

このような場合は、

rpm -qf /usr/lib64/dri/iHD_drv_video.so
ldd /usr/lib64/dri/iHD_drv_video.so

LIBVA_DRIVER_NAME=iHD \
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

の順で Intel Media Driver の導入状態・依存関係を調べます。


まとめ

Rocky Linux 9 で FFmpeg + Intel QSV を使う場合、単に ffmpeg -encodersh264_qsv が表示されれば完了、というわけではありません。

必要になるレイヤは概ね次の通りです。

コンポーネント 必要性 役割
nomodeset 無効化 重要 DRM/KMS を正常に初期化
Intel GPU 必須 ハードウェア
i915 / xe 必須 Kernel GPU driver
/dev/dri/renderD128 必須 DRM render node
libva Linux QSV 環境で重要 VA-API
intel-media-driver 対応 Intel GPU で重要 iHD_drv_video.so
intel-mediasdk libmfx 構成 Legacy QSV runtime
libvpl oneVPL 構成 oneVPL dispatcher
intel-vpl-gpu-rt 対応する新世代 GPU oneVPL GPU implementation
QSV 対応 FFmpeg 必須 h264_qsv / hevc_qsv

特に、

Failed to initialise VAAPI connection
Failed to create a VAAPI device
Enter fullscreen mode Exit fullscreen mode

が出た場合には、エンコードオプションを変更する前に、

cat /proc/cmdline
vainfo --display drm --device /dev/dri/renderD128
Enter fullscreen mode Exit fullscreen mode

を確認するのが近道です。

nomodeset が残っていれば外し、vainfo が正常に動かなければ VA-API / Intel Media Driver の問題を先に解決します。

Rocky Linux 9 で QSV を構築するときは、

nomodeset
↓
GPU
↓
Kernel driver
↓
DRM
↓
VA-API
↓
Intel Media Driver
↓
Media SDK / oneVPL
↓
FFmpeg
Enter fullscreen mode Exit fullscreen mode

というレイヤを意識して、下から一段ずつ正常動作を確認するのが最も確実なセットアップ方法です。

Top comments (0)