Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Building a VAAPI enabled FFmpeg for use bound to the !/bin prefix

Build FFmpeg and libva with decode and encode hardware acceleration on an Intel-based validation testbed:

Build platform: Ubuntu

Install baseline dependencies first

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

Then add the Oibaf PPA, needed to install the latest development headers for libva:

sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade

Build the latest libva and all drivers from source:

First things first, build the dependency chain:

  1. libva:

Libva is an implementation for VA-API (Video Acceleration API)

VA-API is an open-source library and API specification, which provides access to graphics hardware acceleration capabilities for video processing. It consists of a main library and driver-specific acceleration backends for each supported hardware vendor. It is a prerequisite for building the VAAPI driver components below.

git clone https://github.com/01org/libva
cd libva
./autogen.sh
./configure
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install
  1. cmrt:

This is the C for Media Runtime GPU Kernel Manager for Intel G45 & HD Graphics family. it's a prerequisite for building the intel-hybrid-driver package.

git clone https://github.com/01org/cmrt
cd cmrt
./autogen.sh
./configure
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install
  1. intel-hybrid-driver:

This package provides support for WebM project VPx codecs. GPU acceleration is provided via media kernels executed on Intel GEN GPUs. The hybrid driver provides the CPU bound entropy (e.g., CPBAC) decoding and manages the GEN GPU media kernel parameters and buffers.

This package grants access to the VPX-series hybrid decode capabilities on supported hardware configurations.

git clone https://github.com/01org/intel-hybrid-driver
cd intel-hybrid-driver
./autogen.sh
./configure
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install
  1. intel-vaapi-driver:

This package provides the VA-API (Video Acceleration API) user mode driver for Intel GEN Graphics family SKUs. The current video driver back-end provides a bridge to the GEN GPUs through the packaging of buffers and commands to be sent to the i915 driver for exercising both hardware and shader functionality for video decode, encode, and processing. it also provides a wrapper to the intel-hybrid-driver when called up to handle VP8/9 hybrid decode tasks on supported hardware (when configured with the --enable-hybrid-codec option as shown below:).

git clone https://github.com/01org/intel-vaapi-driver
cd intel-vaapi-driver
./autogen.sh
./configure --enable-hybrid-codec
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install
  1. libva-utils:

This package provides a collection of tests for VA-API, such as vainfo, needed to validate a platform's supported features (encode, decode & postproc attributes on a per-codec basis by VAAPI entry points information).

git clone https://github.com/intel/libva-utils
cd libva-utils
./autogen.sh
./configure
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install

Platform environment variables:

Check if LIBVA environment variables are correctly configured:

set | grep LIBVA

Should output something like:

LIBVA_DRIVER_NAME=i965
LIBVA_DRIVERS_PATH=/usr/local/lib/dri

If not (as expected), set them on your system environment variables (/etc/environment) and reboot.

sudo systemctl reboot 

Verification:

When done, test the VAAPI supported featureset by running vainfo:

vainfo

The output on my current testbed is:

libva info: VA-API version 0.40.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_0_40
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.40 (libva 1.7.3)
vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 1.8.3.pre1 (glk-alpha-58-g5a984ae)
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
      VAProfileVP9Profile0            :	VAEntrypointVLD

Option 2: Skip building the dependencies manually and install them from a PPA (not recommended):

This can be accomplished by adding the Oibaf PPA and the xorg-edgers-PPA to the system, and rebooting when done:

sudo add-apt-repository  ppa:xorg-edgers/ppa
sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade && sudo systemctl reboot

On reboot, test the VAAPI supported featureset by running vainfo:

vainfo

Making a usable FFmpeg build to test the encoders:

Now, we will build an FFmpeg binary that can take advantage of VAAPI to test the encode and decode capabilities on the test platform.

Prepare the target directories first:

mkdir -p $HOME/bin
chown -Rc $USER:$USER $HOME/bin
mkdir -p ~/ffmpeg_sources

Include extra components as needed:

(a). Build and deploy nasm: Nasm is an assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.

Note that we've now switched away from Yasm to nasm, as this is the current assembler that x265,x264, among others, are adopting.

cd ~/ffmpeg_sources
wget wget http://www.nasm.us/pub/nasm/releasebuilds/2.14rc0/nasm-2.14rc0.tar.gz
tar xzvf nasm-2.14rc0.tar.gz
cd nasm-2.14rc0
./configure --prefix="$HOME/bin" --bindir="$HOME/bin"
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

