0

So I'm trying to create a telegram bot using python and ffmpeg and I want to deploy it to a server through a docker image.

I already looked through a lot of resources as I've been looking at the same 5 lines of code for the past three days and neither discords, stack overflow previous answers have helped me.

This is my dockerfile where half of the program works (apart from the ffmpeg functionality).

FROM python:3.9

RUN mkdir /app
WORKDIR /app

COPY requirements.txt ./
RUN pip3 install --no-cache-dir --user -r requirements.txt

COPY . .

ENTRYPOINT ["/usr/bin/python3", "./app.py" ]

With this code I get the following error when trying to use a function that invokes ffmpeg functionality.

Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/pyrogram/dispatcher.py", line 240, in handler_worker
await handler.callback(self.client, *args)
File "/app/./app.py", line 274, in choice_from_inline
await helpers.trim_file(trim_length, "audio", chat_id_for_join.strip())
File "/app/helpers.py", line 53, in trim_file
output = ffmpeg.output(
File "/root/.local/lib/python3.9/site-packages/ffmpeg/_run.py", line 313, in run
process = run_async(
File "/root/.local/lib/python3.9/site-packages/ffmpeg/_run.py", line 284, in run_async
return subprocess.Popen(
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Another issue is that when changing the ENTRYPOINT (or using CMD) to ["python3", "./app.py" ] everything works well locally but as soon as I try to deploy, the deployment/docker container just doesn't work or crash because I get the error of ModuleNotFoundError: No module named 'ffmpeg'.

I have already tried setting up different ENV PATH and ENV PYTHONPATH, does absolutely nothing. I have tried to use COPY --from=jrottenberg/ffmpeg /usr/local ./ and it also doesn't work. I have tried to explicitly use RUN apt-get install -y ffmpeg and similar commands, pip, pip3, etc.. it just doesn't work.

I tried to use the copy command to access the /root/.local/lib/python3.9/site-packages/ffmpeg/_run.py but I either get a permission denied or a file does not exist error.

I am also using the ffmpeg-python wrapper and am using a windows machine if that's of any importance.

At this point I'm contemplating of finding another way of implementing the functionality I want without using ffmpeg.

I think I added everything I had, if needed more I can provide.

stxss
  • 1
  • 2
  • Have you already tried to deploy only the python container (with your file binded as a volume) and run these commands in shell? It used to make troubleshoot easier – dsenese Dec 08 '22 at 12:17
  • @dsenese I am not sure what you mean by only the python container. I tried to just create the image thorugh ```docker build -t ``` and then running it in the docker and just seeing if it works in the docker desktop terminal and just the windows shell as well but got the same results again and again (I'm sorry if this is completely off but I'm really new to docker as well) – stxss Dec 08 '22 at 12:22
  • I mean run the container with `docker run -it -v yourfolder:app/yourfolder python3:9 bash` and then install your requirements and run your code as you would do locally. This way is better for your troubleshooting and every step you take you can copy to your Dockerfile – dsenese Dec 08 '22 at 12:30
  • @dsenese I just tried that and it works fine and perfectly as I expect it, locally, but then, when deploying it goes array with ffmpeg – stxss Dec 08 '22 at 12:45
  • Maybe installing ffmpeg inside your container: https://stackoverflow.com/questions/29454002/filenotfounderror-errno-2-no-such-file-or-directory-ffmpeg – dsenese Dec 08 '22 at 13:14

1 Answers1

0

Okay, somehow just adding the ethon library helped me solve the problems. I tried swapping the "pythonic" way of commands (stuff like output() and run()) with plain old bash commands and it got solved but then I went back to the pythonic commands and for some reason everything was working. I don't know why or how it changed things but I'm glad and hope this can help someone in the future

stxss
  • 1
  • 2