Codecs & Hardware Acceleration

Hardware accelerated encoding was first supported in Owncast 0.0.7.

Requirements

All four of these things need to be true to support hardware accelerated encoding with Owncast.

  1. You are not running on a VPS provided to you by a hosting provider, as shared virtual servers do not allow for direct access to hardware.
  2. You have compatible hardware and have direct access to it.
  3. You installed and configured any drivers and libraries needed to take advantage of your hardware.
  4. You have a copy of ffmpeg that is version 4.1.5 or greater that is specifically built to utilize these drivers and libraries.

Things to keep in mind

  1. Most people won’t be able to take advantage of this unless you’re running your own hardware.
  2. Just because a specific hardware accelerated codec shows in the Owncast admin does not mean your machine is configured to support it. It simply means Owncast believes that codec to be available.
  3. Very little of what is required to get your hardware working has anything to do with Owncast. Any questions you have about your particular hardware should be directed to your hardware manufacturer or whoever provides the drivers and libraries to utilize it. There’s likely a lot of information already online, so please do your research.

Compatible hardware

Intel Graphics

If you have Intel integrated graphics you may be able to use it using VA-API.

Raspberry Pi

Note: The most recent version of the Raspberry Pi OS has a bug with the OpenMax codec. Use the previous version of the OS by downloading it, unzipping it, and using the Raspberry Pi Imager to save it to your SD card for installation.

Using that version of the Raspberry Pi operating system it’s actually quite easy to get Owncast running in a hardware accelerated fashion. Raspberry Pi OS includes support for OpenMax (OMX) out of the box and includes a version of ffmpeg that is built to support it.

However, this seems to only be true for 32 bit operating systems on a Raspberry Pi, as omx seems to be deprecated under 64 bit environments.

NVIDIA GPUs

NVIDIA GPUs ship with an on-chip hardware encoder unit often referred to as NVENC. Separate from the CUDA cores, NVENC run encoding workloads without slowing the execution of graphics or CUDA workloads running at the same time.

As of July 2019 Kepler, Maxwell, Pascal, Volta and Turing generation GPUs support hardware encoding. Visit the NVIDIA GPU Support Matrix to verify your GPU is listed in the “encoder” list.

AMD GPUs

VA-API is supported on AMD and ATI GPUs by the libva-mesa-driver.

Note: ffmpeg 5 is not currently supported with VA-API. Please use a version less than 5. Read the issue about this particular issue to learn more.

Compatible codecs/libraries

VA-API

VA-API (video acceleration API) is a layer to support hardware accelerated encoding on linux. You need the libva library installed for it to work. VA-API is not compatible with ARM chipsets.

Note: ffmpeg 5 is not currently supported with VA-API. Please use a version less than 5. Read the issue about this particular issue to learn more.

Links:

OpenMAX

OpenMAX is a unified abstraction layer that allows access to hardware that otherwise requires vendor specific APIs. It will work out of the box on modern Raspberry Pi’s running a recent version of the Raspberry Pi OS operating system.

Verify your copy of ffmpeg has omx support by looking at the ffmpeg instructions below. If h264_omx is in the list you should be good to go.

Note: OpenMAX support has unfortunately been disconnected with the Raspberry Pi OS. To get hardware accelerated encoding working on a Raspberry Pi it will require running an older 32 bit version of the operating system.

NVIDIA Encoder (nvenc)

Follow the instructions on the NVIDIA ffmpeg transcoding guide to install all the required drivers and libraries. This requires installing a driver from the NVIDIA website, Downloading and install the CUDA toolkit, downloading nv-codec-headers, and building ffmpeg. Scroll to the section entitled Hardware accelerated transcoding with FFmpeg at the NVIDIA transcoding guide for more information.

You may be able to find a pre-built version of ffmpeg that has nvenc support, however that’s outside the scope of this document. You still need NVIDIA drivers regardless.

Links:

ffmpeg

Once your system is configured to use the correct drivers and libraries required you’ll need to make sure your copy of ffmpeg supports it.

Verify you have ffmpeg installed that’s at least version 4.1.5.

$ ffmpeg -version
ffmpeg version 4.1.6-1~deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)

Verify the codec you expect to use is enabled in your version of ffmpeg.

$ ffmpeg -hide_banner -codecs | grep 264
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_mmal ) (encoders: libx264 libx264rgb h264_omx h264_v4l2m2m h264_vaapi )

If the codec you hope to use is not in this list then you may need to build your own copy of ffmpeg that supports it.