How to Install ffmpeg on aws lambda machine?

天涯浪子 提交于 2020-01-24 14:38:27

问题


I'm trying to run a node js script on aws lambda that uses ffmpeg. To do this, I need to install ffmpeg on the machine itself.

I have looked trhough the documentation but I could not find how to connect to the machine that runs the lambda.


回答1:


You don't ever connect to the "machine" the Lambda is running on. There is no single machine the function runs on, and the function isn't even deployed until the first time it is called. The Lambda runs in one or more containers that are created and deleted on demand as requests come in. You have to include anything like ffmpeg in your Lambda's deployment package itself, so it will be there every time your function is deployed to a container.

Any binaries you include in your function's deployment package need to be built for Amazon Linux, which is the operating system Lambda runs on. You can either use an EC2 server to build the binaries or search for someone that has already packaged ffmpeg for Lambda and made it available.




回答2:


You can also find pre-compiled versions of ffmpeg for aws-lambda hosted by this cool dude, here: https://johnvansickle.com/ffmpeg/

(I went with the x86_64 build)

Tip: don't forget to set the correct +x permissions for the binaries ffmpeg and perhaps ffprobe if needed.




回答3:


This works for me in Python:

  1. Get static build of ffmpeg from here, as already mentioned by @Xeroxoid
  2. Untar with tar -zxvf ffmpeg-release-amd64-static.tar.xz
  3. Fetch file ffmpeg (and optionally ffprobe) from folder.
  4. Put bare ffmpeg file (without the subfolder) in the same folder as your lambda code.
  5. cd into this folder and zip with zip -r -X "../archive.zip" *
  6. Upload zipped file to AWS Lambda.

Set the correct filepath to ffmpeg like so:

FFMPEG_STATIC = "/var/task/ffmpeg"
import subprocess
subprocess.call([FFMPEG_STATIC, '-i', input_file, output_file])


来源:https://stackoverflow.com/questions/47044448/how-to-install-ffmpeg-on-aws-lambda-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!