Lambda not connecting to ffmpeg

后端 未结 2 471
我寻月下人不归
我寻月下人不归 2020-12-21 22:15

I have an issue with a Lambda function that tries to use ffmpeg as a third party on AWS. The function itself uses ffmpeg.js library which generates ffmpeg commands in it\'s

相关标签:
2条回答
  • 2020-12-21 22:42

    You need to include static build of ffmpeg inside your project directory

    Download x86_64 version. As it the one used my lambda environment

    Unzip the file and copy ffmpeg named file which is binary build and paste it in your project directory.

    After that on the top of your code paste the following snippet:

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

    Now inside your exports.handler, paste the following line of code in the beginning of function call. It will look like this

    exports.handler = function(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');
    // Your task to be performed
    }
    }
    )
    }
    

    I hope this helps. Don't forget to leave a thumbs up :) Above solution is for Node.js language

    0 讨论(0)
  • 2020-12-21 22:43

    I successfully can work with ffmpeg on AWS Lambda in Python:

    1. Get static build of ffmpeg from here.
    2. Untar with tar -zxvf ffmpeg-release-amd64-static.tar.xz
    3. Fetch file ffmpeg (and optionally ffprobe) from folder and delete rest of files.
    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 and save.

    In your Python code you need to set the correct filepath to the ffmpeg static build like so:

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

    I didn´t have to change any file permissions. This wouldn't have worked anyways because /var/task/ doesn't seem to be writeable.

    input_file and output_file are local files in your spawned Lambda instance. I download my files from s3 to /tmp/ and do the processing with ffmpeg there. Make also sure to set sufficient memory and timeout for the Lambda (I use maximum settings for my workflow).

    0 讨论(0)
提交回复
热议问题