(b). Build and deploy libx264 statically: This library provides a H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples. This requires ffmpeg to be configured with --enable-gpl --enable-libx264.

cd ~/ffmpeg_sources
git clone http://git.videolan.org/git/x264.git -b stable
cd x264/
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/bin" --bindir="$HOME/bin" --enable-static --disable-opencl
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install VERBOSE=1
make -j$(nproc) distclean

(c). Build and configure libx265: This library provides a H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.

sudo apt-get install cmake mercurial
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/bin" -DENABLE_SHARED:bool=off ../../source
make -j$(nproc) VERBOSE=1
make -j$(nproc) install VERBOSE=1
make -j$(nproc) clean VERBOSE=1

(d). Build and deploy the libfdk-aac library: This provides an AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples. This requires ffmpeg to be configured with --enable-libfdk-aac (and --enable-nonfree if you also included --enable-gpl).

cd ~/ffmpeg_sources
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$HOME/bin" --disable-shared
make -j$(nproc)
make -j$(nproc) install
make -j$(nproc) distclean

(e). Build and configure libvpx

   cd ~/ffmpeg_sources
   git clone https://github.com/webmproject/libvpx/
   cd libvpx
   ./configure --prefix="$HOME/bin" --enable-runtime-cpu-detect --enable-vp9 --enable-vp8 \
   --enable-postproc --enable-vp9-postproc --enable-multi-res-encoding --enable-webm-io --enable-vp9-highbitdepth --enable-onthefly-bitpacking --enable-realtime-only \
   --cpu=native --as=yasm
   time make -j$(nproc)
   time make -j$(nproc) install
   time make clean -j$(nproc)
   time make distclean

(f). Build LibVorbis

   cd ~/ffmpeg_sources
   wget -c -v http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.6.tar.xz
   tar -xvf libvorbis-1.3.6.tar.xz
   cd libvorbis-1.3.6
   ./configure --enable-static --prefix="$HOME/bin"
   time make -j$(nproc)
   time make -j$(nproc) install
   time make clean -j$(nproc)
   time make distclean

(g). Build FFmpeg:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure \
  --pkg-config-flags="--static" \
  --prefix="$HOME/bin" \
  --extra-cflags="-I$HOME/bin/include" \
  --extra-ldflags="-L$HOME/bin/lib" \
  --extra-cflags="-I/usr/local/include" \
  --extra-ldflags="-L/usr/local/lib" \
  --bindir="$HOME/bin" \
  --enable-debug=3 \
  --enable-vaapi \
  --enable-libvorbis \
  --enable-libvpx \
  --disable-debug \
  --enable-gpl \
  --cpu=native \
  --enable-opengl \
  --enable-libfdk-aac \
  --enable-libx264 \
  --enable-libx265 \
  --extra-libs=-lpthread \
  --enable-nonfree 
PATH="$HOME/bin:$PATH" make -j$(nproc) 
make -j$(nproc) install 
make -j$(nproc) distclean 
hash -r

Note: To get debug builds, omit the distclean step and the --disable-debug configure flag and you'll find the ffmpeg_g binary under the sources subdirectory.

We only want debug builds when an issue crops up and a gdb trace may be required for debugging purposes.

Sample snippets to test the new encoders:

Confirm that the VAAPI encoders have been built successfully:

ffmpeg  -hide_banner -encoders | grep vaapi 

 V..... h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 V..... hevc_vaapi           H.265/HEVC (VAAPI) (codec hevc)
 V..... mjpeg_vaapi          MJPEG (VAAPI) (codec mjpeg)
 V..... mpeg2_vaapi          MPEG-2 (VAAPI) (codec mpeg2video)
 V..... vp8_vaapi            VP8 (VAAPI) (codec vp8)

See the help documentation for each encoder in question:

ffmpeg -hide_banner -h encoder='encoder name'

Test the encoders;

Using GNU parallel, we will encode some mp4 files (4k H.264 test samples, 40 minutes each, AAC 6-channel audio) on the ~/src path on the system to VP8 and HEVC respectively using the examples below. Note that I've tuned the encoders to suit my use-cases, and re-scaling to 1080p is enabled. Adjust as necessary.

