Using FFmpeg with Docker

Docker containers: the easiest way to distribute softwares

Bruno Celeste
Feb 29, 2016 · 4 min read

What is interesting with Docker containers is that you can use them not only for deploying services to the cloud, but also to distribute softwares that you just need to run locally. It is especially useful when the software has a lot of dependencies and requires to be compiled like FFmpeg. With Docker containers, everything is inside and with just one command line, it just works!

FFmpeg dockerized

FFmpeg is a free software project and is the leading software for everything related to multimedia like video encoding, streaming and muxing.

The problem with FFmpeg is that it is not easy to install. You have to compile it which implies that you need to install a ton of dependencies and have a development environment setup! I’ve been doing this for a decade and it’s not that simple.

A typical FFmpeg image on Docker Hub is +350MB and I wanted it to be as small as possible. So I choose Alpine Linux which is a lightweight Linux distribution, and I ended up with an image of 106MB only. 70% smaller, not bad!

Here is the FFmpeg build configuration used in this image:

How to use FFmpeg with Docker

If you don’t have Docker installed yet, follow this guide.

Once Docker is properly setup, it is pretty straightforward to use the FFmpeg image. Instead of using the ffmpeg command line, you call docker to run the opencoconut/ffmpeg image in a container. That’s it!

You should be aware of 2 caveats by using FFmpeg from a container:

  1. The input file must be publicly available on a web server since the container doesn’t have access to the local file system.
  2. The FFmpeg command must pipe the result to STDOUT, again for the same reason of not accessing the local file system.

The #2 is a big issue, because there are some technical limitations depending on the format you want to use. For instance, MP4, which is the most popular video format out there, can’t be used with a pipe as output. You will get this message if you try:

[mp4 @ 0x556c59f21260] muxer does not support non seekable output

To work around this problem, we can use the current path on the Docker host’s filesystem (your computer) as a volume inside the container with the “-v” option. So now we can access files on our local disk for input / output and use FFmpeg without these limitations.

This command is too long, so let’s create an alias by adding this line at the end of your ~/.bashrc or ~/.zshrc file:

Now FFmpeg can be used like it’s installed on your computer:

Docker image versioning

The FFmpeg team releases a new version every 3 months on average and I wanted this Docker image to follow their version numbering scheme for sake of simplicity.

At this time, we only have two versions: 3.0 and git. The version 3.0 is the latest stable version and was released on February 15th, 2016. When using git, you will use the development version which is working fine 99% of the time.

By using docker run opencoconut/ffmpeg, you will use the latest stable version by default. To use a specific FFmpeg version, just run it like this:

You can find all versions on the Docker Hub tag page.

If you have any feedbacks, you can send me a message on Twitter or by email. The project is on Github, so feel free to contribute!

Coconut Stories

Once upon a time, near a coconut tree…

Coconut Stories

Once upon a time, near a coconut tree…

Bruno Celeste

Written by

I play video games. I write code. I love traveling. Coffee enthusiast • Entrepreneur

Coconut Stories

Once upon a time, near a coconut tree…