AWS LAMBDA制作视频缩略图 [英] AWS Lambda making video thumbnails

查看:997
本文介绍了AWS LAMBDA制作视频缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望做的视频上传到S3的缩略图,我知道如何使用的Node.js和ffmpeg的做到这一点。

I want make thumbnails from videos uploaded to S3, I know how to make it with Node.js and ffmpeg.

根据这个论坛帖子我可以添加库:

ImageMagick的是当前所提供的唯一的外部库   默认的,但你可以包括在zip任何额外的依赖   文件当您创建一个lambda函数你提供。需要注意的是,如果此   是本机库或可执行文件,你需要确保它   运行在亚马逊的Linux。

ImageMagick is the only external library that is currently provided by default, but you can include any additional dependencies in the zip file you provide when you create a Lambda function. Note that if this is a native library or executable, you will need to ensure that it runs on Amazon Linux.

但我怎么可以把静态的ffmpeg二进制在AWS上的lambda?

But how can I put static ffmpeg binary on aws lambda?

和我怎样才能从Node.js的这种静态二进制(ffmpeg)来调用与AWS LAMBDA?

And how can I call from Node.js this static binary (ffmpeg) with AWS Lambda?

我是新手亚马逊AWS和Linux

I'm newbie with amazon AWS and Linux

谁能帮我?

推荐答案

该过程概述了纳文是正确的,但它掩盖了一个细节,可以是pretty的痛苦 - 包括在zip FFmpeg的二进制文件和访问它的lambda函数中。

The process as outlined by Naveen is correct, but it glosses over a detail that can be pretty painful - including the ffmpeg binary in the zip and accessing it within your lambda function.

我只是通过这个去了,它是这样的:

I just went through this, it went like this:

  1. 包含了ffmpeg的静态二进制在压缩的lambda功能包(我有一口任务,将它复制到 / DIST 每次生成时间)
  2. 当你的函数被调用,将二进制到的/ tmp / DIR和搭配chmod 它给自己访问
  3. 更新路径,以包含FFmpeg的可执行文件(我用流畅,ffmpeg的它可以让你设置 2 ENV瓦尔来处理更多容易。
  1. Include the ffmpeg static binary in your zipped lambda function package (I have a gulp task to copy this into the /dist every time it builds)
  2. When your function is called, move the binary to a /tmp/ dir and chmod it to give yourself access
  3. update your PATH to include the ffmpeg executable (I used fluent-ffmpeg which lets you set two env vars to handle that more easily.

让我知道,如果有更多的细节是必要的,我可以更新这个答案。

Let me know if more detail is necessary, I can update this answer.

复制和chmod(步骤2),显然是不理想的....很想知道如果任何人发现了一个更好的方式来处理这个问题,如果这是典型的这种建筑风格。

The copy and chmod (step 2) is obviously not ideal.... would love to know if anyone's found a better way to handle this, or if this is typical for this architecture style.

复制+搭配chmod一步不再需要,作为@Allen指出 - 我直接在/ var /任务执行的ffmpeg的lambda函数/,没有麻烦,在这一点上。请务必行chmod 755 上传到LAMBDA(也是@Allen指出)。

The copy + chmod step is no longer necessary, as @Allen pointed out – I'm executing ffmpeg in Lambda functions directly from /var/task/ with no trouble at this point. Be sure to chmod 755 whatever binaries before uploading them to Lambda (also as @Allen pointed out).

我不再用流利的-ffmpeg的做工作。相反,我更新的路径,包括 process.env ['LAMBDA_TASK_ROOT'] 和执行简单的bash脚本。

I'm no longer using fluent-ffmpeg to do the work. Rather, I'm updating the PATH to include the process.env['LAMBDA_TASK_ROOT'] and executing simple bash scripts.

在你的lambda函数的顶部:

At the top of your Lambda function:

process.env['PATH'] = process.env['PATH'] + "/" + process.env['LAMBDA_TASK_ROOT']

有关使用ffmpeg的一个例子:λ-PNG图片到MP4

For an example that uses ffmpeg: lambda-pngs-to-mp4.

有关的有用成分拉姆达摆: lambduh

For a slew of useful lambda components: lambduh.

更新更多的细节:

我这里下载静态的ffmpeg二进制。亚马逊建议启动了一个EC2,建设二进制上有您的使用,因为这样的环境将是相同的LAMBDA运行的条件。可能是一个好主意,但更多的工作,而这个静态的下载为我工作。

I downloaded the static ffmpeg binary here. Amazon recommends booting up an EC2 and building a binary for your use on there, because that environment will be the same as the conditions Lambda runs on. Probably a good idea, but more work, and this static download worked for me.

我把仅有的的ffmpeg 二进制到我的项目的待归档 / DIST 文件夹。

I pulled only the ffmpeg binary into my project's to-be-archived /dist folder.

在你的拉链上传到拉姆达,它生活在的/ var /任务/ 。无论出于何种原因,我跑进试图使用二进制在该位置访问问题,更多的问题试图在文件中编辑权限存在。一个快速的解决办法是将二进制移至的/ tmp / 搭配chmod 上有权限。

When you upload your zip to lambda, it lives at /var/task/. For whatever reason, I ran into access issues trying to use the binary at that location, and more issues trying to edit permissions on the file there. A quick work-around is to move the binary to /tmp/ and chmod permissions on it there.

在节点,您可以运行通过 child_process 外壳。我所做的是这样的:

In Node, you can run shell via a child_process. What I did looks like this:

require('child_process').exec(
  'cp /var/task/ffmpeg /tmp/.; chmod 755 /tmp/ffmpeg;',
  function (error, stdout, stderr) {
    if (error) {
      //handle error
    } else {
      console.log("stdout: " + stdout)
      console.log("stderr: " + stderr)
      //handle success
    }
  }
)

这多少应该给你一个可执行的二进制文件的ffmpeg在lambda函数 - 但是你仍然需要确保它在你的$ PATH。

This much should give you an executable ffmpeg binary in your lambda function – but you still need to make sure it's on your $PATH.

我放弃了一口流利的-ffmpeg的使用节点,推出有利于刚推出一个bash脚本出节点的,所以对我来说,我不得不添加的ffmpeg的命令的/ tmp / 我在lambda函数顶部的路径:

I abandoned fluent-ffmpeg and using node to launch ffmpeg commands in favor of just launching a bash script out of node, so for me, I had to add /tmp/ to my path at the top of the lambda function:

process.env.PATH = process.env.PATH +':/ tmp目录/

如果你用流利的-的ffmpeg,你可以设置路径通过到FFmpeg的:

If you use fluent-ffmpeg, you can set the path to ffmpeg via:

process.env ['FFMPEG_PATH'] ='/ tmp目录/ ffmpeg的';

有些关联/无耻的自我插头:我工作的一组模块,使建设lambda函数出组合的模块更容易的名义下的 Lambduh 。可能会节省一些时间让这些东西放在一起。一个简单的例子:在处理这一场景 lambduh-执行将非常简单,如:

Somewhat related/shameless self-plug: I'm working on a set of modules to make building Lambda functions out of composable modules easier under the name Lambduh. Might save some time getting these things together. A quick example: handling this scenario with lambduh-execute would be as simple as:

promises.push(execute({
  shell: "cp /var/task/ffmpeg /tmp/.; chmod 755 /tmp/ffmpeg",
})

其中,承诺是要运行的承诺的数组。

Where promises is an array of promises to be run.

这篇关于AWS LAMBDA制作视频缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