解决ffmpeg无法调用intel QSV转码一例
最近在Debian下使用ffmpeg,调用intel QSV转换视频时遇到一个问题
废话
原本我使用的命令是
ffmpeg -i 1.mp4 -b:v 4000k -c:v h264_qsv -preset fast -c:a copy -y -stats 2.mp4
h264_qsv 是 ffmpeg 中的一个编码器,可以使用Intel QSV(Quick Sync Video)来实现硬件加速技术来进行H.264视频的编码
最近新换了硬件,于是顺手也重做了系统,发现问题来了。使用上述命令转码时,提示
[AVHWDeviceContext @ 0x65217f5774c0] Failed to initialise VAAPI connection: -1 (unknown libva error).
[h264_qsv @ 0x65217e1a8dc0] Failed to create a VAAPI device.
Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 – maybe incorrect parameters such as bit_rate, rate, width or height
首先我想到的是,查看 /dev/dir
root@AIO:~# ls /dev/dri
by-path card1 renderD128
能加载到核显啊,奇怪,再看看驱动
#安装驱动和vainfo
apt install intel-media-va-driver vainfo -y
root@AIO:~# vainfo
error: can't connect to X server!
libva info: VA-API version 1.17.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_17
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.17 (libva 2.12.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 23.1.1 ()
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
驱动也是一切正常啊~~
期间各种搜索和折腾,直到翻阅到debian下关于硬件加速的官方文档:https://wiki.debian.org/HardwareVideoAcceleration#VA-API
有句话点醒了我
For Intel, it’s split generationally, and into free and non-free drivers. The non-free drivers are necessary to encode media while the free drivers can only decode
对于英特尔来说,它按代数分为free和non-free驱动程序。non-free驱动程序是编码媒体所必需的,而free驱动程序只能解码
我日哦!
解决
给apt加上 non-free non-free-firmware
#/etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
apt update
更新一下,然后安装 non-free 版驱动
apt install intel-media-va-driver-non-free
再次尝试,恢复正常