To VP8, launching 10 encode jobs simultaneously:

parallel -j 10 --verbose 'ffmpeg -loglevel debug -threads 4 -hwaccel vaapi -i "{}"  -vaapi_device /dev/dri/renderD129 -c:v vp8_vaapi -loop_filter_level:v 63 -loop_filter_sharpness:v 15 -b:v 4500k -maxrate:v 7500k -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' -c:a libvorbis -b:a 384k -ac 6 -f webm "{.}.webm"' ::: $(find . -type f -name '*.mp4')

To HEVC with GNU Parallel:

To HEVC Main Profile, launching 10 encode jobs simultaneously:

parallel -j 4 --verbose 'ffmpeg -loglevel debug -threads 4 -hwaccel vaapi -i "{}"  -vaapi_device /dev/dri/renderD129 -c:v hevc_vaapi -qp:v 19 -b:v 2100k -maxrate:v 3500k -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' -c:a libvorbis -b:a 384k -ac 6 -f matroska "{.}.mkv"' ::: $(find . -type f -name '*.mp4')

Some notes:

  1. Intel's QuickSync is very efficient. See the power utilization traces and average system loads with 10 encodes running simultaneously here.

  2. Skylake's HEVC encoder is very slow, and I suspect that on my hardware, may be slower than the software-based x265 encoder and kvazaar's HEVC encoders. However, its' quality, when well tuned, is significantly superior to other hardware-based encoders such as the Nvidia NVENC HEVC encoder on Maxwell GM200-series SKUs. The NVENC encoder on Pascal is however faster and superior to the one on Intel's Skylake HEVC encoder implementation.

  3. Unlike Nvidia's NVENC, there are no simultaneous encodes limitations on the consumer SKUs. I was able to run 10 encode sessions siumultaneously with VAAPI, whereas with NVENC, I'd have been limited to two maximum simultaneous encodes on the GeForce GTX series GPUs on the testbeds. Good work, Intel.

@makabar
Copy link

makabar commented Nov 28, 2017

hg clone https://bitbucket.org/multicoreware/x265
will break!
try
hg clone --insecure https://bitbucket.org/multicoreware/x265

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/bin/lib/pkgconfig" ./configure \
  --pkg-config-flags="--static" \
  --prefix="$HOME/bin" \
  --extra-cflags="-I$HOME/bin/include" \
  --extra-ldflags="-L$HOME/bin/lib" \
  --bindir="$HOME/bin" \
  --enable-debug=3 \
  --enable-vaapi \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-gpl \
  --cpu=native \
  --enable-opengl \
  --enable-libfdk-aac \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree 

breaks with
ERROR: x265 not found using pkg-config

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Nov 30, 2017

There's a known issue with building FFmpeg with libx265, and I've now included the fix for that (see the extra --extra-libs=-lpthread configuration option.

Loading

@TomiMc
Copy link

TomiMc commented Dec 31, 2017

mnn, why i am getting this error?

Stream mapping:
Stream #0:5 -> #0:0 (hevc (native) -> h264 (h264_vaapi))
Stream #0:0 -> #0:1 (ac3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[hevc @ 0x49e7080] No support for codec hevc profile 2.
[hevc @ 0x49e7080] Failed setup for format vaapi_vld: hwaccel initialisation returned error.
[h264_vaapi @ 0x49dda40] H.264 constrained baseline profile doesn't support encoding with B frames, disabling them.

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Jan 3, 2018

For one, what's your hardware?

Loading

@TomiMc
Copy link

TomiMc commented Jan 6, 2018

mnn i7 4770, maybe no support for hevc :).

Loading

@etiennepouliot
Copy link

etiennepouliot commented Jan 12, 2018

