Home > Software design >  How to setup ffmpeg in docker container
How to setup ffmpeg in docker container

Time:11-15

I compress the video using ffmpeg in python. Normally it run without problem in my local machine but when i dockerize my app it seems docker container cant recognize ffmpeg or i missed something.

with open(uid) as f:
  output = uid[0:-4]   "-f"  ".mp4"
  try:
    subprocess.run('ffmpeg -i '   name   ' -vcodec libx264 '   output)
  except:
     subprocess.run('docker run ffmpeg -i '   name   ' -vcodec libx264 '   output)

It throws exception


Exception has occurred: FileNotFoundError
\[Errno 2\] No such file or directory: 'docker run ffmpeg -i cam4_2022-11-15082920.avi -vcodec libx264 cam4_2022-11-15082920-f.mp4'
File "\\main.py", line 61, in finishing
subprocess.run('ffmpeg -i '   name   ' -vcodec libx264 '   output)

During handling of the above exception, another exception occurred:

File "\\main.py", line 63, in finishing
subprocess.run('docker run ffmpeg -i '   name   ' -vcodec libx264 '   output)

This is how I docker my python app.


FROM python:3.11.0
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN apt-get -y update
RUN apt-get install ffmpeg libsm6 libxext6  -y

ADD main.py .
CMD \["python","/main.py"\]

CodePudding user response:

If the python script mentioned in the beginning of the question is the content of main.py, then there are few issues with the implementation:

  • You cannot run docker with the python:3.11.0 as base image.
  • You need to mount the volume with the videos and just process them inside the container.

CodePudding user response:

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.

  • Related