简体   繁体   English

在 AWS Lambda function 中使用 python 运行 ffmpeg 命令时出现问题

[英]Issue with running ffmpeg command using python in AWS Lambda function

My use case is to concatenate the files using ffmpeg.我的用例是使用 ffmpeg 连接文件。 I do it by specifying the S3 URLs (in a text file /tmp/files.txt) of the files to be concatenated.我通过指定要连接的文件的 S3 URL(在文本文件 /tmp/files.txt 中)来做到这一点。

Below is the command and and the way I run it using Python:下面是命令以及我使用 Python 运行它的方式:

ffmpeg_cmd = "ffmpeg -f concat -safe 0 -protocol_whitelist file,http,https,tcp,tls -i /tmp/files.txt -c copy /tmp/output.mp4"
subprocess.run(ffmpeg_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

The same Python file works perfectly fine when I run it on my Windows machine.当我在我的 Windows 机器上运行相同的 Python 文件时,它工作得非常好。 But when it is run on AWS Lambda function, it fails.但是当它在 AWS Lambda function 上运行时,它会失败。 Please find below the error I get:请在下面找到我得到的错误:

"errorMessage": "[Errno 2] No such file or directory: 'ffmpeg -f concat -safe 0 -protocol_whitelist file,http,https,tcp,tls -i /tmp/files.txt -c copy /tmp/output.mp4'", "errorType": "FileNotFoundError" "errorMessage": "[Errno 2] No such file or directory: 'ffmpeg -f concat -safe 0 -protocol_whitelist file,http,https,tcp,tls -i /tmp/files.txt -c copy /tmp/output. mp4'", "errorType": "FileNotFoundError"

Am I doing it the right way?我做对了吗? I suppose yes, as it works just fine on my Windows PC.我想是的,因为它在我的 Windows PC 上运行良好。

If someone faced this issue and fixed it, please help me with this issue.如果有人遇到此问题并已解决,请帮助我解决此问题。

FFMPEG is not pre-installed in the Lambda runtime environment. FFMPEG 未预安装在 Lambda 运行时环境中。 It has to be explicitly deployed as a Lambda Layer or bundled and uploaded with your Lambda function.它必须明确部署为 Lambda 层或与 Lambda function 捆绑并上传。 If you did deploy it then the ffmpeg binary may not be executable or may not be on your PATH.如果您确实部署了它,那么ffmpeg二进制文件可能无法执行或可能不在您的 PATH 中。

Here are a few options for deploying FFMPEG:以下是部署 FFMPEG 的几个选项:

  1. ffmpeg-aws-lambda-layer ffmpeg-aws-lambda 层
  2. ffmpeg-lambda-layer ffmpeg-lambda 层
  3. install FFMPEG on Lambda 在 Lambda 上安装 FFMPEG

I tested a simple Lambda Python function without FFMPEG binaries and saw exactly the error message you are seeing.我测试了一个简单的 Lambda Python function没有Z6846C1A17DDAF84E01F26EC51C151 的情况下,你看到了8个错误消息。 This is evidence that the ffmpeg binary is not installed in your Lambda environment or not on your PATH.这证明ffmpeg二进制文件未安装在您的 Lambda 环境中或您的 PATH 中。 The actual location of an uploaded ffmpeg binary depends on where you upload it to but it would typically be under /var/task/ if you uploaded the binary as part of your Lambda Layer or under /opt/ if deployed as part of your Lambda package. The actual location of an uploaded ffmpeg binary depends on where you upload it to but it would typically be under /var/task/ if you uploaded the binary as part of your Lambda Layer or under /opt/ if deployed as part of your Lambda package . Rather than simply trying to execute ffmpeg , you might want to list files in those locations to verify what you have deployed.与其简单地尝试执行ffmpeg ,不如列出这些位置中的文件以验证您已部署的内容。

Try This:-尝试这个:-

ffmpeg_cmd = "/opt/ffmpeglib/ffmpeg -f concat -safe 0 -protocol_whitelist file,http,https,tcp,tls -i /tmp/audio_list.txt -c copy /tmp/output.mp4"

command1 = shlex.split(ffmpeg_cmd)

p1 = subprocess.run(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM