Ubuntu编译安装libva

该笔记是我编译libva(VAAPI)记录,基于Ubuntu 16.04,想用intel核显解码。

一、VAAPI的介绍

在Linux上支持GPU加速。
vaapi:https://www.freedesktop.org/wiki/Software/vaapi/

在Linux / X11上,有两个用于硬件视频解码的竞争接口:

  • Intel的VA-API
  • NVIDIA的VDPAU

通常,VAAPI用于Intel和Broadcom图形卡,而VDPAU用于AMD / ATI和NVIDIA卡。

VA-API:

VA-API是一个开源库和API规范,可以访问图形硬件加速功能以进行视频处理。它由一个主库和每个支持的硬件供应商的特定于驱动程序的加速后端组成。

VA API是一个统一的编解码规范,类似Windows上的Dxva方案,主要由各大显卡厂商在驱动中实现。目前主要Intel与AMD实现这个VA API方案,不过AMD上支持的编解码特性比较少,也只是部分支持。对于Intel来说,基本上带集显的都支持VA API。

在Ubuntu发行版上,首先安装硬件支持包:i965-va-driver,libva-intel-vaapi-driver和vainfo,然后在Preferences→Input&Codecs中激活GPU硬件加速。

  • $ sudo apt-get install i965-va-driver libva-intel-vaapi-driver vainfo

VDPAU:

VDPAU是一个开源库,API允许视频程序将部分视频解码过程和视频后处理卸载到GPU视频硬件。如果VDPAU可用,CPU使用率可以显着降低。

英特尔显卡不提供VDPAU。幸运的是,有一个名为的开源项目libvdpau-va-gl,它是一个VDPAU驱动程序,它使用OpenGL来加速绘图和缩放,以及VA-API(如果可用)来加速视频解码。您可以在某些英特尔芯片上使用它。

可以打开终端使用命令查看开启的接口信息:
$ lspci |grep VGA
00:02.0 VGA compatible controller: Intel Corporation Device 3e92
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1b83 (rev a1)

如果没有看到Intel Corporation Device,则需要在BIOS里开启核显:看到有IGFX等类似设置,具体百度。


二、vainfo、libva、intel-vaapi-driver编译与安装

首先给大家理顺VAAPI里面各种软件包的主次关系:

  • libva:也就是传说中的VAAPI,是一个开放源代码的提供硬件解码功能的模块;
  • va-i965-driver:Intel显卡的VAAPI后端,负责连接Intel显示卡驱动与VAAPI。
  • xvba-video:AMD/ATi显卡的VAAPI后端,负责连接AMD/ATi显示卡驱动与VAAPI。
  • vdpau:NV显卡的VAAPI后端

示卡驱动与VAAPI的接口:

  • AMD/ATi显卡:xvba: https://launchpad.net/ubuntu/+source/xvba-video
  • Intel显卡:i965-va-driver: 源里面应该会有。
  • NV显卡:请用Synaptic软件包管理器搜索安装vadpu,源里面应该会有。

VAAPI开源硬件解码模块:

  • libva1, libva-dev, libva-x11-1, libva-glx1, libva-tpi1, vainfo:https://launchpad.net/ubuntu/+source/libva/1.0.12-2

通过将vaapi值添加到USE变量,可以在系统范围内启用VAAPI支持:

文件 /etc/portage/make.conf
USE = “vaapi”

启用VAAPI支持将引入x11-libs / libva包,该包具有以下USE标记:
x11-libs / libva的USE标志 适用于Linux的视频加速(VA)API

  • drm 启用VA / DRM API支持。
  • utils 安装VA-API实用程序。
  • wayland 启用dev-libs / wayland后端

1.vainfo工具

vainfo工具用于查看libva库调用信息。

$ sudo apt install vainfo #将会依赖安装:libva-drm1,libva-wayland1,libva-x11-1,libva1
$ vainfo
# 将会输出一些调用信息
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

vainfo支持调用nvidia显卡,但需要先安装nvidia_video驱动:

$ sudo apt install vdpau-va-driver
#查看库文件
$ ll /usr/lib/x86_64-linux-gnu/dri/
#将查看到有个nvidia_drv_video.so文件
lrwxrwxrwx   1 root root       18 4月   7  2016 nvidia_drv_video.so -> vdpau_drv_video.so
#此时使用vainfo查看调用情况
$ vainfo
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'nvidia'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.0)
vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.4
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG4Simple            :	VAEntrypointVLD
      VAProfileMPEG4AdvancedSimple    :	VAEntrypointVLD
      VAProfileH264Baseline           :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD

2.libva环境变量

检查一下看是否正确配置了libva环境变量,libva环境变量可以配置调用使用哪个库:

$ set | grep LIBVA #或者:$ env |grep LIBVA
#应输出如下内容:
LIBVA_DRIVER_NAME=i965 #iHD #i965 #nvidia
LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri
#如果没有,请根据库路径将这些添加到系统环境变量:$ gedit ~/.bashrc
#在~/.bashrc文件中添加下面两行(永久),或者直接在终端输入(仅限本次)
export LIBVA_DRIVER_NAME=i965 #iHD #i965 #nvidia
export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri

3.检查版本

#查看libva版本
dpkg-query --showformat='${Package}: ${Version}\n' --show | grep libva
#查看vainfo版本
dpkg-query --showformat='${Package}: ${Version}\n' --show | grep vainfo
#查看i965版本
dpkg-query --showformat='${Package}: ${Version}\n' --show | grep i965

例:(我运行的结果)

# List installed libva packages
$ dpkg-query --showformat='${Package}: ${Version}\n' --show | grep libva
libva-dev: 1.7.0-1ubuntu0.1
libva-drm1: 1.7.0-1ubuntu0.1
libva-egl1: 1.7.0-1ubuntu0.1
libva-glx1: 1.7.0-1ubuntu0.1
libva-tpi1: 1.7.0-1ubuntu0.1
libva-wayland1: 1.7.0-1ubuntu0.1
libva-x11-1: 1.7.0-1ubuntu0.1
libva1: 1.7.0-1ubuntu0.1
libva1: 1.7.0-1ubuntu0.1
# The vainfo installed
$ dpkg-query --showformat='${Package}: ${Version}\n' --show | grep vainfo
vainfo: 1.7.0-1ubuntu0.1
# List installed i915 Intel VAAPI driver
$ dpkg-query --showformat='${Package}: ${Version}\n' --show | grep i965
i965-va-driver: 1.7.0-1

4.vainfo调用intel核显

vainfo支持调用intel核显,但需要先安装i965-va-driver驱动。
intel的vaapi编译安装是一个大坑,我经历了很多波折,尝试了多种方法去解决(可查阅本文后面的下半部分),。
ssss

#查看是否安装了驱动
$ apt list i965-va-driver
Listing... Done
i965-va-driver/xenial,now 1.7.0-1 amd64 [installed,automatic]
#如果没有安装,则进行安装
$ sudo apt install -y i965-va-driver