When I try to build libvpx
/usr/bin/ld: ./libvpx.a(inv_txfm_ssse3_x86_64.asm.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libvpx.a(quantize_ssse3_x86_64.asm.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: ./libvpx.a(subpel_variance_sse2.asm.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ./libvpx.a(highbd_subpel_variance_impl_sse2.asm.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status /home/etienne/ffmpeg_sources/libvpx-1.6.1/libs.mk:517: recipe for target 'test_intra_pred_speed' failed make[1]: *** [test_intra_pred_speed] Error 1 make[1]: *** Waiting for unfinished jobs.... Makefile:17: recipe for target '.DEFAULT' failed make: *** [.DEFAULT] Error 2

Any ideas ?

Loading

@etiennepouliot
Copy link

etiennepouliot commented Jan 13, 2018

Solved my issue by rebuilding everything with sharing enabled (--enable-shared).

Loading

@Sub-7
Copy link

Sub-7 commented Jan 20, 2018

(g). Build FFmpeg:
stops at : PATH = "$ HOME / bin" make -j $ (nproc)
after : export PATH = $ PATH: $ HOME / bin
then it works

FFmpeg:
libavutil / libavutil.a (hwcontext_vaapi.o): In function vaapi_device_connect ':
/root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c🔢 Undefined reference to vaSetErrorCallback ' /root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1235: Undefined reference to vaSetInfoCallback '
libavutil / libavutil.a (hwcontext_vaapi.o): In function vaapi_device_connect ': /root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1234: Undefined reference to vaSetErrorCallback '
/root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1235: Undefined reference to vaSetInfoCallback ' libavutil / libavutil.a (hwcontext_vaapi.o): In function vaapi_device_connect ':
/root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c🔢 Undefined reference to vaSetErrorCallback ' /root/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1235: Undefined reference to vaSetInfoCallback '
collect2: error: ld returned 1 exit status
Makefile 107: The rule for target "ffprobe_g" failed
make: *** [ffprobe_g] Error 1
make: *** Waiting for unfinished processes ...
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
Makefile 107: The rule for target "ffmpeg_g" failed
make: *** [ffmpeg_g] Error 1
Makefile: 107: The rule for target "ffplay_g" failed
make: *** [ffplay_g] ​​Error 1
`

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Jan 20, 2018

Hey @TomiMc,

Please disable -hwaccel vaapi when encoding to H.264 and your source file(s) are in the HEVC codec for the Video streams.

Haswell does not support HEVC decoding via VAAPI.

Loading

@dan-cristian
Copy link

dan-cristian commented Feb 6, 2018

I have the same issue as @Sub-7. Tried the recommended path export approach with no luck. Any more ideas please?

LD ffmpeg_g
LD ffprobe_g
libavutil/libavutil.a(hwcontext_vaapi.o): In function vaapi_device_connect': /home/haiot/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1234: undefined reference to vaSetErrorCallback'
/home/haiot/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1235: undefined reference to vaSetInfoCallback' collect2: error: ld returned 1 exit status Makefile:107: recipe for target 'ffmpeg_g' failed make: *** [ffmpeg_g] Error 1 make: *** Waiting for unfinished jobs.... libavutil/libavutil.a(hwcontext_vaapi.o): In function vaapi_device_connect':
/home/haiot/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c🔢 undefined reference to vaSetErrorCallback' /home/haiot/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1235: undefined reference to vaSetInfoCallback'
collect2: error: ld returned 1 exit status
Makefile:107: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1

My configure string:
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/bin/lib/pkgconfig" ./configure --pkg-config-flags="--static" --prefix="$HOME/bin" --extra-cflags="-I$HOME/bin/include" --extra-ldflags="-L$HOME/bin/lib" --bindir="$HOME/bin" --enable-debug=3 --enable-vaapi --enable-libvorbis --enable-gpl --cpu=native --enable-libfdk-aac --enable-libx264 --enable-libx265 --extra-libs=-lpthread --enable-nonfree

Loading

@dan-cristian
Copy link

dan-cristian commented Feb 6, 2018

If you get an error when compiling libx264, use the stable archive instead of the one indicated in the guide:

replace
wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2

with
wget http://download.videolan.org/pub/x264/snapshots/last_stable_x264.tar.bz2

Loading

@Edwardfpan
Copy link

Edwardfpan commented Feb 16, 2018

I have a Dell XPS 13 notebook.

I followed Option 2 and am able to encode using vaapi h264, vp8, but can't do so for vp9.

My command line is as follows,
ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 30 -i ./Sample.yuv -vaapi_device /dev/dri/renderD128 -c:v vp9_vaapi -vf 'format=nv12,hwupload' Sample.webm

And the error message is as,

[vp9_vaapi @ 0x56482b5ac0c0] Encoding entrypoint not found (19 / 6).
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
Conversion failed!

Tried to follow option 1, but can't even get h.264 or vp8 to work.

Any suggestions ?

Thanks a million!
Edward

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Mar 1, 2018

Hello @Edwardfpan,

What's the output of vainfo on your end?

Loading

@Edwardfpan
Copy link

Edwardfpan commented Mar 2, 2018

Hi @Brainiarc7,
Thank you for your response. Following is my 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_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.40 (libva 1.7.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Kabylake - 1.7.0
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
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
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Mar 5, 2018

Good, good, show me the output of:

ls -al /dev/dri

Perhaps you are using the wrong DRI render node?

Loading

@Edwardfpan
Copy link

Edwardfpan commented Mar 5, 2018

Here is the output.

amd@amd-XPS-13-9360:~/Downloads/video$ ls -al /dev/dri
total 0
drwxr-xr-x 2 root root 80 Feb 16 14:20 .
drwxr-xr-x 19 root root 4300 Mar 5 09:47 ..
crw-rw----+ 1 root video 226, 0 Feb 16 14:20 card0
crw-rw----+ 1 root video 226, 128 Feb 16 14:20 renderD128

Since I am able to encode vp8 using vp8_vaapi, I think the node should be correct.

Thank you for your kind help.

Loading

@chaoticryptidz
Copy link

chaoticryptidz commented Mar 16, 2018

libavutil/libavutil.a(hwcontext_vaapi.o): In function vaapi_device_connect': /home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1237: undefined reference to vaSetErrorCallback'
/home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1238: undefined reference to vaSetInfoCallback' collect2: error: ld returned 1 exit status Makefile:107: recipe for target 'ffplay_g' failed make: *** [ffplay_g] Error 1 make: *** Waiting for unfinished jobs.... libavutil/libavutil.a(hwcontext_vaapi.o): In function vaapi_device_connect':
/home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1237: undefined reference to vaSetErrorCallback' /home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1238: undefined reference to vaSetInfoCallback'
collect2: error: ld returned 1 exit status
Makefile:107: recipe for target 'ffmpeg_g' failed
make: *** [ffmpeg_g] Error 1
libavutil/libavutil.a(hwcontext_vaapi.o): In function vaapi_device_connect': /home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1237: undefined reference to vaSetErrorCallback'
/home/namedkitten/ffmpeg_sources/FFmpeg/libavutil/hwcontext_vaapi.c:1238: undefined reference to `vaSetInfoCallback'
collect2: error: ld returned 1 exit status
Makefile:107: recipe for target 'ffprobe_g' failed
make: *** [ffprobe_g] Error 1

using ffmpeg commit 1296a718dc62728b6601f694539a1c5ad8ad260c and libva commit b70a92e61c25ebc144f54a0086cf715757330782

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Mar 18, 2018

Hey @Edwardfpan,

I just noticed that you do not have a VP9 entry point for encodes (See the *Slice entries in your vainfo) despite the fact that you have an Intel Kabylake IGP.

That can be fixed by setting the correct LIBVA variables as shown below, and I'll also update my documentation here to point to that:

Verification:

Check if LIBVA environment variables are correctly configured:

set | grep LIBVA

Should output something like:

LIBVA_DRIVER_NAME=i965
LIBVA_DRIVERS_PATH=/usr/local/lib/dri

If not, add these, according to your library path, to your system environment variables (/etc/environment) and reboot.

When done, run:

vainfo | grep VP9

And confirm that the slice entry for VP9 exists.

For all encode paths, run:

vainfo | grep Slice

And verify the output.

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Mar 18, 2018

For these running into issues, the document has been updated.

Loading

@francoism90
Copy link

francoism90 commented Jul 1, 2018

@BBrainiarc7 Is it still true it doesn't work on Skylake?
$ ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 -vf 'format=nv12,hwupload' -c:v vp9_vaapi -b:v 5M output.webm

[libopus @ 0x55cc61397780] No bit rate set. Defaulting to 96000 bps.
[vp9_vaapi @ 0x55cc612cb900] Encoding entrypoint not found (19 / 6).
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
[libopus @ 0x55cc61397780] 1 frames left in the queue on closing
Conversion failed!

Many thanks!

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Jul 3, 2018

Hello @francoism90,

Yes, VP9 encoding in SKL is not supported at all.

My issue on the same got bushwhacked by the devs, yet this feature is mentioned in the Intel PRMS for SKL.

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Jul 3, 2018

Over time, I'll be adding documentation for OpenCL h/w accel for VP9 as a workaround for this shortcoming.

Loading

@terminalcommand
Copy link

terminalcommand commented Jul 7, 2018

If any of you following this tutorial encounter with the error:

vainfo: error while loading shared libraries: libva-x11.so.2: cannot open shared object file: No such file or directory

The solution is to run sudo ldconfig to rebuild the library cache. It starts working after that.

Incredible tutorial btw!

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Aug 23, 2018

Thanks.

Loading

@thematrixdev
Copy link

thematrixdev commented Aug 25, 2018

Compiled following this guide, or installed libx264-dev instead, still show this error:

$ ldd ~/bin/ffmpeg | grep x264
libx264.so.155 => not found

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Sep 17, 2018

Ah, yes.

You will need to create a library configuration file for ffmpeg under /etc/ld.so.conf.d/ffmpeg.conf , with the content:

/home/$(whoami)/ffmpeg_build/lib

Then run:

sudo ldconfig -vvvv

And re-run ffmpeg again.

Loading

@Sub-7
Copy link

Sub-7 commented May 25, 2019

Check my FFmpegUI > https://github.com/Sub-7/FFmpegUI

Loading

@qlianghit
Copy link

qlianghit commented Jul 8, 2019

There is an error "/usr/bin/ld: final link failed: Nonrepresentable section on output" for x264 compile. Adding "--enable-pic" configuration option fixes the error.
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/bin" --bindir="$HOME/bin" --enable-static --disable-opencl --enable-pic

Loading

@Brainiarc7
Copy link
Author

Brainiarc7 commented Nov 26, 2019

I'll need to update these docs. They're badly out of date.

Loading

@djacemk
Copy link

djacemk commented Dec 17, 2019

did you manage to finish the up to day documentation, since I tested and a lot of errors.
Also support for newest distro of Ubuntu Disco 19.04 should be put. (Starting with Ubuntu 19.04 Intel media stack components are available in respiratory)

Loading

@pjobson
Copy link

pjobson commented Sep 28, 2020

x265 repo is gone, there's a mirror here: git@github.com:videolan/x265.git

Built on Linux Mint 19.3 today. Thanks!

Loading

@coneypo
Copy link

coneypo commented Mar 10, 2021

Typo there:

(a). Build and deploy nasm: Nasm is an assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.

Note that we've now switched away from Yasm to nasm, as this is the current assembler that x265,x264, among others, are adopting.

cd ~/ffmpeg_sources
wget wget http://www.nasm.us/pub/nasm/releasebuilds/2.14rc0/nasm-2.14rc0.tar.gz

Double "wget" for nasm package, thanks!

Loading

@frdbr
Copy link

frdbr commented Apr 14, 2021

Is --enable-nonfree a requirement for vaapi to work? Also do you know why the --extra-cflags and --extra-ldflags are needed?

Loading

@Sub-7
Copy link

Sub-7 commented Apr 14, 2021

--enable-gpl and --enable-nonfree is an easy way to comply with licenses.
--extra-cflags would provide extra command-line switches for the C compiler.

Check out my project -> https://github.com/Sub-7/FFmpegUI

`intel CPU supports VAAPI

[x] 1 Install Dependencies
[ ] 2 Install NVIDIA driver
[ ] 3 Install NVIDIA driver (Proxmox LXC)
[ ] 4 Install CUDA
[ ] 5 Install FFmpeg (supports VAAPI+CUDA)
[x] 6 Install FFmpeg (supports VAAPI)
[x] 7 Install Apache2 and FFmpegUI
[ ] 8 reboot`

Loading

@antonioste
Copy link

antonioste commented Apr 15, 2021

Hello,
i compiled ffmpeg correctly with support for intel, but i have a problem i can't solve, vainfo and ffmepg always load iHD_drv_video.so file instead of the one that works i965_drv_video.so
how can i do to upload the i965 file ONLY?

thank you

Loading

@Sub-7
Copy link

Sub-7 commented Apr 15, 2021

Hello,
i compiled ffmpeg correctly with support for intel, but i have a problem i can't solve, vainfo and ffmepg always load iHD_drv_video.so file instead of the one that works i965_drv_video.so
how can i do to upload the i965 file ONLY?

thank you

Hi antonioste,
if you mean my project, please create a new issue.

Which OS do you use?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment