3

I am building a lambda function that requires ffmpeg. The error that I am getting is:

ERROR :: Error: Cannot find ffmpeg

Relevant code to the problem is below...

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

var ffmpeg = require('fluent-ffmpeg')

exports.handler = (event, context, callback) => {

   var proc = new ffmpeg();

   proc.addInput('testfile.mp4)
   .on('start', function(ffmpegCommand) {
    })
   .on('progress', function(data) {
   })
   .on('end', function() {
   })
   .on('error', function(error) {
     /// ERROR IS HERE
   })
   .outputOptions(['-hls_time 10'])
   .output(fileName + '.m3u8')
   .run();

}

Here's my ZIP structure:

./ffmpeg
./ffprobe
./index.js
./node_modules
./node_modules/aws-sdk
./node_modules/ffmpeg
./node_modules/fluent-ffmpeg
./package.json

I've read around and have seen people mention chmod-ing ffmpeg and ffprobe, and I tried that using chmod 755 on both executables, and that didn't work.

Also read about having to change the path. I tried what I could, and was unsuccessful again. I am not sure where to turn from here, or how to further diagnose what I am doing wrong. Any help would be greatly appreciated. Thanks!

user3678528
  • 1,741
  • 2
  • 18
  • 24
raisedandglazed
  • 804
  • 11
  • 29
  • Check my answer for a similar question: http://stackoverflow.com/questions/36063411/aws-lambda-permission-denied-when-trying-to-use-ffmpeg – helloV Aug 31 '16 at 05:58

1 Answers1

0

Apart of fluent-ffmpeg you need to install:

npm install @ffmpeg-installer/ffmpeg
npm install @ffprobe-installer/ffprobe

After that you need to first get the path then set the path to both FFmpeg and ffprobe with the next lines of code:

const ffmpeg = require('fluent-ffmpeg'); // first require this

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;

ffmpeg.setFfmpegPath(ffmpegPath);

const ffprobePath = require('@ffprobe-installer/ffprobe').path;

ffmpeg.setFfprobePath(ffprobePath);

After the previous steps implement the function that returns a promise (Metadata about the video)

ffprobe first parameter is path to local video and second is anonymous function that returns either resolve with metadata or reject with error

const videoInformation = () => {
    return new Promise((resolve,reject) => {
        ffmpeg.ffprobe('./Fishes - 16166.mp4', (err,info)=>{
            if(err) {
                reject(err)
            } else {
                resolve(info)
            }
        })
    })
}

This part will return metadata from video

try {
    const data = await videoInformation();
    console.log(data)
} catch (err){
    console.log(err)
}
Jan
  • 1,268
  • 4
  • 12
  • 20