我正在为amazon lambda函数在docker上安装ffmpeg。Dockerfile的代码为:
FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt .
RUN yum install gcc -y
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
RUN yum install -y ffmpeg
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]
我得到一个错误:
> [6/6] RUN yum install -y ffmpeg:
#9 0.538 Loaded plugins: ovl
#9 1.814 No package ffmpeg available.
#9 1.843 Error: Nothing to do
由于ffmpeg包不可用于百胜软件包管理器,我手动安装了ffmpeg并将其作为容器的一部分。以下是步骤:
-
从这里下载了静态构建(
public.ecr.aws/lambda/python:3.8 image is ffmpeg-release-amd64-static.tar.xz
的构建以下是关于这个主题的更多信息。
-
手动将其取消归档到我项目的根文件夹中(Dockerfile和app.py文件所在的位置(。我使用CodeCommit回购,但这当然不是强制性的。
-
添加了以下行我的Dockerfile:
COPY ffmpeg-5.1.1-amd64-static /usr/local/bin/ffmpeg
-
在
requirements.txt
中,我添加了以下行(以便管理的python包安装ffmpeg-python包(:ffmpeg-python
-
以下是我如何在python代码中使用它:
import ffmpeg ... process1 = (ffmpeg .input(sourceFilePath) .output("pipe:", format="s16le", acodec="pcm_s16le", ac=1, ar="16k", loglevel="quiet") .run_async(pipe_stdout=True, cmd=r"/usr/local/bin/ffmpeg/ffmpeg") )
请注意,为了工作,在run方法(在我的情况下是run_async(中需要指定带有ffmpeg位置的cmd属性可执行文件。
-
我能够构建容器,ffmpeg对我来说工作正常。
FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
COPY input_files ./input_files
COPY ffmpeg-5.1.1-amd64-static /usr/local/bin/ffmpeg
RUN chmod 777 -R /usr/local/bin/ffmpeg
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.lambda_handler" ]