ubuntu下集成intel qsv加速ffmpeg转码

/

软硬件环境

  • ubuntu 16.04 64bit
  • ffmpeg binary 3.3.4
  • intel mss 2017-r3
  • Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz

准备工作

安装MSS

intel 安装包下载地址

https://software.intel.com/en-us/blogs/2017/07/11/whats-new-in-intel-media-server-studio-2017-r3,下载community的版本,这个是免费的

  1. tar xvf MediaServerStudioEssentials2017R3.tar.gz
  2. cd MediaServerStudioEssentials2017R3
  3. tar xvf SDK2017Production16.5.2.tar.gz
  4. cd SDK2017Production16.5.2
  5. cd Generic(我这里是ubuntu系统,如果是centos就进入CentOS目录)
  6. # 安装libva
  7. cd opt/intel/mediasdk/opensource/libva/1.67.0.pre1-64009
  8. tar xvf libva-1.67.0.pre1.tar.bz2
  9. cd libva-1.67.0.pre1
  10. ./configure
  11. make
  12. sudo make install
  13. # 安装libdrm
  14. cd ../../../../../../../
  15. cd opt/intel/mediasdk/opensource/libdrm/2.4.67-64009
  16. tar xvf libdrm-2.4.67.tar.bz2
  17. cd libdrm-2.4.67
  18. ./configure
  19. make
  20. sudo make install
  21. cd ../../../../../../
  22. tar xvf intel-linux-media_generic_16.5.2-64009_64bit.tar.gz
  23. sudo install_media.sh
  24. sudo reboot

在~/.bashrc中添加环境变量设置语句

  1. LD_LIBRARY_PATH=/usr/local/lib:/usr/lib64
  2. LIBVA_DRIVER_NAME=iHD
  3. LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib64

系统重启后,检查上述安装是否成功

  1. djstava@ThinkPad:~$ lsmod | grep 'i915'
  2. i915 1208320 12
  3. i2c_algo_bit 16384 2 i915,radeon
  4. drm_kms_helper 155648 2 i915,radeon
  5. drm 364544 16 ttm,i915,drm_kms_helper,radeon
  6. video 40960 2 i915,thinkpad_acpi
  1. djstava@ThinkPad:~/ffmpeg-3.3.4$ vainfo
  2. libva info: VA-API version 0.99.0
  3. libva info: va_getDriverName() returns 0
  4. libva info: User requested driver 'iHD'
  5. libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
  6. libva info: Found init function __vaDriverInit_0_32
  7. libva info: va_openDriver() returns 0
  8. vainfo: VA-API version: 0.99 (libva 1.67.0.pre1)
  9. vainfo: Driver version: 16.5.2.64009-ubit
  10. vainfo: Supported profile and entrypoints
  11. VAProfileH264ConstrainedBaseline: VAEntrypointVLD
  12. VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
  13. VAProfileH264ConstrainedBaseline: <unknown entrypoint>
  14. VAProfileH264ConstrainedBaseline: <unknown entrypoint>
  15. VAProfileH264Main : VAEntrypointVLD
  16. VAProfileH264Main : VAEntrypointEncSlice
  17. VAProfileH264Main : <unknown entrypoint>
  18. VAProfileH264Main : <unknown entrypoint>
  19. VAProfileH264High : VAEntrypointVLD
  20. VAProfileH264High : VAEntrypointEncSlice
  21. VAProfileH264High : <unknown entrypoint>
  22. VAProfileH264High : <unknown entrypoint>
  23. VAProfileMPEG2Simple : VAEntrypointEncSlice
  24. VAProfileMPEG2Simple : VAEntrypointVLD
  25. VAProfileMPEG2Main : VAEntrypointEncSlice
  26. VAProfileMPEG2Main : VAEntrypointVLD
  27. VAProfileVC1Advanced : VAEntrypointVLD
  28. VAProfileVC1Main : VAEntrypointVLD
  29. VAProfileVC1Simple : VAEntrypointVLD
  30. VAProfileJPEGBaseline : VAEntrypointVLD
  31. VAProfileJPEGBaseline : VAEntrypointEncPicture
  32. VAProfileVP8Version0_3 : VAEntrypointEncSlice
  33. VAProfileVP8Version0_3 : VAEntrypointVLD
  34. VAProfileVP8Version0_3 : <unknown entrypoint>
  35. VAProfileVP9Profile0 : <unknown entrypoint>
  36. <unknown profile> : VAEntrypointVideoProc
  37. VAProfileNone : VAEntrypointVideoProc
  38. VAProfileNone : <unknown entrypoint>
编译kernel

下载地址

https://www.kernel.org/pub/linux/kernel/v4.x/,下载4.4版本,这个版本号必须要和MSS里提供的kernel补丁版本对应

  1. tar xvf linux-4.4.tar.gz
  2. cd linux-4.4
  3. cp -r MediaServerStudioEssentials2017R3/SDK2017Production16.5.2/Generic/opt/intel/mediasdk/opensource/patches/kmd/4.4/intel-kernel-patches .
  4. for i in intel-kernel-patches/*.patch; do patch -p1 < $i; done
  5. make olddefconfig
  6. make
  7. make modules_install
  8. sudo make install
  9. sudo reboot

编译比较耗时,静静等待

编译安装ffmpeg

通过apt-get安装的ffmpeg本身不支持h264_qsv选项(windows版本支持),因此必须自己去重新编译,首先安装必备的工具包

  1. sudo apt-get install libvdpau-dev libvorbis-dev libass-dev libgnutls-dev frei0r-plugins-dev libopencore-amrwb-dev libopencore-amrnb-dev libopenjpeg-dev libopus-dev libsoxr-dev libvo-amrwbenc-dev libvpx-dev libwebp-dev libxvidcore-dev

在/opt/intel/mediasdk/include中创建文件夹mfx,并把include下的所有头文件拷贝到mfx文件夹中,然后

  1. mkdir -p /opt/intel/mediasdk/lib64/pkgconfig
  2. touch /opt/intel/mediasdk/lib64/pkgconfig/libmfx.pc

libmfx.pc文件内容如下

  1. prefix=/opt/intel/mediasdk
  2. exec_prefix=${prefix}
  3. libdir=${prefix}/lib/lin_x64
  4. includedir=${prefix}/include
  5. Name: libmfx
  6. Description: Intel Media Server Studio SDK
  7. Version: 16.4.2
  8. Libs: -L${libdir} -lmfx -lva -lstdc++ -ldl -lva-drm -ldrm
  9. Cflags: -I${includedir} -I/usr/include/libdrm

最后一步,删除/usr/lib64下的所有libdrm*和libva*,我在这里被坑了很久,多个drm和va会导致ffmpeg编译时报错,如下

ffmpeg_qsv_01

ffmpeg 3.3.4源码包下载地址

https://www.ffmpeg.org/download.html#get-sources

  1. tar xvf ffmpeg-3.3.4.tar.bz2
  2. cd ffmpeg-3.3.4
  3. ./configure --enable-gpl --enable-version3 --enable-static --disable-debug --disable-indev=sndio --disable-outdev=sndio --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid
  4. make
  5. sudo make install

期间一般都会出现各种错误,通过查看config.log文件,依个解决.

测试

通过一下命令查看

  1. djstava@ThinkPad:~/ffmpeg-3.3.4$ ffmpeg -codecs |grep qsv
  2. ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  3. built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  4. configuration: --enable-version3 --enable-libfdk-aac --enable-libmp3lame --enable-libx264 --enable-libmfx --extra-cflags=-I/opt/intel/mediasdk/include --extra-ldflags=-L/opt/intel/mediasdk/lib/lin_x64 --extra-libs=-lmfx --extra-libs=-ldl --enable-librtmp --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads
  5. libavutil 55. 58.100 / 55. 58.100
  6. libavcodec 57. 89.100 / 57. 89.100
  7. libavformat 57. 71.100 / 57. 71.100
  8. libavdevice 57. 6.100 / 57. 6.100
  9. libavfilter 6. 82.100 / 6. 82.100
  10. libswscale 4. 6.100 / 4. 6.100
  11. libswresample 2. 7.100 / 2. 7.100
  12. libpostproc 54. 5.100 / 54. 5.100
  13. DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_qsv h264_vdpau h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc h264_qsv h264_vaapi nvenc nvenc_h264 )
  14. DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_qsv hevc_cuvid ) (encoders: nvenc_hevc hevc_nvenc hevc_qsv hevc_vaapi )
  15. DEV.L. mpeg2video MPEG-2 video (decoders: mpeg2video mpegvideo mpegvideo_vdpau mpeg2_qsv mpeg2_cuvid ) (encoders: mpeg2video mpeg2_qsv mpeg2_vaapi )
  16. D.V.L. vc1 SMPTE VC-1 (decoders: vc1 vc1_vdpau vc1_qsv vc1_cuvid )
  17. DEV.L. vp8 On2 VP8 (decoders: vp8 vp8_cuvid vp8_qsv ) (encoders: vp8_vaapi )

参考资料

http://blog.csdn.net/ww506772362/article/details/49865437

https://www.intel.com/content/www/us/en/architecture-and-technology/quick-sync-video/quick-sync-video-installation.html

https://github.com/Intel-Media-SDK/MediaSDK

https://trac.ffmpeg.org/wiki/Hardware/QuickSync

http://blog.csdn.net/leochen1983/article/details/72742656

转载请注明作者和出处,并添加本页链接。
原文链接: blog.xugaoxiang.com/14

给我留言