Minimalistic Docker image with FFmpeg and support for hardware acceleration based on archlinux.
3.2K
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.
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
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 makes it possible for the video card to decode/encode video, thus offloading the CPU and saving power:
Please have a look at archlinux Hardware video acceleration for further details.
intel-media-driver.libva-intel-driver.libva-mesa-driver and mesa-vdpau.nvidia-utils:mesa-vdpau.libva-mesa-driver.libva-vdpau-driver – VDPAU backend for VA-API.libvdpau-va-gl – VA-API backend for VDPAU, only H.264 support.To use the hardware acceleration features you have to configure your Docker host and the container to match the required drivers.
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.
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
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
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.
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.
libva-intel-driver set to i965.intel-media-driver set to iHD.nouveau.vdpau.radeonsi.You need to set VDPAU_DRIVER environment variable to point to correct driver. The correct driver name depends on your setup.
va_gl.nouveau.nvidia.vdpauinfo to determine the driver version of your GPU.Content type
Image
Digest
Size
529.3 MB
Last updated
over 5 years ago
docker pull migoller/ffmpeg