Skip to content

Instantly share code, notes, and snippets.

@FarisR99
Last active May 12, 2023 17:04
Show Gist options
  • Save FarisR99/84e3e5f2e564b0dc7921e3186dbefd15 to your computer and use it in GitHub Desktop.
Save FarisR99/84e3e5f2e564b0dc7921e3186dbefd15 to your computer and use it in GitHub Desktop.
Intel Arc on Ubuntu 22.04 with ffmpeg & mpv
--disable-gnutls
--disable-stripping
--enable-gpl
--enable-shared
--enable-nonfree
--enable-libass
--enable-libcodec2
--enable-libfontconfig
--enable-libfreetype
--enable-libfribidi
--enable-libmp3lame
--enable-libfdk-aac
--enable-libopenjpeg
--enable-libopus
--enable-libpulse
--enable-libvorbis
--enable-libvpx
--enable-libsnappy
--enable-opencl
--enable-opengl
--enable-libdrm
--enable-chromaprint
--enable-frei0r
--enable-libplacebo
--enable-libx264
--enable-libx265
--enable-libvpl

I recently received an Intel A750 from an Intel run contest. My idea for it was to replace the GTX 1660 in my media server with it, as it has AV1 encode/decode and faster encoding. Before installing my A750 in my media server, I had to make sure it will actually work, and work well with ffmpeg.

This took some time spanning a couple of days to figure out, but I managed to get it almost completely working thanks to coming across this post, and the very helpful user who wrote it (u/Mr_Deathproof): https://www.reddit.com/r/Tdarr/comments/yvsq3n/got_my_intel_arc_a380_dg2_to_work_with_booshs_qsv/iwhsezk/

I've adapted this to include solutions to issues I faced, and following method should work on a fresh install of Ubuntu 22.04.

Disclaimer: I'm not proficient at Linux, and there may be a much simpler method of doing this. This will also be using a "bleeding edge" kernel.

Make sure your user is in the render and video groups:

sudo usermod -aG render $USER
sudo usermod -aG video $USER

Install the typical build tools: sudo apt-get install git build-essential cmake

Optional: Install gcc-12:

sudo apt-get install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 90 --slave /usr/bin/g++ g++ /usr/bin/g++-11

Install some packages for good luck and compatibility with other packages: sudo apt-get install intel-media-va-driver-non-free intel-opencl-icd

Install the latest build of drm-tip from https://kernel.ubuntu.com/~kernel-ppa/mainline/drm-tip/ If the build failed, compile the kernel yourself. Personally I followed this guide: https://phoenixnap.com/kb/build-linux-kernel Alternatively you can use the latest kernel release candidate, e.g. https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.2-rc4/

Download the latest Intel GPU firmware from https://github.com/intel-gpu/intel-gpu-firmware

git clone https://github.com/intel-gpu/intel-gpu-firmware.git
cd intel-gpu-firmware
sudo mkdir -p /lib/firmware/updates/i915/
sudo cp firmware/*.bin /lib/firmware/updates/i915/
sudo update-initramfs -c -k all
sudo update-grub

Reboot: sudo reboot Hopefully you manage to log back in again. If your kernel panics, don't panic. You should be able to enter "Advanced" boot in the Ubuntu boot option list and load a previous kernel, e.g. 5.15 that comes with Ubuntu 22.04. Here you can attempt to debug the issue by reading sudo dmesg, or give up and uninstall the kernel you installed earlier, e.g. sudo apt-get purge linux-*-6.2.0-* or sudo rm -rf /boot/*6.2.0-rc4* && sudo rm -rf /lib/modules/6.2.0-rc4+.

Install libva:

sudo apt-get install autoconf libtool libdrm-dev xorg xorg-dev openbox libx11-dev libwayland-dev libxext-dev libxfixes-dev libx11-xcb-dev libxcb-dri3-dev libgl1-mesa-glx libgl1-mesa-dev
git clone https://github.com/intel/libva.git
cd libva
./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
make -j"$(nproc)"
sudo make install

Install libva-utils:

git clone https://github.com/intel/libva-utils.git
cd libva-utils
./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
make -j"$(nproc)"
sudo make install

Install gmmlib:

git clone https://github.com/intel/gmmlib
cd gmmlib
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DARCH=64 -DRUN_TEST_SUITE=OFF ..
make -j"$(nproc)"
sudo make install

Install the media driver:

mkdir workspace && cd workspace
git clone https://github.com/intel/media-driver
mkdir build_media
cd build_media
cmake ../media-driver -DENABLE_KERNELS=ON -DENABLE_NONFREE_KERNELS=ON -DENABLE_PRODUCTION_KMD=ON
make -j"$(nproc)"
sudo make install

Optional: Add export LIBVA_DRIVER_NAME=iHD to your ~/.bashrc

Install libvpl2 and libvpl-dev: sudo apt-get install libvpl2 libvpl-dev libmfx-gen1.2 Personally I built oneVPL and oneVPL-intel-gpu myself following:

Verify media info tools work:

  • glxinfo -B reports: "OpenGL renderer string: Mesa Intel(R) Arc(tm) AXXX Graphics (DG2)"
  • clinfo reports: "Platform Name Intel(R) OpenCL HD Graphics"
  • vulkaninfo reports details of Vulkan features for your Arc GPU.

Compile ffmpeg and mpv:

  • Follow the instructions in: https://github.com/mpv-player/mpv-build
  • Add --enable-libvpl to your ffmpeg_options, ensuring --enable-libmfx is not there.
    • I've attached my ffmpeg_options in this Gist.
  • If you are not building the additional development libraries (such as libx264) yourself, I recommend adding the following repositories for more up-to-date versions:
    • ppa:savoury1/ffmpeg4
    • ppa:savoury1/ffmpeg5
    • ppa:savoury1/mpv
  • If you get pkg-config or linking errors in the "configure ffmpeg" stage, try modifying scripts/ffmpeg-config and adding --pkg-config-flags="--static" --extra-cflags="-I$BUILD/build_libs/include" --extra-ldflags="-L$BUILD/build_libs/lib" to the configure line

Testing ffmpeg:

  • ffmpeg -hide_banner -encoders | grep qsv lists h264_qsv, hevc_qsv and av1_qsv
  • ffmpeg -y -hwaccel qsv -qsv_device /dev/dri/renderD128 -i somemediafile.mkv -b:v 3M -c:v av1_qsv -c:a copy -c:s copy output.mkv encodes somemediafile.mkv with Arc's AV1 encoder. If you have multiple GPUs (including an iGPU), change renderD128 to whichever points to your Arc device.

Testing mpv:

  • mpv -v --hwdec=vaapi somemediafile.mkv - Check the logs for successful hardware decoding, ensuring there was no fallback to software decoding.
  • mpv --no-config --hwdec=vaapi --ovc=av1_qsv --ovcopts=time_base=1000/24000 -o=output.mkv somemediafile.mkv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment