我想在 python 中使用 ffmpeg 壓縮專案目錄中的視頻
視頻保存自cv2.VideoCapture(rtsp_url)
通常它在我的本地機器上運行沒有問題,但是當我對我的應用程式進行 docker 化時,docker 容器似乎無法識別 ffmpeg 或者我錯過了一些東西。
def compress(name):
with open(name) as f:
output = name[0:-4] "-f" ".mp4"
input = name
subprocess.run('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
它拋出例外
Exception in thread Thread-8 (compress):
Traceback (most recent call last):
File "/usr/local/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/app/main.py", line 59, in compress
subprocess.run('ffmpeg -i ' input ' -vcodec libx264 ' output)
File "/usr/local/lib/python3.11/subprocess.py", line 546, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 1022, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.11/subprocess.py", 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'
這就是我 docker 我的 python 應用程式的方式。
FROM python:3.11.0
WORKDIR /app/
ENV VIRTUAL_ENV = /env
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
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","/app/main.py"]
uj5u.com熱心網友回復:
如果問題開頭提到的python腳本是 的內容main.py,那么實作上幾乎沒有問題:
- 您不能使用
python:3.11.0as 基礎映像運行 docker。 - 您需要用視頻安裝卷,然后在容器內處理它們。
uj5u.com熱心網友回復:
要除錯您的問題,我的建議是互動式地使用您的容器。
嘗試像這樣運行一個新容器:
docker run -t -i <image-name-or-container-id> /bin/bash
或者附加到您正在運行的容器:
docker exec -i -t <container-id> /bin/bash
通過這種方式,您可以嘗試從不同的路徑啟動 ffmpeg,安裝其他依賴項,最后看看您缺少什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/534115.html
上一篇:為什么docker容器不運行?
