Skip to content

How to setup ffmpeg in docker container

I want to compress the video from project directory using ffmpeg in python

the video is saved from cv2.VideoCapture(rtsp_url)

Normally it run without problem in my local machine, but when I dockerize my app it seems docker container can’t recognize ffmpeg or I missed something.

def compress(name):
    with open(name) as f:
        output = name[0:-4] + "-f"+ ".mp4"
        input = name'ffmpeg -i ' + input + ' -vcodec libx264 ' + output)

video = cv2.VideoCapture(rtsp_url) # This is where the video comming from
fileName = saveToProjDir(video) # Save the video to project directory and return the name
compress(fileName) # Compress the video

It throws exception

Exception in thread Thread-8 (compress):
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/", line 1038, in _bootstrap_inner
  File "/usr/local/lib/python3.11/", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/app/", line 59, in compress'ffmpeg -i ' + input + ' -vcodec libx264 ' + output)
  File "/usr/local/lib/python3.11/", line 546, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/lib/python3.11/", line 1022, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.11/", line 1899, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg -i cam1_2022-11-15125845.avi -vcodec libx264 cam1_2022-11-15125845-f.mp4'

This is how I docker my python app.

FROM python:3.11.0


RUN python3 -m venv $VIRTUAL_ENV

COPY requirements.txt .

RUN pip install -r requirements.txt
RUN apt-get -y update
RUN apt-get install ffmpeg libsm6 libxext6  -y

CMD ["python","/app/"]



To debug your problem my suggestion is to use your container interactively.

Try running a new container like this:

docker run -t -i <image-name-or-container-id> /bin/bash

Or attach to your running container:

docker exec -i -t <container-id> /bin/bash

In this way you can play around, try to launch ffmpeg from different paths, install other dependencies and finally see what you are missing.

6 People found this is helpful