【发布时间】:2019-06-13 10:25:38
【问题描述】:
我正在尝试通过 Lambda 函数将 S3 视频文件转换为音频文件。每当视频文件上传到 S3 存储桶时,我必须生成一个音频文件并通过触发 AWS Lambda 函数将其保存回 S3 存储桶。我可以在本地将视频文件转换为音频。 (Convert video to an audio file using FFMPEG)。但我想知道,每次将视频文件上传到 S3 存储桶时,如何在 Lambda 函数中执行此转换部分。我不知道如何执行此 AWS Lambda 函数。请分享您的建议。
示例代码:
var ffmpeg = require('fluent-ffmpeg');
/**
* input - string, path of input file
* output - string, path of output file
* callback - function, node-style callback fn (error, result)
*/
function convert(input, output, callback) {
ffmpeg(input)
.output(output)
.on('end', function() {
console.log('conversion ended');
callback(null);
}).on('error', function(err){
console.log('error: ', e.code, e.msg);
callback(err);
}).run();
}
convert('./df.mp4', './output.mp3', function(err){
if(!err) {
console.log('conversion complete');
//...
}
});
谢谢,
【问题讨论】:
-
如果您有大型视频文件,也可能值得考虑使用 Elastic Transcoder。见medium.com/@ratulbasak93/…
标签: node.js amazon-web-services amazon-s3 ffmpeg