Sign inSign up

migoller/ffmpeg

By migoller

•Updated over 5 years ago

Minimalistic Docker image with FFmpeg and support for hardware acceleration based on archlinux.

Image
1

3.2K

migoller/ffmpeg repository overview

⁠FFmpeg Docker image

Minimalistic Docker image with FFmpeg⁠ and support for hardware acceleration⁠ based on archlinux⁠. You can install the latest build of this image by running docker pull migoller/ffmpeg.

This image can be used as a base for an encoding farm or for Shinobi CCTV⁠ hardware accelerated Docker images. The image is scheduled for weekly builds on every Sunday.

Please use GitLab issues⁠ to report any bug or missing feature.

Feel free to contribute on my GitLab FFmpeg Docker image repository⁠.

⁠Examples

⁠Encode rtsp stream into a MP4

Let's encode a rtsp stream into an MP4 out_nohwaccel.mp4 is located in the current directory.

$ docker run -it -rm -v $PWD:/tmp \
        migoller/ffmpeg \
        -loglevel info -stats \
        -i rtsp://<rtsp url> \
        -vf 'scale=640:480' \
        -preset ultrafast \
        -c:v libx264 \
        -t 20 -r 8 -f mp4 /tmp/out_nohwaccel.mp4
⁠Encode rtsp stream into a MP4 with hardware acceleration

Now let's encode a rtsp stream into an MP4 out_hwaccel.mp4 is located in the current directory with VA-API hardware acceleration of an Intel i965 compatible CPU with Intel HD GPU.

$ docker run -it -rm --device /dev/dri:/dev/dri -v $PWD:/tmp -e LIBVA_DRIVER_NAME="i965" \
        migoller/ffmpeg \
        -loglevel info -stats \
        -i rtsp://<rtsp url> \
        -vaapi_device /dev/dri/renderD128 \
        -vf 'hwupload,scale_vaapi=w=640:h=480:format=nv12' \
        -preset ultrafast \
        -c:v h264_vaapi \
        -t 20 -r 8 -f mp4 /tmp/out_hwaccel.mp4

⁠Hardware video acceleration

Hardware video acceleration makes it possible for the video card to decode/encode video, thus offloading the CPU and saving power:

  • Video Acceleration API (VA-API) provides both hardware accelerated video encoding and decoding, designed for Intel CPU / GPU.
  • Video Decode and Presentation API for Unix (VDPAU) allows to offload portions of the video decoding process and video post-processing to the GPU video-hardware, developed by NVIDIA. VDPAU has not been updated since September 2015.
  • NVDECODE/NVENCODE - hardware video acceleration used by NVIDIA Fermi, Kepler, Maxwell and Pascal generation GPUs.

Please have a look at archlinux Hardware video acceleration⁠ for further details.

⁠Intel
⁠Intel graphics open-source drivers support VA-API:
  • HD Graphics series starting from CannonLake (or optionally from Broadwell) and newer are supported by intel-media-driver.
  • GMA 4500 series and newer GPUs up to Coffee Lake are supported by libva-intel-driver.
⁠NVIDIA
⁠Nouveau open-source driver supports both VA-API and VDPAU:
  • GeForce 8 series and newer GPUs up until GeForce GTX 750 are supported by libva-mesa-driver and mesa-vdpau.
⁠NVIDIA proprietary driver supports via nvidia-utils:
  • VDPAU on GeForce 8 series and newer GPUs
  • NVDECODE on Fermi and newer GPUs
  • NVENCODE on Kepler and newer GPUs
⁠ATI/AMD
⁠ATI and AMDGPU open-source drivers support both VA-API and VDPAU:
  • VDPAU on Radeon R300 and newer GPUs is supported by mesa-vdpau.
  • VA-API on Radeon HD 2000 and newer GPUs is supported by libva-mesa-driver.
⁠Translation layers
⁠To get VA-API support when device driver provides none:
  • libva-vdpau-driver – VDPAU backend for VA-API.
⁠To get VDPAU support when device driver provides none:
  • libvdpau-va-gl – VA-API backend for VDPAU, only H.264 support.

⁠Configuration

To use the hardware acceleration features you have to configure your Docker host and the container to match the required drivers.

⁠Docker host configuration

Have your GPUs´ drivers up and running on your host.

Ensure that your graphics card has been recognized correctly running vainfo, vdpauinfo or nvidia-utils.

⁠Verifying VA-API drivers

Run vainfo to check that your GPU is recognized correctly.

$ vainfo
error: XDG_RUNTIME_DIR not set in the environment.
error: can't connect to X server!
libva info: VA-API version 0.39.4
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_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.3)
vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 1.7.0
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
      VAProfileHEVCMain               : VAEntrypointEncSlice
⁠Verifying VDPAU

Run vdpauinfo to check that your GPU is recognized correctly.

$ vdpauinfo
display: :0   screen: 0
API version: 1
Information string: G3DVL VDPAU Driver Shared Library version 1.0

Video surface:

name   width height types

420    16384 16384  NV12 YV12 
422    16384 16384  UYVY YUYV 
444    16384 16384  Y8U8V8A8 V8U8Y8A8 

Decoder capabilities:

name                        level macbs width height

MPEG1                          --- not supported ---
MPEG2_SIMPLE                    3  9216  2048  1152
MPEG2_MAIN                      3  9216  2048  1152
H264_BASELINE                  41  9216  2048  1152
H264_MAIN                      41  9216  2048  1152
H264_HIGH                      41  9216  2048  1152
VC1_SIMPLE                      1  9216  2048  1152
VC1_MAIN                        2  9216  2048  1152
VC1_ADVANCED                    4  9216  2048  1152
⁠FFmpeg container configuration

Run the container with the device attached /dev/dri from your Docker host into the container and set the environment accordingly to the GPU driver.

$ docker run --device /dev/dri:/dev/dri -e LIBVA_DRIVER_NAME="i965" [...] migoller/ffmpeg [...]`

Run the FFmpeg container with the correct parameters like running ffmpeg natively⁠.

⁠Configuring VA-API

You can override the driver for VA-API by using the LIBVA_DRIVER_NAME environment variable; the default value is set to i965. The correct driver name depends on your setup.

⁠Intel graphics:
  • For libva-intel-driver set to i965.
  • For intel-media-driver set to iHD.
⁠NVIDIA:
  • For Nouveau set to nouveau.
  • For NVIDIA set toe vdpau.
⁠ATI/AMD:
  • For AMDGPU driver set to radeonsi.
⁠Configuring VDPAU

You need to set VDPAU_DRIVER environment variable to point to correct driver. The correct driver name depends on your setup.

⁠Intel graphics:
  • For Intel Graphics or AMD Catalyst you need to set it to va_gl.
⁠NVIDIA:
  • For Nouveau driver set it to nouveau.
  • For NVIDIA's proprietary version set it to nvidia.
⁠ATI/AMD:
  • For AMDGPU driver set it to the proper driver version depending on your GPU. Run vdpauinfo to determine the driver version of your GPU.

Tag summary

Content type

Image

Digest

Size

529.3 MB

Last updated

over 5 years ago

docker pull migoller/ffmpeg