在亚马逊ecr linux python上安装ffmpeg

问题描述 投票:0回答:2

我正在尝试在 docker 上安装 ffmpeg 以实现 amazon lambda 函数。 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
python amazon-web-services docker ffmpeg
2个回答
4
投票

由于 yum 包管理器无法使用 ffmpeg 包,因此我手动安装了 ffmpeg 并将其作为容器的一部分。步骤如下:

  1. here下载静态构建(

    public.ecr.aws/lambda/python:3.8 image is ffmpeg-release-amd64-static.tar.xz

    的构建

    这里是有关该主题的更多信息。

  2. 手动将其解压到我的项目的根文件夹(我的 Dockerfile 和 app.py 文件所在的位置)。我使用 CodeCommit 存储库,但这当然不是强制性的。

  3. 在我的 Dockerfile 中添加了以下行:

    COPY ffmpeg-5.1.1-amd64-static /usr/local/bin/ffmpeg
    
  4. requirements.txt
    中,我添加了以下行(以便托管的python包安装ffmpeg-python包):

    ffmpeg-python
    
  5. 这是我在 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 属性 可执行。

  6. 我能够构建容器,并且 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" ]

0
投票

2024 年 5 月解决方案

鉴于没有人愿意发布他们的解决方案,我想我会的:)

.ebextensions/ffmpeg.config

sources:
  /usr/local/bin/ffmpeg: https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz

commands:
  01_link_ffmpeg:
    command: ln -sf /usr/local/bin/ffmpeg/ffmpeg*/ffmpeg /usr/bin/ffmpeg

我最初的尝试是仅使用 wget 和 tar 等 Linux 命令来下载并解压存档。但是,每次运行 tar 命令时,机器都会冻结。以上工作虽然没有任何问题。

© www.soinside.com 2019 - 2024. All rights reserved.