Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PSA: You can now use FFmpeg's VAAPI-based VP8 and VP9 encoder on Skylake+ systems on Linux: Tested on Ubuntu 16.04LTS

Build VAAPI with support for VP8/9 decode and encode hardware acceleration on a Skylake validation testbed:

Build platform: Ubuntu 16.04LTS.

First things first:

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 intel-gpu-tools

This presents only one option, building all components from source and installing the latest build dependencies from source.

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

Option 1: 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 --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
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 --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
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,, namely Haswell and Skylake. Do not build this target on unsupported platforms.

Related, see this commit regarding the hybrid driver initialization failure on platforms where its' not relevant.

git clone https://github.com/01org/intel-hybrid-driver
cd intel-hybrid-driver
./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
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 --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --enable-hybrid-codec
time make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install

However, on Kabylake and newer, omit this as shown since its' not needed:

cd ~/vaapi
git clone https://github.com/intel/intel-vaapi-driver
cd intel-vaapi-driver
./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu 
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 --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
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/lib/x86_64-linux-gnu/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/lib/x86_64-linux-gnu/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

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 Skylake, using a custom prefix because we load FFmpeg via the environment-modules system on the testbed.

Prepare the target directories first:

sudo mkdir -p /apps/ffmpeg/dyn
sudo chown -Rc $USER:$USER /apps/ffmpeg/dyn
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="/apps/ffmpeg/dyn" --bindir="/apps/ffmpeg/dyn/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="/apps/ffmpeg/dyn/bin:$PATH" ./configure --prefix="/apps/ffmpeg/dyn" --bindir="/apps/ffmpeg/dyn/bin" --enable-static --disable-opencl --enable-pic
PATH="/apps/ffmpeg/dyn/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.

cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$/apps/ffmpeg/dyn/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/apps/ffmpeg/dyn" -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="/apps/ffmpeg/dyn" --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="/apps/ffmpeg/dyn" --enable-runtime-cpu-detect --enable-vp9 --enable-vp8 \
   --enable-postproc --enable-vp9-postproc --enable-multi-res-encoding --enable-webm-io --enable-better-hw-compatibility --enable-vp9-highbitdepth --enable-onthefly-bitpacking --enable-realtime-only \
   --cpu=native --as=nasm
   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="/apps/ffmpeg/dyn"
   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="/apps/ffmpeg/dyn/bin:$PATH" PKG_CONFIG_PATH="/apps/ffmpeg/dyn/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure \
  --pkg-config-flags="--static" \
  --prefix="/apps/ffmpeg/dyn" \
  --extra-cflags="-I/apps/ffmpeg/dyn/include" \
  --extra-ldflags="-L/apps/ffmpeg/dyn/lib" \
  --extra-cflags="-I/usr/local/include" \
  --extra-ldflags="-L/usr/local/lib" \
  --bindir="/apps/ffmpeg/dyn/bin" \
  --enable-debug=3 \
  --enable-vaapi \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-gpl \
  --cpu=native \
  --enable-opengl \
  --enable-libfdk-aac \
  --enable-libx264 \
  --enable-libx265 \
  --extra-libs=-lpthread \
  --enable-nonfree 
PATH="/apps/ffmpeg/dyn/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 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.

The environment-modules file for FFmpeg (edit as necessary if your prefixes differ, and to add conflicts if needed):

less /usr/share/modules/modulefiles/ffmpeg/vaapi


#%Module1.0#####################################################################
##
## ffmpeg media transcoder modulefile
## By Dennis Mungai <dmngaie@gmail.com>
## February, 2018
##

# for Tcl script use only
set     appname         ffmpeg
set     version         dyn
set     prefix          /apps/${appname}/${version}
set     exec_prefix     ${prefix}/bin

conflict        ffmpeg/git

prepend-path    PATH            ${exec_prefix}
prepend-path    LD_LIBRARY_PATH ${prefix}/lib

To load and test, run:

module load ffmpeg/vaapi

Confirm all is sane via:

which ffmpeg

Expected output:

/apps/ffmpeg/dyn/bin/ffmpeg

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'

Making a usable FFmpeg build without the module system:

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 --enable-pic
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.

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 '/apps/ffmpeg/dyn/bin/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.

VP9 hardware-accelerated encoding is now available for FFmpeg. However, you'll need an Intel Kabylake-based Integrated GPU to take advantage of this feature.

And now, with the new vp9_vaapi encoder, here's what we get.

Encoder options now available:

ffmpeg -h vp9_vaapi

Output:

Encoder vp9_vaapi [VP9 (VAAPI)]:
    General capabilities: delay 
    Threading capabilities: none
    Supported pixel formats: vaapi_vld
vp9_vaapi AVOptions:
  -loop_filter_level <int>        E..V.... Loop filter level (from 0 to 63) (default 16)
  -loop_filter_sharpness <int>        E..V.... Loop filter sharpness (from 0 to 15) (default 4)

What happens when you try to pull this off on unsupported hardware, say Skylake?

See the sample output below:

[Parsed_format_0 @ 0x42cb500] compat: called with args=[nv12]
[Parsed_format_0 @ 0x42cb500] Setting 'pix_fmts' to value 'nv12'
[Parsed_scale_vaapi_2 @ 0x42cc300] Setting 'w' to value '1920'
[Parsed_scale_vaapi_2 @ 0x42cc300] Setting 'h' to value '1080'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'video_size' to value '3840x2026'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'time_base' to value '1/1000'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x42cce00] Setting 'frame_rate' to value '24000/1001'
[graph 0 input from stream 0:0 @ 0x42cce00] w:3840 h:2026 pixfmt:yuv420p tb:1/1000 fr:24000/1001 sar:1/1 sws_param:flags=2
[format @ 0x42cba40] compat: called with args=[vaapi_vld]
[format @ 0x42cba40] Setting 'pix_fmts' to value 'vaapi_vld'
[auto_scaler_0 @ 0x42cd580] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 0x42cd580] w:iw h:ih flags:'bicubic' interl:0
[Parsed_format_0 @ 0x42cb500] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and the filter 'Parsed_format_0'
[AVFilterGraph @ 0x42ca360] query_formats: 6 queried, 4 merged, 1 already done, 0 delayed
[auto_scaler_0 @ 0x42cd580] w:3840 h:2026 fmt:yuv420p sar:1/1 -> w:3840 h:2026 fmt:nv12 sar:1/1 flags:0x4
[hwupload @ 0x42cbcc0] Surface format is nv12.
[AVHWFramesContext @ 0x42ccbc0] Created surface 0x4000000.
[AVHWFramesContext @ 0x42ccbc0] Direct mapping possible.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000001.
[AVHWFramesContext @ 0x42c3e40] Direct mapping possible.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000002.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000003.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000004.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000005.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000006.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000007.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000008.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x4000009.
[AVHWFramesContext @ 0x42c3e40] Created surface 0x400000a.
[vp9_vaapi @ 0x409da40] 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
[AVIOContext @ 0x40fdac0] Statistics: 0 seeks, 0 writeouts
[aac @ 0x40fcb00] Qavg: -nan
[AVIOContext @ 0x409f820] Statistics: 32768 bytes read, 0 seeks
Conversion failed!

The interesting bits are the entrypoint warnings for VP9 encoding being absent on this particular platform, as confirmed by vainfo's output:

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.4.pre1 (glk-alpha-71-gc3110dc)
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

The VLD (for Variable Length Decode) entry point for VP9 profile 0 is the furthest that Skylake comes to in terms of VP9 hardware-acceleration.

These with Kabylake test beds, run these encode tests and report back :-)

@pollylin914

This comment has been minimized.

Copy link

commented Jun 7, 2017

HI~Brainiarc7

I try to use ffmpeg vp9 vaapi to transcode
but ffmpeg is not support vp9 vaapi encode yet,right?

Thanks your doc is very helpful for me.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 7, 2017

Yes, VP9 encode is NOW supported, but on Kabylake, at the moment.

I'm not sure if Intel witll allow for hybrid VP9 encode support for Skylake.

@cold1746

This comment has been minimized.

Copy link

commented Jun 12, 2017

hi Brainiarc7

i built the dependences first but i did something to my vaapi driver..
.previously it was 0.39.4 and working fine...when i built the dependences it is updated and itz not working

my vaapi info 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: va_openDriver() returns -1 vaInitialize failed with error code -1 (unknown libva error),exit

this is the error im getting while running the commands

[AVHWDeviceContext @ 0x35e5a00] Failed to initialise VAAPI connection: -1 (unknown libva error). [vaapi @ 0x1fea000] Failed to create a VAAPI device

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 12, 2017

Hello there, @cold1746,

Can I get the full output of vainfo?

It seems the gist has clipped off some bits at the end, particularly the /usr/local/lib/dri segment.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 12, 2017

Ah, got it.

Did you run:

sudo ldconfig

After installing all the components?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 12, 2017

Ah, got it.

Did you run:

sudo ldconfig

After installing all the components?

Also, what are your specs?

lspci and dmesg snippets would be appreciated.

@cold1746

This comment has been minimized.

Copy link

commented Jun 14, 2017

yes , i did run sudo ldconfig afetr installing all the component ..

lspci
00:00.0 Host bridge: Intel Corporation Sky Lake Host Bridge/DRAM Registers (rev 07) 00:01.0 PCI bridge: Intel Corporation Sky Lake PCIe Controller (x16) (rev 07) 00:02.0 VGA compatible controller: Intel Corporation Device 1902 (rev 06) 00:14.0 USB controller: Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller (rev 31) 00:14.2 Signal processing controller: Intel Corporation Sunrise Point-H Thermal subsystem (rev 31) 00:16.0 Communication controller: Intel Corporation Sunrise Point-H CSME HECI #1 (rev 31) 00:17.0 SATA controller: Intel Corporation Sunrise Point-H SATA controller [AHCI mode] (rev 31) 00:1b.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Root Port #19 (rev f1) 00:1c.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #3 (rev f1) 00:1c.4 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #5 (rev f1) 00:1d.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #9 (rev f1) 00:1d.4 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #13 (rev f1) 00:1f.0 ISA bridge: Intel Corporation Sunrise Point-H LPC Controller (rev 31) 00:1f.2 Memory controller: Intel Corporation Sunrise Point-H PMC (rev 31) 00:1f.3 Multimedia audio controller: Intel Corporation Sunrise Point-H HD Audio (rev 31) 00:1f.4 SMBus: Intel Corporation Sunrise Point-H SMBus (rev 31) 00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (2) I219-V (rev 31) 01:00.0 Multimedia video controller: Blackmagic Design DeckLink Mini Recorder

i reinstalled the drivers but this time generally like
sudo make
sudo make install ...

after that its working fine and this time i didnt run sudo ldconfig

i just started working with ffmpeg .. i would like to know what this sudo ldconfig -vvvv does and also why u specified like this j$(nproc) VERBOSE=1...kindly help me understand these things

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 14, 2017

To answer your questions, @cold1746,

  1. ldconfig is a program that is used to maintain the shared library cache. This cache is typically stored in the file /etc/ld.so.conf and under configuration file entries under /etc/ld.so.conf.d/ and is used by the system to map a shared library name to the location of the corresponding shared library file entries. These settings are global, but can be overridden by the environment modules package for use on HPCs, resources shared by multiple users.

You have noted an issue with the ldconfig phase that I'll soon comment in and add notes about. It was needed for these running Nvidia Optimus system where a modification to one of the EGL config files is needed to achieve the desired setup under PRIME.

  1. The options passed to make map as follows:

(a). -j$(nproc) tells make to run as many concurrent make jobs as are the online processors detected on the system. Run nproc on your shell and it returns the total number (of all available physical and logical processors detected, if Hyperthreading is on for the latter case). nproc
s output is always a number, so if you have 8 logical CPUS available, the command unwraps as:

make -j8

(b). We pass VERBOSE=1 to run make with maximum verbosity. The output from 'make' will show more details per step. This allows us to catch any build errors that may pop up.

Now, a few notes:

What kernel version are you running?
And what version of Ubuntu are you on?
Your Intel Graphics controller (a Skylake HD 530) is not being properly recognized for some reason.

You can pull out this information by running:

uname -a

uname -r

And for the Ubuntu version:

lsb_release -a

And a bonus: You may also want to look at this snippet on tuning Intel's Skylake and kabylake chips on Linux, as some functions have been moved into firmware only regions (HuC and GuC) and depending on the Linux kernel version you're running, these options may be needed.

@mausspb

This comment has been minimized.

Copy link

commented Jul 4, 2017

Hello !
I have this error while compilling you instructions, can you help me ?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jul 4, 2017

Hey, let me confirm and get back with you.

But first, ensure that you have the build dependencies for libva first:

sudo apt-get build-dep libva

@costasStasi

This comment has been minimized.

Copy link

commented Jul 11, 2017

Hi
How can i use this FFmpeg's VAAPI-based for VP8 and VP9 decoding on Skylake systems on Linux?
It seems that the VAAPI decoding has not be covered for VPx through the FFmpeg.
Thnaks!

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jul 12, 2017

Hello there,

Decoding has been covered extensively on FFmpeg elsewhere in their documentation, and even on one of the gists here.

For starters, use of the -hwaccel vaapi and selecting a device (such as -vaapi_device /dev/dri/renderD129 for the DRI render node renderD129 in that example) automatically enables hardware accelerated decoding for that codec on encoding.

It's even possible to use the VAAPI based decoder with any other encoder, such as when doing H.264 encoding with libx264, using VAAPI to apply a scaling filter:

ffmpeg -loglevel debug -hwaccel vaapi -vaapi-device /dev/dri/renderD* -i "input.file" \
-vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080'
-c:v libx264 -x264-params "nal-hrd=cbr" -b:v 1M -minrate 1M -maxrate 1M -bufsize 2M \
-c:a copy \
-f mkv "output.file"

Note that to have fully hardware accelerated decoding with scaling options, the -vaapi_device option must be passed. It can be omitted if transcoding with VAAPI isn't needed.

To confirm what formats are supported for VAAPI-based encoding and decoding, run vainfo and inspect the output:

For example, on Skylake, with the intel-hybrid-driver installed, you'll see such output:

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.4.pre1 (glk-alpha-71-gc3110dc)
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

To translate the output:

(a). All VAEntryPointVLD markers point to supported codecs for decoding on VAAPI.

(b). All VAEntryPointEncSlice markers point to supported codecs for encoding on VAAPI.

(c). All VAEntryPointEncSlice markers point to supported codecs for low power encoding on VAAPI, and again, on supported hardware.

@Dalmat

This comment has been minimized.

Copy link

commented Jul 31, 2017

Thousand thanks for your help on the intel accelerated VP9 encoding topic (which was suprisingly lacking on ffmpeg despite the major intel announcement regarding kaby lake VP9 support)

I selected a kaby lake specifically for this reason, and just understood that the vp9_vaapi encoder was missing in most linux distributions although the feature was already available on ffmpeg master branch.

I wanted to compare the different codecs I planned to test (x264, x265, vp9, hevc_vaapi, vp9_vaapi).
I encoded a source video with the different encoders, and then computed the PSNR value from ffmpeg (ffmpeg -i P4160098.x265_crf26.mkv -i P4160098.MOV -lavfi psnr="stats_file=psnr.log" -f null - )

The result is quite suprising to me as you can see in the following diagram :

Video Encoder Parameters Encoding Speed Size PSNR Quality
libx264 -crf 26 43 fps 29724kB y:40.812480 u:49.935540 v:49.735007 average:42.309557 min:38.732542 max:48.553462
libx265 crf 26 preset slow 9.45 fps 17580kB y:41.812702 u:49.534277 v:49.485941 average:43.219461 min:39.672495 max:49.150971 min:39.672495 max:49.150971
libvpx-vp9 -g 100 -threads 4 -tile-columns 6 -frame-parallel 0 -speed 1 -b:v 4M -crf 26 6.0 fps 37624kB y:43.615569 u:51.279239 v:51.250914 average:45.018561 min:40.307736 max:53.724640
h264_vaapi -qp 26 111 fps 53213kB y:28.546440 u:46.077189 v:46.405143 average:30.270560 min:29.002821 max:32.132672
hevc_vaapi -qp 26 106 fps 59878kB y:28.473968 u:44.933619 v:44.873095 average:30.185748 min:29.124867 max:32.053832
vp9_vaapi -qp 26 107 fps 44200kB y:28.516704 u:46.725472 v:46.908743 average:30.245612 min:29.104857 max:31.998554

Indeed, the vaapi encoders show a major improvement regarding encoding speed, at the cost of a much lower quality
When watching the video, the quality difference is noticeable.
I did not expect such a huge difference between the software implementation and the vaapi one.
What is also surprising is the small difference between h264_vaapi and vp9/hevc_vaapi.
Hence I'm actually wondering whether I'm running into a configuration problem.

Did you run any quality test on your side regarding the vaapi output ?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 1, 2017

Hello @Dalmat,

Thanks for your analysis on this matter.

On my end, not yet. This is because I don;t have a Skylake testbed (yet), but as soon as I lay hands on it, I'll run these quality tests again with the Netflix VMAF perceptual quality analysis tools.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 1, 2017

Also, can you rerun the tests with -qp set to 21?

I'm doing that now on both Haswell and Skylake.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 18, 2017

Hey @Dalmat,

It also seems that the QSV based encoders do not fare any better than the VAAPI-based ones in FFmpeg, at least on Haswell and Skylake.

@zcwang

This comment has been minimized.

Copy link

commented Aug 30, 2017

May I know any easy way to test vp9 decoding in intel-hybrid-driver? Via gstreamer/gstreamer-vaapi, ffmpeg, or any test-case to run vp9 VLD profile0? Thanks a lot.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 31, 2017

Sure, run:

ffplay -loglevel debug -i "path-to-vp9-based-file"

Then look at the output.

@Dalmat

This comment has been minimized.

Copy link

commented Sep 4, 2017

Hi,

I finally reran the testbench with a standard input video and the netflix VMAF test.
I used the old town cross file from xiph test videos.

The results can be found below :

Setup

  • Intel i5-7600 CPU @ 3.50GHz (quad core, without hyperthreading)
  • Debian stretch, ffmpeg 3.3.2 for non-vaapi encoding
  • Recompiled ffmpeg master branch for vaapi encoding (version N-86703-g95f3c85976)

Results

Video Encoder Parameters Encoding Speed Size PSNR Quality Netflix VMAF score
libx264 -crf 21 15 fps 18395kB average:36.823307 min:36.091262 max:40.788654 94.106313
libx265 -crf 21 preset slow 9.0 fps 10184kB average:37.093507 min:36.434691 max:38.874824 93.633479
libvpx-vp9 -g 100 -threads 4 -tile-columns 6 -frame-parallel 0 -speed 1 -b:v 4M 4.7 fps 8464kB average:36.619408 min:35.856899 max:39.639154 92.603045
h264_vaapi -qp 21 151 fps 83235kB average:38.678466 min:37.838194 max:40.980355 96.432837
hevc_vaapi -qp 21 142 fps 78948kB average:38.185972 min:37.382995 max:39.834882 96.361457
vp9_vaapi / 130 fps 25629kB average:36.761880 min:36.455215 max:37.779381 94.359042

Test Procedure

PSNR

for i in old_town_cross-*.mkv ; do ffmpeg -i "$i" -i old_town_cross_1080p50.y4m -lavfi psnr="stats_file=psnr.log" -f null - ; done

Netflix VMAF

for i in old_town_cross-*.mkv ; do PYTHONPATH=/opt/vmaf/python/src/ /opt/vmaf/ffmpeg2vmaf 1920 1080 old_town_cross_1080p50.y4m "$i"; done

Comments

  • It's interesting (and sad) to notice that vp9_vaapi encoder performs more a bit worse than libx264 regarding quality/size, however at a *9 framerate
  • vp9_vaapi encoder lacks quality parameters.
@zcwang

This comment has been minimized.

Copy link

commented Sep 5, 2017

Thanks for your helpful advice. I can use ffplay to have vp9 clip payback now. :)

BTW I saw only VAProfileVP9Profile0:VAEntrypointVLD in my vainfo but got "vap9_vaapi" encoder but not corresponding vaapi vp9 decoder (only) in my built ffmpeg (without --enable-vpx flag). I only saw "vp9" from list of "-decoders".

List of "-encoders"

V..... vp8_vaapi VP8 (VAAPI) (codec vp8)
V..... vp9_vaapi VP9 (VAAPI) (codec vp9)

Does ffplay use vaapi vp9 hybrid decoding for my test? I'm not so sure due to no any related vp9 avcorder log from ffplay. Any built-in vp9 codec for ffmpeg? I have no idea why it shown vp9 even without libvpx for my built ffmpeg.

Thanks!

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Sep 11, 2017

To answer your questions:

  1. Yes, you can do VP9 decoding via VAAPI without libvpx. Libva and libvpx are two very different projects.
  2. And yes, your platform seems capable of hybrid VP9 decode acceleration, based on the VAProfileVP9Profile0:VAEntrypointVLD decode field from the vainfo utility.
@pv-sap

This comment has been minimized.

Copy link

commented Sep 15, 2017

Hi Guys,

Running Kabylake testbed with VA-API (0.40) libva
Trying to encode 4K /10bit /yuv420p /30fps video
Encoding speed is 0.4 to 0.5 x that is encoding is around 14 frames per second

hevc_vaapi on kabylake is supposed to encode 4k@30fps

Any Clue??

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Sep 17, 2017

Can you provide a sample of the FFmpeg snippet you're using?

@pv-sap

This comment has been minimized.

Copy link

commented Sep 18, 2017

ffmpeg -i jellyfish-120-mbps-4k-uhd-hevc-10bit.mkv -vaapi_device /dev/dri/renderD128 -vf 'format=p010,hwupload,scale_vaapi' -c:v hevc_vaapi -profile:v 2 -g 250 -bf 3 -qp 32 -c:a aac test1.mp4
ffmpeg version N-87233-ge59da0f Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 6.3.0 (Ubuntu 6.3.0-12ubuntu2) 20170406
configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --bindir=/home/pas/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 55. 74.100 / 55. 74.100
libavcodec 57.105.100 / 57.105.100
libavformat 57. 81.100 / 57. 81.100
libavdevice 57. 8.100 / 57. 8.100
libavfilter 6.103.100 / 6.103.100
libswscale 4. 7.103 / 4. 7.103
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 0
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 info: va_openDriver() returns 0
Input #0, matroska,webm, from 'jellyfish-120-mbps-4k-uhd-hevc-10bit.mkv':
Metadata:
COMPATIBLE_BRANDS: iso4hvc1iso6
MAJOR_BRAND : iso4
MINOR_VERSION : 1
ENCODER : Lavf56.3.100
Duration: 00:00:30.10, start: 0.067000, bitrate: 119845 kb/s
Stream #0:0(und): Video: hevc (Main 10), yuv420p10le(tv), 3840x2160 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 29.97 tbc (default)
Metadata:
CREATION_TIME : 2016-02-05 13:00:09
LANGUAGE : und
HANDLER_NAME : hevc@GPAC0.5.2-DEV-rev565-g71748d7-ab-suite
File 'test1.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> hevc (hevc_vaapi))
Press [q] to stop, [?] for help
Output #0, mp4, to 'test1.mp4':
Metadata:
COMPATIBLE_BRANDS: iso4hvc1iso6
MAJOR_BRAND : iso4
MINOR_VERSION : 1
encoder : Lavf57.81.100
Stream #0:0(und): Video: hevc (hevc_vaapi) (Main 10) (hev1 / 0x31766568), vaapi_vld, 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 11988 tbn, 29.97 tbc (default)
Metadata:
CREATION_TIME : 2016-02-05 13:00:09
LANGUAGE : und
HANDLER_NAME : hevc@GPAC0.5.2-DEV-rev565-g71748d7-ab-suite
encoder : Lavc57.105.100 hevc_vaapi
frame= 5 fps=0.0 q=-0.0 size= 0kB time=00:00:00.00 bitrate=4241.0kbits/frame= 10 fps=9.5 q=-0.0 size= 256kB time=00:00:00.16 bitrate=12566.1kbitsframe= 18 fps= 11 q=-0.0 size= 512kB time=00:00:00.43 bitrate=9668.4kbits/frame= 26 fps= 11 q=-0.0 size= 1024kB timframe= 900 fps= 13 q=-0.0 Lsize= 33162kB time=00:00:29.96 bitrate=9066.5kbits/s speed=0.44x
video:33154kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.025320%

@doisyg

This comment has been minimized.

Copy link

commented Sep 25, 2017

Thanks for this post. I have now VP8 HW enabled on my ubuntu 16.04 Skylake
Any tips on enabling vaapi support in chromium/chrome/firefox?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Sep 27, 2017

Hello @doisyg,

That may take a while to materialize.

VAAPI support for Chrome is only existent on Chromebooks, for now.

VAAPI in Chromium is completely disabled on Linux unless you patch the build. Google uses it on Chromebooks, but it is disabled on Linux. It is possible to compile it from source and enable it yourself. See this discussion for more details.

Besides, I've compiled Chromium with the VAAPI patch, and it barely reduced the CPU usage at all for YouTube playback, even with the h264ify extension and checking the stats to make sure it's playing h264. It's still much lower in Windows when playing h264 (Skylake laptop).

@saiarcot895

This comment has been minimized.

Copy link

commented Oct 1, 2017

Hi @Brainiarc7 @doisyg,

I have a PPA for Chromium Beta and Chromium Dev for Ubuntu 16.04 and newer that enables the hardware acceleration. It works on Intel, and should work on Nvidia to some extent.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Oct 2, 2017

Wow, thanks for that :-)

@cold1746

This comment has been minimized.

Copy link

commented Nov 23, 2017

hi @Brainiarc7
my vaapi info 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: va_openDriver() returns -1 vaInitialize failed with error code -1 (unknown libva error),exit`

i previously faced the same problem . i fluked out and solved it i guess

this time i updated the ffmpeg from git

while running vaapi commands

ffmpeg version N-89184-gbea8eea Copyright (c) 2000-2017 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609 configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pas/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-ffplay --enable-decklink --enable-libx264 --enable-libx265 --enable-nonfree --enable-vaapi libavutil 56. 0.100 / 56. 0.100 libavcodec 58. 3.105 / 58. 3.105 libavformat 58. 2.102 / 58. 2.102 libavdevice 58. 0.100 / 58. 0.100 libavfilter 7. 2.100 / 7. 2.100 libswscale 5. 0.101 / 5. 0.101 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 [AVHWDeviceContext @ 0x3f8a7c0] No VA display found for device: /dev/dri/renderD128. Device creation failed: -22. Failed to set value '/dev/dri/renderD128' for option 'vaapi_device': Invalid argument Error parsing global options: Invalid argument
this is the error i'm getting
lspci
00:00.0 Host bridge: Intel Corporation Sky Lake Host Bridge/DRAM Registers (rev 07) 00:01.0 PCI bridge: Intel Corporation Sky Lake PCIe Controller (x16) (rev 07) 00:02.0 VGA compatible controller: Intel Corporation Device 1902 (rev 06) 00:14.0 USB controller: Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller (rev 31) 00:14.2 Signal processing controller: Intel Corporation Sunrise Point-H Thermal subsystem (rev 31) 00:16.0 Communication controller: Intel Corporation Sunrise Point-H CSME HECI #1 (rev 31) 00:17.0 SATA controller: Intel Corporation Sunrise Point-H SATA controller [AHCI mode] (rev 31) 00:1b.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Root Port #19 (rev f1) 00:1c.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #3 (rev f1) 00:1c.4 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #5 (rev f1) 00:1d.0 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #9 (rev f1) 00:1d.4 PCI bridge: Intel Corporation Sunrise Point-H PCI Express Root Port #13 (rev f1) 00:1f.0 ISA bridge: Intel Corporation Sunrise Point-H LPC Controller (rev 31) 00:1f.2 Memory controller: Intel Corporation Sunrise Point-H PMC (rev 31) 00:1f.3 Multimedia audio controller: Intel Corporation Sunrise Point-H HD Audio (rev 31) 00:1f.4 SMBus: Intel Corporation Sunrise Point-H SMBus (rev 31) 00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (2) I219-V (rev 31) 01:00.0 Multimedia video controller: Blackmagic Design DeckLink Mini Recorder

for dmeg
dmesg | grep vaapi

it doesnt display anything

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Nov 23, 2017

Hello @cold1746,

Can you give me the output of:

ls -al /dev/dri

Most likely, you have selected the wrong node and may need to switch to another, such as /dev/dri/renderD129 , for example.

@cold1746

This comment has been minimized.

Copy link

commented Nov 24, 2017

hi @Brainiarc7
output of ls -al /dev/dri
ls: cannot access '/dev/dri': No such file or directory

output of lsmod
Module Size Used by isofs 40960 0 8192eu 1708032 0 kvm_intel 172032 0 kvm 544768 1 kvm_intel irqbypass 16384 1 kvm blackmagic_io 1912832 1 crct10dif_pclmul 16384 0 crc32_pclmul 16384 0 ghash_clmulni_intel 16384 0 aesni_intel 167936 0 aes_x86_64 20480 1 aesni_intel lrw 16384 1 aesni_intel gf128mul 16384 1 lrw glue_helper 16384 1 aesni_intel ablk_helper 16384 1 aesni_intel input_leds 16384 0 cryptd 20480 3 ghash_clmulni_intel,aesni_intel,ablk_helper serio_raw 16384 0 video 40960 0 acpi_pad 24576 0 parport_pc 32768 1 ppdev 20480 0 lp 20480 0 parport 49152 3 lp,ppdev,parport_pc autofs4 40960 2 uas 24576 0 usb_storage 69632 1 uas hid_generic 16384 0 usbhid 49152 0 hid 118784 2 hid_generic,usbhid e1000e 237568 0 ptp 20480 1 e1000e pps_core 20480 1 ptp ahci 36864 2 libahci 32768 1 ahci

output of uname -a

Linux pas 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Nov 30, 2017

You would ideally need DRI libraries installed.

Do you have xorg installed?

@mikhailnov

This comment has been minimized.

Copy link

commented Jan 30, 2018

Can you please explain the purpose of intel-hybrid-driver ?
At the moment I'm using ubuntu 17.10 and kernel 4.13 without any Intel's patches

vainfo
libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 0
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 info: va_openDriver() returns 0
vainfo: VA-API version: 0.40 (libva )
vainfo: Driver version: Intel i965 driver for Intel(R) CherryView - 1.8.3
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

VA-API H264 decoding does work with Chromium from PPA by @saiarcot895 , but no vp9 decoding support
How can intel-hybrid-driver help?

Hardware info here: https://linux-hardware.org/?probe=7777a5062e

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jan 30, 2018

Hello @mikhailnov,

The intel-hybrid-driver is used to provide a hardware-assisted (partial offload) decode for VP8 and VP9 codecs on hardware generations that do not natively offer the same capability purely in hardware.

For instance, Skylake has partial VP9 decode acceleration that can be enabled by installing this package.

For more details, see the clone from 01.org here.

@p00h

This comment has been minimized.

Copy link

commented Feb 26, 2018

Im tryin to encode h264 source to h265 using vaapi.

ffmpeg -threads 1 -i within.temptation.mkv -vaapi_device /dev/dri/renderD128 -acodec copy -c:v hevc_vaapi -qp:v 19 -b:v 2100k -maxrate:v 3500k -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' output.mkv

I've been trying tons of options: bitrate, quality, profiles and so on. Unfortunately, there was no luck and anytime I've tried I had the message:
[h265_vaapi @ 0x557d68f496a0] Encoding profile not found (17).

Do you have any clues? What is the reason of the message? Is it the lack of some options?
Please give me the direction at least. I'll keep searching.
Any help would be greatly appreciated.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 16, 2018

Hello @p00h, and sorry for the late reply. Wish github had notifiers for comments on gists.

Provide a copy of your vainfo output.

@Laaas

This comment has been minimized.

Copy link

commented Apr 6, 2018

I'm not him, but I get the same thing no matter what I try:
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_1
ATTENTION: default value of option mesa_glthread overridden by environment.
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.1 (libva 2.1.0)
vainfo: Driver version: mesa gallium vaapi
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 6, 2018

From your output, your system provides no encode entry points for any codecs.

The encode entry points are prepended with the *Slice keyword, as shown in the example below:

vainfo
libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 0
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 info: va_openDriver() returns 0
vainfo: VA-API version: 0.40 (libva )
vainfo: Driver version: Intel i965 driver for Intel(R) CherryView - 1.8.3
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

Without these, you're not getting any hardware accelerated encoding, sorry.

With that in mind, provide the details of:

  1. Your GPU: (via lspci and dmesg | grep drm)

  2. Your kernel. (uname -r and uname -m will do)

  3. Your distribution. The output of lsb_release -a is sufficient.

@rayburgemeestre

This comment has been minimized.

Copy link

commented May 25, 2018

Someone might find it helpful, while compiling on 17.10 (artful) during intel-vaapi-driver I got errors like:

i965_avc_hw_scoreboard.c:43:10: fatal error: shaders/h264/mc/export.inc.gen5: No such file or directory
 #include "shaders/h264/mc/export.inc.gen5"

This was resolved after installing sudo apt install intel-gpu-tools which makes intel-gen4asm available. The autogen step didn't warn about a missing intel-gen4asm so that can be confusing

Second thing to get it working, I noticed mpv and chromium (patched for vaapi) were making calls that failed: [vaapi] libva: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so has no function __vaDriverInit_0_32

Master is already at version 2, so I checkout out the following tags for the following repos (before compiling + installing again):

  • libva at liva-1.8.3
  • intel-vaapi-driver at 1.8.3.pre1
  • libva-utils at 1.8.3.pre1
@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented May 28, 2018

Hey @rayburgemeestre,

Thanks for the observation :-)

The notes on intel-gpu-tools is very helpful. Thanks.

I'll add the notes on the tags soon.

@montvid

This comment has been minimized.

Copy link

commented Jun 2, 2018

Hi there, just wanted to ask as libva-intel-driver encodes and decodes vp8 vp9 what is the use of libva-intel-hybrid-driver?Do I need to install both to have hardware decode? Can I have hw decode of vp8 9 with libva-intel-hybrid-driver only? Thanks.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 6, 2018

Hello @montvid,

The hybrid driver is for specific platforms (HSW and SKL) where partial hwaccel exists for specific codec entry points (HEVC is only partially accelerated on Haswell whereas VP9 is only partially accelerated on Skylake for decode ONLY), and is NOT needed on kabylake and newer.

@eclipseo

This comment has been minimized.

Copy link

commented Jun 28, 2018

@Brainiarc7 is it supposed to work on Haswell too? https://github.com/01org/intel-hybrid-driver/blob/master/README mentions Broadwell but the hybrid driver fails to load.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 28, 2018

Hey @eclipseo,

Show me the output of vainfo on your platform.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 29, 2018

Related, see this commit regarding the hybrid driver initialization failure on platforms where its' not relevant.

@Nottt

This comment has been minimized.

Copy link

commented Aug 19, 2018

do you think this can work with Ivybridge cpus?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 29, 2018

@Nottt, yes.

Ivybridge is supported.

@hamwong

This comment has been minimized.

Copy link

commented Dec 6, 2018

@Brainiarc7

Hi, you said intel hevc encoder have good outcome with well tune, I tried few days on it and still can’t get nice quality (compare to x265) on lower bitrate 1000K, do u mind share your hevc Parma?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2018

@hamwong,

Let me get back to you on that.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2018

@Dalmat,

An year later:

(a). FFmpeg's h264_vaapi:

ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device intel -i old_town_cross_1080p50.y4m -filter_hw_device intel -vf 'format=nv12|vaapi,hwupload' -c:v h264_vaapi -qp 21 old_town_cross_1080p50_h264_vaapi.mkv

Readings:
i. PSNR: PSNR y:37.903869 u:39.785445 v:41.603166 average:38.630980 min:37.573365 max:41.537383
ii. VMAF: VMAF score: 96.270236

(b). FFmpeg's hevc_vaapi:

ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device intel -i old_town_cross_1080p50.y4m -filter_hw_device intel -vf 'format=nv12|vaapi,hwupload' -c:v hevc_vaapi -qp 21 old_town_cross_1080p50_hevc_vaapi.mkv

Readings:
i. PSNR: PSNR y:37.488106 u:39.573284 v:41.712610 average:38.282739 min:37.230676 max:41.611796
ii. VMAF: 96.395142

(c). FFmpeg's vp8_vaapi:

ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device intel -i old_town_cross_1080p50.y4m -filter_hw_device intel -vf 'format=nv12|vaapi,hwupload' -c:v vp8_vaapi old_town_cross_1080p50_vp8_vaapi.mkv

Readings:
i. PSNR: PSNR y:35.494408 u:38.265035 v:39.605085 average:36.359397 min:35.820870 max:37.004402
ii. VMAF: VMAF score: 93.076852

(d). FFmpeg's vp9_vaapi:

ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device intel -i old_town_cross_1080p50.y4m -filter_hw_device intel -vf 'format=nv12|vaapi,hwupload' -c:v vp9_vaapi old_town_cross_1080p50_vp9_vaapi.mkv

Readings:
i. PSNR: PSNR y:35.874297 u:38.632504 v:40.298447 average:36.761880 min:36.455215 max:37.779381

ii. VMAF: VMAF score: 94.359042

Measurement:

  1. PSNR:

for i in *.mkv ; do ffmpeg -i "$i" -i old_town_cross_1080p50.y4m -lavfi psnr="stats_file=psnr.log" -f null - ; done

  1. Netflix VMAF:

for i in *.mkv ; do ffmpeg -i "$i" -i old_town_cross_1080p50.y4m -lavfi libvmaf="psnr=1:log_fmt=json" -f null - ; done

Platform information:

  1. vainfo:
vainfo: VA-API version: 1.4 (libva 2.4.0.pre1)
vainfo: Driver version: Intel i965 driver for Intel(R) Coffee Lake - 2.4.0.pre1 (2.2.0-15-gecfb0db)
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
@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2018

@hamwong,

For the HEVC encoder, here are the available options, using the latest git heads from both libva and ffmpeg:

ffmpeg -h encoder=hevc_vaapi

Encoder hevc_vaapi [H.265/HEVC (VAAPI)]:
    General capabilities: delay hardware 
    Threading capabilities: none
    Supported pixel formats: vaapi_vld
h265_vaapi AVOptions:
  -low_power         <boolean>    E..V..... Use low-power encoding mode (only available on some platforms; may not support all encoding features) (default false)
  -qp                <int>        E..V..... Constant QP (for P-frames; scaled by qfactor/qoffset for I/B) (from 0 to 52) (default 25)
  -aud               <boolean>    E..V..... Include AUD (default false)
  -profile           <int>        E..V..... Set profile (general_profile_idc) (from -99 to 255) (default -99)
     main                         E..V.....
     main10                       E..V.....
     rext                         E..V.....
  -tier              <int>        E..V..... Set tier (general_tier_flag) (from 0 to 1) (default main)
     main                         E..V.....
     high                         E..V.....
  -level             <int>        E..V..... Set level (general_level_idc) (from -99 to 255) (default -99)
     1                            E..V.....
     2                            E..V.....
     2.1                          E..V.....
     3                            E..V.....
     3.1                          E..V.....
     4                            E..V.....
     4.1                          E..V.....
     5                            E..V.....
     5.1                          E..V.....
     5.2                          E..V.....
     6                            E..V.....
     6.1                          E..V.....
     6.2                          E..V.....
  -sei               <flags>      E..V..... Set SEI to include (default hdr)
     hdr                          E..V..... Include HDR metadata for mastering display colour volume and content light level information

With that in mind, here's what you can tune:

(a). Change the -profile to main.

(b). Set the -tier from main to high.

(c). The same applies to the -level option. Change that to 6.2.

Now, for the bitrates: You're targeting 1000KB/s. If that's the case, set it as shown:

`-b:v 1M -maxrate:v 1.0M -bufsize:v=4(b:v/fps)

For audio synchronization, use the following audio filter: -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0".
This should ensure that your audio stream is in sync with the video stream, especially when segmenting.

@pathmissing

This comment has been minimized.

Copy link

commented Dec 28, 2018

@Brainiarc7 Works fine on Debian Stretch 9.6. Had some minor issues but nothing that could not be resolved by using my brain + Google.
Thank you for this nice piece of information, it helped me a lot!

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 31, 2018

You're most welcome. @pathmissing!
Thanks for the feedback.

@Mandrewoid

This comment has been minimized.

Copy link

commented Apr 14, 2019

@Brainiarc7 I realize this is kindof an old topic. Hopefully you're still around.
I was having some trouble getting vaapi gpu-acceleration to work on linux.

Currently I have achieved h264 acceleration functional, getting about 900fps vs 300fps on Cpu-only.
with a command like:
ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -i input.mp4 -an -c:v h264_vaapi -qp:v 19 -b:v 2100k -maxrate:v 3500k output.mp4

Unfortunately I don't seem to be able to get h265 to work, despite vainfo showing
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointVLD

other commands that you have run like:
ffmpeg -h encoder=hevc_vaapi
returns:
Codec 'hevc_vaapi' is not recognized by FFmpeg.
but I also get
Codec 'h264_vaapi' is not recognized by FFmpeg.
if I try to do 'ffmpeg -h encoder=h264_vaapi', yet as I said h264 encoding does in fact work fine.

The error I get when I try to run ffmepg with -c:v hevc_vaapi instead of -c:v h264_vaapi is:
[hevc_vaapi @ 0x2586f00] No usable encoding entrypoint found for profile (no profile names) (17).
so it does look like it is recognizing and calling the encoder, but not asking for a valid profile?
Any ideas? Thanks for your help

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 21, 2019

@Mandrewoid,

The encoding formats supported by VAAPI on your end can be printed out via:

vainfo | grep Slice

What you've pointed above only indicates support for Variable Length Decoding (VLD) entrypoints.

Can you provide the output of:

vainfo
ffmpeg -buildconf
lspci
@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 21, 2019

@hamwong

I'll update this with an explanation for the rate control modes you can expect.

@TRPB

This comment has been minimized.

Copy link

commented Jun 20, 2019

I've been playing around encoding with vp9_vaapi and thought I'd share my experiences here as this thread was useful.

Using vp9_vaapi the flags -crf and -qp are ignored. The one option that works is -global_quality which seems to go from 1-150ish. Lower numbers give higher quality/filesize. Has anyone else played around with controlling the quality using vp9_vaapi? Is there documentation for global_quality anywhere?

I was hoping to save space compared to h264 source files without losing quality. Here's my ffmpeg command:

fmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$infile" -c:v vp9_vaapi -global_quality $quality  -bf 4 -bsf:v vp9_raw_reorder,vp9_superframe  -c:a libvorbis "$outfile"

This does everything in hardware so you don't need to use hwupload and uses pseudo b-frames as recommended by the manual to increase compression.

Unfortunately global_quality is rather frustrating as it needs tweaking based on the source material. For low quality sources with already high compression (e.g. SD h264 video with a bitrate < 800K) any global_quality setting less than 120 will result in a larger file than the source file. It's not clear how global_quality relates to bitrate but lower values will give higher bitrates.

For HD h264 video with a high bitrate (>3M) global quality settings affect the quality/compression. For visual quality, I used ffmpeg to screenshot the video at the same timestamp and compared the frames by zooming in to 400%

  • global_quality 40 gives a visually indistinguishable video with a 5% filesize reduction.

  • global_quality 50 seems give very slightly worse visual quality with about a 25% filesize reduction.

  • Omitting global_quality and using whatever the default is, lowers quality a bit more (From playing around the default seems to be in the 90-100 range)

Obviously different source videos will have different results but that's what I've found so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.