#此时使用vainfo查看调用情况(注:要先将libva调用库改为i965,即intel的VAAPI库。)
$ export LIBVA_DRIVER_NAME=i965
$ vainfo
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
vainfo: intel_driver.c:100: intel_driver_init: Assertion `(((struct drm_state *)(ctx)->drm_state)->auth_type == (VA_DRM_AUTH_DRI1)) || (((struct drm_state *)(ctx)->drm_state)->auth_type == (VA_DRM_AUTH_DRI2)) || (((struct drm_state *)(ctx)->drm_state)->auth_type == (VA_DRM_AUTH_CUSTOM))' failed.
Aborted (core dumped)

分析:

  • 1.可能是直接使用apt安装存在支持问题,可尝试源码编译安装;
  • 2.看信息应该是va_drm相关的问题。

尝试1:尝试源码编译

经过仔细考虑怀疑是这些驱动的版本兼容问题,我尝试自己编译intel的vaapi驱动:

#一些必要的依赖项
$ sudo apt-get install libx11-dev libtool libdrm-dev build-essential autoconf libva-dev
#源码
$ git clone https://github.com/intel/intel-vaapi-driver.git
$ cd intel-vaapi-driver/
$ ./autogen.sh
#此时存在一些依赖项的版本问题:
#configure: error: Package requirements (libva >= 1.4.0) were not met:
#Requested 'libva >= 1.4.0' but version of libva is 1.3.0

看信息提示,我们的libva版本太低,而我们安装的这个版本是使用apt安装的,看来我们需要自己从源码编译libva进行安装了(可以就用 1.4.0版本,不过我使用的是直接git下来的版本)。

编译libva
#依赖
$ sudo apt install -y libc6 libdrm-intel1 libdrm2 libva-x11-1 libva1 multiarch-support
#源码
$ git clone https://github.com/intel/libva.git
$ cd libva/
#编译
$ ./autogen.sh -with-drivers-path=/usr/lib/x86_64-linux-gnu/dri
$ make -j12
$ sudo make install
#完成后返回intel-vaapi-driver目录,再次配置并编译:
$ cd ../intel-vaapi-driver/
$ ./autogen.sh
#我在配置路径的时候发现配置无用,路径仍然是默认的/usr/local/lib/dri/
#没去深究,我继续编译安装,最后手动将/usr/local/lib/dri/i965_drv_video.so库链接到/usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
#后来发现是libva必须要先修改安装路径,然后intel-vaapi-driver的修改才能起作用
$ ./configure --prefix=/usr/lib/x86_64-linux-gnu/dri/
$ make -j12
$ sudo make install
#$ sudo ln -s /usr/local/lib/dri/i965_drv_video.so /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
#$ sudo ln -s /usr/local/lib/dri/i965_drv_video.la /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.la

此时使用vainfo查看调用情况,这次异常不一样了,似乎是某内部函数异常:

$ vainfo
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so has no function __vaDriverInit_0_32
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

我在GitHub上有找到类似的问题,但并不能解决我这出现的情况,后来提了issue:https://github.com/intel/intel-vaapi-driver/issues/455


后来,我查到的大部分人们的版本为:libva info: VA-API version 0.34.0,而我的是0.39.0。
经查询:0.34.0对应的libva版本是1.2.1,所以下载对应版本:https://github.com/intel/libva/archive/libva-1.2.1.tar.gz
解压后进入目录,进行编译安装:

$ ./autogen.sh -with-drivers-path=/usr/lib/x86_64-linux-gnu/dri
$ make -j12
$ sudo make install
#完成后使用vainfo查看
$ vainfo
libva info: VA-API version 0.34.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so has no function __vaDriverInit_0_32
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
#可以看到VA-API版本已经为0.34.0了,接下来重新编译intel-vaapi-driver
$ cd intel-vaapi-driver
$ ./autogen.sh
#会出现错误:
configure: error: Package requirements (libva >= 1.4.0) were not met:
Requested 'libva >= 1.4.0' but version of libva is 0.34.0

我们的intel-vaapi-driver也应该使用旧版本,经检查应该使用:intel-vaapi-driver_1.2.1版本。下载:https://github.com/intel/intel-vaapi-driver/archive/1.2.1.tar.gz
解压后进入目录,进行编译安装:

$ cd ../intel-vaapi-driver-1.2.1/
$ ./autogen.sh
$ make -j12

但是编译出现了错误,问题可能出在源码里吧,因为新版本编译都正常,`
只可惜新版本运行调用有异常,而旧版本又编译不过。

Traceback (most recent call last):
  File "../../gpp.py", line 200, in <module>
    writeblocks(outfile, blocks)
  File "../../gpp.py", line 168, in writeblocks
    do_writeblock(block, [])
  File "../../gpp.py", line 161, in do_writeblock
    while check_cond(block.param_op, for_curs[0], block.param_limit):
  File "../../gpp.py", line 138, in check_cond
    assert type(cur) == int
AssertionError
make[5]: Leaving directory '/home/toson/soft/intel-vaapi-driver-1.2.0/src/shaders/post_processing/gen5_6'
Makefile:376: recipe for target 'all-recursive' failed
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory '/home/toson/soft/intel-vaapi-driver-1.2.0/src/shaders/post_processing'
Makefile:377: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/home/toson/soft/intel-vaapi-driver-1.2.0/src/shaders'
Makefile:941: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/toson/soft/intel-vaapi-driver-1.2.0/src'
Makefile:533: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/toson/soft/intel-vaapi-driver-1.2.0/src'
Makefile:410: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

尝试2:尝试VA-API版本0.40.0

网上看到的有人用VA-API版本0.40.0调通了:https://bugzilla.redhat.com/show_bug.cgi?id=1491186
我开始尝试对应的版本:Intel i965 driver for Intel® Sandybridge Mobile - 1.8.3
libva - 1.8.3下载:https://github.com/tosonw/libva/archive/libva-1.8.3.tar.gz
对应的intel-vaapi-driver版本:https://github.com/intel/intel-vaapi-driver/archive/1.8.3.tar.gz

$ cd libva-libva-1.8.3
$ ./autogen.sh -with-drivers-path=/usr/lib/x86_64-linux-gnu/dri
#可以得到信息,配置通过:
libva - 1.8.3 (VA-API 0.40.0)
Installation prefix .............. : /usr/local
Default driver path .............. : /usr/lib/x86_64-linux-gnu/dri
Extra window systems ............. : drm x11 glx egl wayland
Build documentation .............. : no
Build with messaging ............. : yes
#开始编译
$ make -j12
$ sudo make install

以上是libva安装完成,接下来编译安装intel-vaapi-driver:

$ cd intel-vaapi-driver-1.8.3
$ ./autogen.sh
#可以得到信息,配置通过:
intel-vaapi-driver configuration summary:
VA-API version ................... : 0.40.0
VA-API drivers path .............. : /usr/lib/x86_64-linux-gnu/dri
Windowing systems ................ : drm x11 wayland
Build tests ...................... : no
#开始编译
$ make -j12
$ sudo make install

接下来运行vainfo:

$ vainfo
libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_40
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so init failed
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

仍然未成功。

尝试3:根据Intel官网

2018Q1 Intel Graphics Stack Recipe
查看:https://01.org/linuxgraphics/downloads/2018q1-intel-graphics-stack-recipe
Download Links:

  • Linux Kernel - 4.16
  • Mesa - 18.0
  • Libdrm - 2.4.91
  • Libva - 2.1.0
  • Vaapi intel-driver - 2.1.0
  • Cairo - 1.15.10
  • Intel-gpu-tools - 1.22
  • Xserver - 1.19.99.901
#解压libva-2.1.0
$ cd libva-2.1.0
$ ./configure
libva - 2.1.0 (VA-API 1.1.0)
Installation prefix .............. : /usr/local
Default driver path .............. : ${exec_prefix}/lib/dri
Extra window systems ............. : drm x11 glx wayland
Build documentation .............. : no
Build with messaging ............. : yes
$ make -j12
$ sudo make install

#解压intel-vaapi-driver-2.1.0
$ cd ../intel-vaapi-driver-2.1.0
$ ./configure #--prefix=/usr/lib/x86_64-linux-gnu/dri/
intel-vaapi-driver configuration summary:
VA-API version ................... : 1.1.0
VA-API drivers path .............. : /usr/lib/x86_64-linux-gnu/dri
Windowing systems ................ : drm x11 wayland
Build tests ...................... : no
$ make -j12
$ sudo make install

#运行vainfo
$ vainfo
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'i965'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so has no function __vaDriverInit_0_32
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

尝试4:根据UbuntuHandbook网站

在Ubuntu中启用英特尔图形卡上的硬件加速:http://ubuntuhandbook.org/index.php/2013/10/enable-hardware-acceleration-on-intel-graphics-cards-in-ubuntu/

在Ubuntu上通过PPA安装libvdpau-va-gl

Github上的libvdpau-va-gl:https://github.com/i-rinat/libvdpau-va-gl
其实直接apt安装:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install libvdpau-va-gl1

要安装Intel HD Graphics的VAAPI驱动程序:

sudo apt-get install i965-va-driver

例如,要使用驱动程序启动应用程序,请启动firefox:

VDPAU_DRIVER=va_gl firefox
#对此,我测试使用:VDPAU_DRIVER=va_gl vlc
#然而

要强制Adobe Flash使用硬件加速:

sudo mkdir -p /etc/adobe
echo "EnableLinuxHWVideoDecode=1" | sudo tee /etc/adobe/mms.cfg
echo "OverrideGPUValidation=1" | sudo tee -a /etc/adobe/mms.cfg

要在系统范围内启用驱动程序(不推荐):

sudo sed -i "s/^# \[/\[/g" /etc/X11/Xsession.d/20vdpau-va-gl
sudo sed -i "s/^# export/ export/g" /etc/X11/Xsession.d/20vdpau-va-gl

尝试5:根据博客

Linux下Intel集成显卡驱动安装:https://blog.csdn.net/sidely/article/details/42092721
下载最新的驱动包 xf86-video-intel 2.15.0:https://01.org/linuxgraphics/community/xf86-video-intel
我没找到2.15.0,在2.13.0和2.19.0之间我选择了2.19.0(xf86-video-intel-screen-conv-api.tar.gz):https://gitlab.freedesktop.org/xorg/driver/xf86-video-intel/-/archive/screen-conv-api/xf86-video-intel-screen-conv-api.tar.gz

$ sudo apt-get install xserver-xorg-dev x11proto-core-dev x11proto-xf86dri-dev xutils-dev
$ cd xf86-video-intel-screen-conv-api
$ ./autogen.sh
$ make -j12
#编译异常,文件丢失
uxa-priv.h:47:22: fatal error: mibstore.h: No such file or directory

尝试6:根据博客

Ubuntu vaapi-ffmpeg开发环境搭建:https://blog.jianchihu.net/ubuntu-vaapi-ffmpeg-build.html
文章主要讲VA API开发环境的搭建,主要针对H264编解码。开发系统为ubuntu18.04.2 LTS server版本。

基本库安装
$ sudo apt-get -y install autoconf automake build-essential libass-dev libtool pkg-config \
texinfo zlib1g-dev libva-dev cmake mercurial libdrm-dev libvorbis-dev libogg-dev git \
libx11-dev libperl-dev libpciaccess-dev libpciaccess0 xorg-dev git-core libfreetype6-dev \
libsdl2-dev libtool libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev wget zlib1g-dev
VA API相关库驱动安装

Libva:

$ git clone https://github.com/intel/libva
$ cd libva
$ ./autogen.sh
$ ./configure
libva - 2.5.0.pre1 (VA-API 1.5.0)
Installation prefix .............. : /usr/local
Default driver path .............. : ${exec_prefix}/lib/dri
Extra window systems ............. : drm x11 glx wayland
Build documentation .............. : no
Build with messaging ............. : yes
$ make -j12
$ sudo make install

intel-vaapi-driver:
主要在我们的程序与Intel 集显之间起桥梁作用。传输打包的缓存以及命令到i965驱动(开源的intel集显驱动,已集成在Linux内核中),用于硬件加速的视频编解码,着色器处理等。

