2
var fs = require('fs');

var ffmpeg = require('fluent-ffmpeg');

var outStream = fs.createWriteStream('output.mp4'); //output path

ffmpeg('input.mp4')
  .duration(600) //trim
  .on('error', function(err) {
      console.log('An error occurred: ' + err.message);
   })
  .on('end', function() {
      console.log('Processing finished !');
   })
  .pipe(outStream, { end: true });

I installed fluent-ffmpeg in my working directory, can anybody tell me what are the other requirements? I'm working on a windows machine.

Gander
  • 1,854
  • 1
  • 23
  • 30
Sumit Sarkar
  • 49
  • 3
  • 7
  • Did you find any solution? I'm stuck on error `Error: Cannot find ffmpeg`. I have added ffmpeg to the environmental variables also. Have tried a lot but not able to get it working :( How did you link the PATH? Adding to Env Var should be enough right? – Somename Apr 04 '17 at 01:14
  • ya you have to set the bin directory of ffmpeg.exe in your path env varible – Sumit Sarkar Apr 14 '17 at 20:27

1 Answers1

2

This worked for me. Make sure you've ffmpeg installed in your machine properly. Check by running "ffmpeg" in command prompt.

const conv = new ffmpeg({ source: "sourcepath" });
conv
.setStartTime(2) //Can be in "HH:MM:SS" format also
.setDuration(10) 
.on("start", function(commandLine) {
    console.log("Spawned FFmpeg with command: " + commandLine);
})
.on("error", function(err) {
    console.log("error: ", +err);
})
.on("end", function(err) {
    if (!err) {
        console.log("conversion Done");
    }
})
.saveToFile("outputpath");