我想使用python中的ffmpeg压缩项目目录中的视频。
这个视频是从cv2.VideoCapture(rtsp_url)保存下来的
正常情况下,它在我的本地机器上运行,但是当我修改我的应用程序时,它似乎无法识别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'这就是我如何对接我的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"]发布于 2022-11-15 08:59:18
要调试您的问题,我的建议是以交互方式使用容器。
尝试运行这样的新容器:
docker run -t -i <image-name-or-container-id> /bin/bash或附加到正在运行的容器:
docker exec -i -t <container-id> /bin/bash通过这种方式,您可以四处游玩,尝试从不同的路径启动ffmpeg,安装其他依赖项,并最终查看所缺少的内容。
发布于 2022-11-15 08:55:27
如果问题开头提到的python脚本是main.py的内容,那么这个实现几乎没有什么问题:
python:3.11.0作为基本映像的对接器。https://stackoverflow.com/questions/74442807
复制相似问题