$ git clone https://github.com/intel/intel-vaapi-driver
$ cd intel-vaapi-driver
$ ./autogen.sh
$ ./configure
intel-vaapi-driver configuration summary:
VA-API version ................... : 1.5.0
VA-API drivers path .............. : /usr/lib/x86_64-linux-gnu/dri
Windowing systems ................ : drm x11 wayland
Build tests ...................... : no
$ make -j12
$ sudo make install

libva-utils:
提供一系列 VA API相关的测试。比如vainfo命令,可以用来检测我们的硬件支持哪些VA API编解码特性。

$ git clone https://github.com/intel/libva-utils
$ cd libva-utils
$ ./autogen.sh
$ ./configure
libva-utils - 2.4.0.pre1
Libva VA-API version ............. : 1.5.0
Installation prefix .............. : /usr/local
Extra window systems ............. : drm x11 wayland
Enable Unit-tests .................... : no
$ make -j12
$ sudo make install
检测安装的成果
#查看我们的显卡设备:
$ ls /dev/dri/
card0  card1  renderD128  renderD129
#可以看到我的电脑有两张显卡,一张独显,一张集显。
$ sudo cat /sys/kernel/debug/dri/128/name
i915 dev=0000:00:02.0 unique=0000:00:02.0
$ sudo cat /sys/kernel/debug/dri/129/name
nvidia-drm dev=0000:01:00.0 unique=0000:01:00.0

下面开始通过vainfo命令验证显卡支持情况:

$ vainfo --display drm --device /dev/dri/renderD128
libva info: VA-API version 1.5.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/local/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_5
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.5 (libva 2.5.0.pre1)
vainfo: Driver version: Intel i965 driver for Intel(R) Coffee Lake - 2.4.0.pre1 (2.3.0-17-g7b859a9)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointEncSlice
      VAProfileVP9Profile2            :	VAEntrypointVLD
$ vainfo --display drm --device /dev/dri/renderD129
libva info: VA-API version 1.5.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
vaInitialize failed with error code -1 (unknown libva error),exit

看似成功了,但是要加上–display drm才行,我在github上找了相关issue:
https://github.com/intel/libva-utils/issues/120
https://github.com/intel/intel-vaapi-driver/issues/293
表面上的解决:

#编辑文件:
$ gedit ~/.bash_aliases
#在新的一行添加:
alias vainfo='vainfo --display drm --device /dev/dri/renderD128'
#这个时候就可以直接使用vainfo
接下来要验证一下对vaapi编解码调用:

使用intel-gpu-tools工具测试,没有正常消息打印:

$ sudo apt install -y intel-gpu-tools
$ sudo intel_gpu_top
                   render busy:   0%:                                        render space: 0/4096

                          task  percent busy
#也试过:
$ sudo intel-gpu-overlay
#  gpu信息一直为:0%
ffmpeg测试:

得到输出信息,看信息应该是完成了VAAPI的加载,但是提示:Driver not found in known nonstandard list, using standard behaviour.(使用标准行为在已知的非标准列表中找不到驱动程序。)
后经过调试,感觉drm不支持h264编码???:Decoder h264 does not support device type drm.

$ ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i http://vodm0pihssv.vod.126.net/edu-video/nos/mp4/2017/10/26/1007445810_45aec1a65d42425b84c5e14782151d7b_sd.mp4 -c:v hevc_vaapi -low_power 1 -qscale:v 20 -y test.h264
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
  configuration: --enable-libmfx --enable-encoder=h264_qsv --enable-decoder=h264_qsv --enable-shared --disable-static
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
[AVHWDeviceContext @ 0x9bb340] Opened VA display via DRM device /dev/dri/renderD128.
[AVHWDeviceContext @ 0x9bb340] libva: VA-API version 1.5.0
[AVHWDeviceContext @ 0x9bb340] libva: va_getDriverName() returns 0
[AVHWDeviceContext @ 0x9bb340] libva: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
[AVHWDeviceContext @ 0x9bb340] libva: Found init function __vaDriverInit_1_5
[AVHWDeviceContext @ 0x9bb340] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x9bb340] Initialised VAAPI connection: version 1.5
[AVHWDeviceContext @ 0x9bb340] VAAPI driver: Intel i965 driver for Intel(R) Coffee Lake - 2.4.0.pre1 (2.3.0-17-g7b859a9).
[AVHWDeviceContext @ 0x9bb340] Driver not found in known nonstandard list, using standard behaviour.
[tcp @ 0x9cd400] Starting connection attempt to 122.72.101.186 port 80
[tcp @ 0x9cd400] Successfully connected to 122.72.101.186 port 80
[h264 @ 0x9cfb00] Reinit context to 960x544, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://vodm0pihssv.vod.126.net/edu-video/nos/mp4/2017/10/26/1007445810_45aec1a65d42425b84c5e14782151d7b_sd.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
    description     : Transcoded by Arctime 2.0 Pro
  Duration: 00:06:54.84, start: 0.000000, bitrate: 1014 kb/s
    Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 960x540 (960x544) [SAR 1:1 DAR 16:9], 881 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 126 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_vaapi))
Press [q] to stop, [?] for help
[h264 @ 0xa08400] Reinit context to 960x544, pix_fmt: vaapi_vld
[graph 0 input from stream 0:0 @ 0xe7e280] w:960 h:540 pixfmt:vaapi_vld tb:1/12800 fr:25/1 sar:1/1 sws_param:flags=2
[hevc_vaapi @ 0x9d1a00] Input surface format is nv12.
[hevc_vaapi @ 0x9d1a00] Using VAAPI profile VAProfileHEVCMain (17).
[hevc_vaapi @ 0x9d1a00] No usable encoding entrypoint found for profile VAProfileHEVCMain (17).
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
[AVIOContext @ 0xb7b680] Statistics: 0 seeks, 0 writeouts
[AVIOContext @ 0x9d6d00] Statistics: 413299 bytes read, 0 seeks
Conversion failed!

上述ffmpeg命令分解:
内部hwaccel解码器通过-hwaccel选项启用。软件解码器正常启动,但如果它检测到可在硬件中解码的流,则它将尝试将所有重要处理委托给该硬件。如果流在硬件中不可解码(例如,它是不受支持的编解码器或配置文件),则它仍将自动在软件中解码。如果硬件需要特定设备才能运行(或需要区分多个设备,例如是否有多个图形卡可用),则可以使用-hwaccel_device选择一个。

-loglevel verbose #设置日志级别
-hwaccel vaapi #设置硬件加速方法
#引申:-hwaccels 显示可用的硬件加速方法
-vaapi_device /dev/dri/renderD128 #设置硬件
-hwaccel_output_format vaapi #
-c:v hevc_vaapi #-c:编解码器名称
-low_power 1 #
-qscale:v 20 #以<数值>质量为基础的VBR,取值0.01-255,约小质量越好
-y #覆盖已有文件

我又继续了几种测试:

#测试1:
$ ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i http://vodm0pihssv.vod.126.net/edu-video/nos/mp4/2017/10/26/1007445810_45aec1a65d42425b84c5e14782151d7b_sd.mp4 -c:v hevc_vaapi -low_power 1 -qscale:v 20 -r 24 -b:v 64k -bufsize 64k -s 640x480 -y test.h264
#测试2:
$ ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i 01.mp4 -c:v hevc_vaapi -r 24 -b:v 64k -bufsize 64k -s 1024x576 -y test.h264
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented

#测试3:
$ ffmpeg -loglevel verbose -init_hw_device vaapi=foo:/dev/dri/renderD128 -i 01.mp4 01.264
Error initializing an internal MFX session: unsupported (-3)
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

你可能感兴趣的:(视频编解码)