目录
目的
最近有学习下ffmpeg,以前正好在搞视频的时候,有稍微了解了下qsv这个东东
查找资料
在的Intel-Media-SDK
的官网瞅瞅看到了ffmpeg专门的一个网站
https://trac.ffmpeg.org/wiki/Hardware/QuickSync
里面找到了安装的方式,但是要换内核,这个之后用虚拟机搞一下
新发现
根据一个老哥的博客,通过vaapi的方式调用集成显卡也可以
Ubuntu
vaapi-ffmpeg开发环境搭建:https://blog.jianchihu.net/ubuntu-vaapi-ffmpeg-build.html
测试了下,在抽i帧方面,2k分辨率,速度要比软件快一点,cpu占用率不满一核,我是j1900 4核,软解每次都跑满
1.基本库安装
utry@ubuntu:~/ttff$ 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:
utry@ubuntu:~/ttff$ git clone https://github.com/intel/libva
utry@ubuntu:~/ttff$ cd libva
utry@ubuntu:~/ttff$ ./autogen.sh
utry@ubuntu:~/ttff$ ./configure
utry@ubuntu:~/ttff$ make -j8
utry@ubuntu:~/ttff$ sudo make install
intel-vaapi-driver:
主要在我们的程序与Intel 集显之间起桥梁作用。传输打包的缓存以及命令到i965驱动(开源的intel集显驱动,已集成在Linux内核中),用于硬件加速的视频编解码,着色器处理等。
utry@ubuntu:~/ttff$ git clone https://github.com/intel/intel-vaapi-driver
utry@ubuntu:~/ttff$ cd intel-vaapi-driver
utry@ubuntu:~/ttff$ ./autogen.sh
utry@ubuntu:~/ttff$ ./configure
utry@ubuntu:~/ttff$ make -j8
utry@ubuntu:~/ttff$ sudo make install
libva-utils:
提供一系列 VA API相关的测试。比如vainfo命令,可以用来检测我们的硬件支持哪些VA API编解码特性。
utry@ubuntu:~/ttff$ git clone https://github.com/intel/libva-utils
utry@ubuntu:~/ttff$ cd libva-utils
utry@ubuntu:~/ttff$ ./autogen.sh
utry@ubuntu:~/ttff$ ./configure
utry@ubuntu:~/ttff$ make -j8
utry@ubuntu:~/ttff$ sudo make install
检测安装的成果
查看我们的显卡设备:
我这个是1900,没有独显
utry@utry:~/ttff/intel-vaapi-driver$ ls /dev/dri/
card0 renderD128
utry@utry:~/ttff/intel-vaapi-driver$ sudo cat /sys/kernel/debug/dri/128/name
i915 dev=0000:00:02.0 unique=0000:00:02.0
下面开始通过vainfo命令验证显卡支持情况:
utry@utry:~/ttff/libva-utils$ vainfo --display drm --device /dev/dri/renderD128
vainfo: error while loading shared libraries: libva-x11.so.2: cannot open shared object file: No such file or directory
报错是因为没有把/usr/local/lib/
加到环境变量里
我这加到.bashrc
里去
再source
以下就可以了
utry@utry:~/ttff/libva-utils$ source ~/.bashrc
utry@utry:~/ttff/libva-utils$ vainfo --display drm --device /dev/dri/renderD128
libva info: VA-API version 1.10.0
libva info: Trying to open /usr/local/lib/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /usr/local/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_10
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.10 (libva 2.10.0.pre1)
vainfo: Driver version: Intel i965 driver for Intel(R) Bay Trail - 2.4.0.pre1 (2.3.0-31-gd87db21)
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264StereoHigh : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc
VAProfileJPEGBaseline : VAEntrypointVLD
我这个古董cpu,支持也就少太多
接下来要验证一下对vaapi编解码调用:
使用intel-gpu-tools工具测试,没有正常消息打印:
然后是编译ffmpeg
./configure --pkg-config-flags="--static" --extra-libs="-lpthread -lm" --enable-gpl --enable-vaapi --enable-libx264 --enable-nonfree
ffmpeg测试:
我这个u不支持265,我选个264的编码测试下
先是软解, fps 0.8
utry@utry:~/ttff$ date +%Y-%m-%d' '%H-%M-%S.%N | cut -b 1-23; ffmpeg -i "video.MP4" -vf "select=eq(pict_type\,I)" -vsync vfr -qscale:v 2 -f image2 "%08d.jpg";date +%Y-%m-%d' '%H-%M-%S.%N | cut -b 1-23
2020-11-24 15-42-53.874
ffmpeg version N-99983-g01eb052 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
configuration: --pkg-config-flags=--static --extra-libs='-lpthread -lm' --enable-gpl --enable-vaapi --enable-libx264 --enable-nonfree
libavutil 56. 60.100 / 56. 60.100
libavcodec 58.112.103 / 58.112.103
libavformat 58. 64.100 / 58. 64.100
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 90.100 / 7. 90.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.MP4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2020-09-09T03:21:38.000000Z
com.android.version: 10
Duration: 00:03:29.78, start: 0.000000, bitrate: 28358 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 3840x2160, 28136 kb/s, SAR 1:1 DAR 16:9, 29.89 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x4346980] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '%08d.jpg':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
com.android.version: 10
encoder : Lavf58.64.100
Stream #0:0(eng): Video: mjpeg, yuvj420p(pc, smpte170m/bt470bg/bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.92 fps, 29.92 tbn, 29.92 tbc (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : VideoHandle
encoder : Lavc58.112.103 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame= 209 fps=0.8 q=2.0 Lsize=N/A time=00:03:28.84 bitrate=N/A speed=0.841x
video:93497kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
2020-11-24 15-47-02.418
utry@utry:~/ttff$
硬解 :fps 1.1
utry@utry:~/ttff$ date +%Y-%m-%d' '%H-%M-%S.%N | cut -b 1-23; ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "video.MP4" -vf "select=eq(pict_type\,I)" -vsync vfr -qscale:v 2 -f image2 "%08d.jpg";date +%Y-%m-%d' '%H-%M-%S.%N | cut -b 1-23
2020-11-24 15-50-23.331
ffmpeg version N-99983-g01eb052 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
configuration: --pkg-config-flags=--static --extra-libs='-lpthread -lm' --enable-gpl --enable-vaapi --enable-libx264 --enable-nonfree
libavutil 56. 60.100 / 56. 60.100
libavcodec 58.112.103 / 58.112.103
libavformat 58. 64.100 / 58. 64.100
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 90.100 / 7. 90.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.MP4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2020-09-09T03:21:38.000000Z
com.android.version: 10
Duration: 00:03:29.78, start: 0.000000, bitrate: 28358 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 3840x2160, 28136 kb/s, SAR 1:1 DAR 16:9, 29.89 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x4d82500] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '%08d.jpg':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
com.android.version: 10
encoder : Lavf58.64.100
Stream #0:0(eng): Video: mjpeg, yuvj420p(pc, smpte170m/bt470bg/bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.92 fps, 29.92 tbn, 29.92 tbc (default)
Metadata:
creation_time : 2020-09-09T03:21:38.000000Z
handler_name : VideoHandle
encoder : Lavc58.112.103 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame= 209 fps=1.1 q=2.0 Lsize=N/A time=00:03:28.84 bitrate=N/A speed=1.13x
video:93497kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
2020-11-24 15-53-29.202
utry@utry:~/ttff$
总结
我这个u太老了,265都解不了。。。硬件相对于软解,帧率提升将近40%,然后cpu基本上单核60%,软解的话,cpu是直接吃满的,集显可以用