Lambda函数(Node JS)中的命令ffmpeg失败

时间:2019-02-14 20:44:26

标签: node.js ffmpeg aws-lambda

我正在尝试在lambda函数中将视频文件转换为音频文件。但是我不断收到FFmpeg命令失败错误。我将FFmpeg二进制exe文件放在项目目录中。但仍然出现相同的错误。我尝试了这个(Lambda not connecting to ffmpeg),但是我的问题尚未解决。有帮助吗?谢谢,

这是我的lambda函数代码

process.env.PATH = process.env.PATH + ':/tmp/';
process.env['FFMPEG_PATH'] = '/tmp/ffmpeg';
const BIN_PATH = process.env['LAMBDA_TASK_ROOT'];
process.env['PATH'] = process.env['PATH'] + ':' + BIN_PATH;

const fs = require('fs');
const AWS = require('aws-sdk');

AWS.config.update({
    region : 'us-east-2'
});
const s3 = new AWS.S3({apiVersion: '2006-03-01'});


exports.handler = (event, context, callback) => {
    require('child_process').exec(
        'cp /var/task/ffmpeg /tmp/.; chmod 755 /tmp/ffmpeg;',
        function (error, stdout, stderr) {
            if (error) {
                console.log('Erro occured',error);
            } else {
                var ffmpeg = require('ffmpeg');
                var params = {
                    Bucket: "bucket_name",
                    Key: event.Records[0].s3.object.key
                };
                s3.getObject(params, function(err, data) {
                    if (err) {
                        console.log("Error", err);
                    }
                    fs.writeFile("/tmp/vid.mp4", data.Body, function (err) {
                        if (err) console.log(err.code, "-", err.message);
                        return callback(err);
                    }, function() {
                        try {
                            var stats = fs.statSync("/tmp/vid.mp4");
                            console.log("size of the file1 ", stats["size"]);
                            try {
                                console.log("Yeah");
                                var process = new ffmpeg('/tmp/vid.mp4');
                                process.then(function (video) {
                                    // Callback mode
                                    console.log("video function ", video);
                                    video.fnExtractSoundToMP3('/tmp/video.mp3', function (error, file) {
                                        if (!error)
                                            console.log('Audio file: ' + file);
                                        else console.log('error video ', error);
                                    });
                                }, function (err) {
                                    console.log('Error: ' + err);
                                });
                            } catch (e) {
                                console.log(e.code);
                                console.log(e.msg);
                            }
                        } catch (e) {
                            console.log("file is not complete", e);
                        }
                    });
                    return callback(err);
                });
            }
        }
    )
}

错误消息

{ Error: Command failed: ffmpeg -i /tmp/vid.mp4 -vn -ar 44100 -ac 2 -ab 192 -f mp3 /tmp/video.mp3

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
    killed: false,
        code: null,
    signal: 'SIGSEGV',
    cmd: 'ffmpeg -i /tmp/vid.mp4 -vn -ar 44100 -ac 2 -ab 192 -f mp3 /tmp/video.mp3' }

0 个答案:

没有答案