RSSAmplifier

Ian's Blog · Oct 30, 2024

Hardware-Accelerated Video Encoding with Intel Arc on Redhat Linux 10

0
Sign in to vote or save

Ian's Blog

I've been wanting hardware-accelerated video encoding on my Linux machine for quite a while now, but ask anybody who's used a Linux machine and they'll tell you of the horrors of Nvidia or AMD drivers.

Intel, on the other hand, seems to be taking things in a much different, much more positive direction when it comes to their Arc graphics cards. I've heard positive things from people who use them about the relatively painless driver experience, at least when compared to Nvidia.

So I went out and grabbed a used Intel Arc A750 locally and installed it in my server running Rocky 10.

This post is to document what I did to install the required drivers and support libraries to be able to encode videos with ffmpeg utilizing the hardware of the GPU.

This post is specific to Red Hat Enterprise Linux (RHEL) and all RHEL-compatible distros (Rocky, Oracle, etc.). If you're using any other distro, this post likely won't help you.

Driver Setup

Intel added drivers for Arc cards into the Linux Kernel, which were included in version 6.2 and later. RHEL 10 was the first version to include a kernel new enough to contain the drivers.

Looking for instructions for RHEL 9? This post has been updated for RHEL 10, view this snapshot for RHEL 9 instructions.

Add Additional Package Repos

While the drivers are present in the kernel, additional libraries are needed to fully use them. Thankfully, these are all available in the official EPEL and RPM Fusion repositories, so let's enable them now:

dnf install epel-release
crb enable
dnf install https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-10.noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-10.noarch.rpm
dnf clean all

Install Support Libraries

Once the additional repos have been added, we can install the required support software and libraries.

dnf install \
  clinfo \
  intel-gpu-firmware \
  intel-media-driver \
  intel-opencl \
  intel-vpl-gpu-rt \
  libva-intel-driver

Reboot your machine for good measure after installing these.

Verify Device Availability

Use lsmod to confirm that the i915 module has been loaded, i915 is the name of the Intel Graphics module. If the module is not loaded, run modprobe i915 and try again.

lsmod | grep i915
i915                 4677632  3
cec                    69632  2 xe,i915
intel_gtt              24576  1 i915
drm_buddy              28672  2 xe,i915
drm_display_helper    286720  2 xe,i915
ttm                   110592  3 drm_ttm_helper,xe,i915
video                  81920  2 xe,i915
i2c_algo_bit           20480  3 ast,xe,i915

Verify the graphics card is recognized as an OpenCL device using clinfo:

clinfo  | grep "Device Name"
  Device Name                                     Intel(R) Arc(TM) A750 Graphics
    Device Name                                   Intel(R) Arc(TM) A750 Graphics
    Device Name                                   Intel(R) Arc(TM) A750 Graphics
    Device Name                                   Intel(R) Arc(TM) A750 Graphics

ffmpeg Setup

Install ffmpeg

ffmpeg needs to be compiled with libvpl support. I recommend using this pre-compiled static build of ffmpeg, as it avoids the dependency hell of shared libraries. Download the ffmpeg-master-latest-linux64-gpl.tar.xz binary.

Verify ffmpeg encoder support

If you're going to use a different copy of ffmpeg, or compile it yourself, you'll want to verify that it has the required Intel Quick Sync Video (QSV) encoder using the following:

./ffmpeg -hide_banner -encoders|grep "qsv"
 V..... av1_qsv              AV1 (Intel Quick Sync Video acceleration) (codec av1)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... hevc_qsv             HEVC (Intel Quick Sync Video acceleration) (codec hevc)
 V..... mjpeg_qsv            MJPEG (Intel Quick Sync Video acceleration) (codec mjpeg)
 V..... mpeg2_qsv            MPEG-2 video (Intel Quick Sync Video acceleration) (codec mpeg2video)
 V..... vp9_qsv              VP9 video (Intel Quick Sync Video acceleration) (codec vp9)

If you don't have any qsv encoders, your copy of ffmpeg isn't built correctly. Again, I recommend using the static builds I linked above, which come with qsv support.

Converting a Video

I'll be using this video from the Wikimedia Commons for reference, if you want to play along at home.

This is a VP9-encoded video in a webm container. Let's re-encode it to H.264 in a MP4 container. I'll skip doing any other transformations to the video for now, just to keep things simple.

./ffmpeg -i Sea_to_Sky_Highlights.webm -c:v h264_qsv Sea_to_Sky_Highlights.mp4

The key parameter here is telling ffmpeg to use the h264_qsv encoder for the video, which is the hardware-accelerated codec using my Intel Arc graphics card.

I'll also encode another copy using libx264, which is a software encoder that will not make use of the card.

Let's see what kind of difference using hardware acceleration makes:

Encoder Time Average FPS
h264_qsv (Hardware) 3.02s 296
libx264 (Software) 1m2.996s 162

Using hardware acceleration sped up this operation by 95%. Naturally your numbers won't be the same as mine, as there's lots of variables at play here, but I feel this is a good demonstration that this was a worthwhile investment.

Read the original on ianspence.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.