Skip to content

Instantly share code, notes, and snippets.

@andrearug
Created November 16, 2017 02:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrearug/ee461152acfbbd3f52b3bb9ffb55b6b8 to your computer and use it in GitHub Desktop.
Save andrearug/ee461152acfbbd3f52b3bb9ffb55b6b8 to your computer and use it in GitHub Desktop.
Build FFmpeg with Intel's QSV-based encoders with Intel's Media SDK on Ubuntu 16.04

**

How to compile FFmpeg with Intel's QSV (h264_qsv) encoder(s) with Intel's Media SDK on Ubuntu:

**

Install required dependencies:

apt-get install gcc gobjc pkg-config libpthread-stubs0-dev
libpciaccess-dev make patch yasm g++ autoconf cmake \
automake build-essential libass-dev libfreetype6-dev libgpac-dev
libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev
libx11-dev \
libxext-dev libxfixes-dev texi2html zlib1g-dev libx264-dev libmp3lame-dev
libfaac-dev librtmp-dev libvo-aacenc-dev libx264-dev cifs-utils

Download and install Media Server Studio Essentials 2015r6 (A newer version may be available at the time of publishing):

wget http://.../mediaserverstudioessentials2015r6.tar.gz
tar xf mediaserverstudioessentials2015r6.tar.gz
cd MediaServerStudioEssentials2015R6
tar xf SDK2015Production16.4.2.1.tar.gz
cd SDK2015Production16.4.2.1/Generic/
tar xf intel-linux-media-ocl_generic_16.4.2.1-39163_64bit.tar.gz
./install_media.sh

Note: This version of the SDK was the last to support Ivy Bridge (Intel 3rd Generation) processors, newer SDKs (such as the 2017 version) deprecated support for this architecture and focus mainly on the 4th (Haswell), 5th (Broadwell) and the 6th (Skylake) architectures and beyond. If you're coming from Ivybridge, please stick with this release.

Take note that processors earlier than Ivy Bridge (Such as Sandy Bridge, Intel's 2nd Generation Processors, Arrandale, the 1st Generation Core and the Clarksfield Mobile Core i7s) are not supported by any SDK version.

Install the libdrm version bundled with the SDK:

cd /opt/intel/mediasdk/opensource/libdrm/2.4.54-39163/
tar xf libdrm-2.4.54.tar.bz2
cd libdrm-2.4.54
./configure
make -j$(nproc)
make -j$(nproc) install

Install the libva package bundled with the SDK:

cd /opt/intel/mediasdk/opensource/libva/1.3.1-staging.20130628.39163
tar xf libva-1.3.1.tar.bz2
cd libva-1.3.1
./configure --enable-static
make -J$(nproc)
make -j$(nproc) install

Deploy libmfx:

cd /opt/intel/mediasdk/opensource/mfx_dispatch/
mkdir build
cd build
cmake –D__ARCH:STRING=intel64 ../
make -j$(nproc)
ln -s /opt/intel/mediasdk/include/ /usr/local/include/mfx

Set up the libraries prior to use:

cd /usr/local/lib
ln -sf /opt/intel/mediasdk/opensource/mfx_dispatch/build/__lib/libmfx.a
ln -sf
/opt/intel/mediasdk/opensource/mfx_dispatch/build/__lib/libdispatch_trace.a
ln -sf
/opt/intel/mediasdk/opensource/mfx_dispatch/build/__lib/libdispatch_shared.a
ln -sf
/opt/intel/mediasdk/opensource/libva/1.3.1-staging.20130628.39163/libva-1.3.1/va/.libs/libva.a
ln -sf
/opt/intel/mediasdk/opensource/libva/1.3.1-staging.20130628.39163/libva-1.3.1/va/.libs/libva-drm.a
ln -sf
/opt/intel/mediasdk/opensource/libva/1.3.1-staging.20130628.39163/libva-1.3.1/va/.libs/libva-tpi.a

Create the pkg-config file under /usr/lib/pkgconfig/libmfx.pc:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libmfx
Description: Intel Media SDK Dispatched static library
Version: 2015
Requires:
Requires.private:
Conflicts:
Libs: -L${libdir} -lmfx -ldispatch_shared -lva -lva-drm -lsupc++ -lstdc++
-ldl
Libs.private:
Cflags: -I${includedir}
-I/opt/intel/mediasdk/opensource/mfx_dispatch/include

Set up the environment variables in /etc/environment:

LD_LIBRARY_PATH="/usr/local/lib:/usr/lib64"
LIBVA_DRIVER_NAME=iHD
LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib64

Apply this linux-kernel patch (for Linux 3.14.5):

wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.5.tar.xz
tar xf linux-3.14.5.tar.xz
cd linux-3.14.5
cp /opt/intel/mediasdk/opensource/patches/kmd/3.14.5/intel-kernel-patches.tar.bz2 .
tar xf intel-kernel-patches.tar.bz2
for i in intel-kernel-patches/*.patch; do patch -p1 < $i; done
make olddefconfig
make -j$(nproc)
make modules_install
make install
reboot

Deploy ffmpeg to /opt/ffmpeg_qsv/

wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xf ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure --disable-shared --enable-static --enable-gpl --enable-nonfree
--enable-fontconfig --enable-libfaac --enable-libfreetype \
--enable-libmp3lame --enable-librtmp --enable-libvo-aacenc --enable-libx264
--enable-version3 --enable-ffplay --disable-doc \
--disable-ffserver --enable-pthreads --enable-filters --enable-libvorbis
--enable-libtheora --enable-runtime-cpudetect --enable-libass \
--enable-bzlib --enable-zlib --prefix=/opt/ffmpeg_qsv/ --enable-libmfx
make -j$(nproc)
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment