2

I want to cut a video in specific start & end time & save it. I cant understand how to cut specific time of that video by Node JS.

Video copy code :

 return new Promise(function(resolve ,reject){
        var ffmpeg = require('fluent-ffmpeg');
        ffmpeg(fs.createReadStream(path.join(__dirname,'..','..','/video.mp4')))
            .seekInput('01:00')
            .duration('02:00')
            .outputOptions('-strict experimental')
            .on('start', function(commandLine) {
                console.log('Spawned Ffmpeg with command: ' + commandLine);
                }).on('end', function(err) {
                if (!err) {
                    console.log('conversion Done');
                    //res.send("conversion Done");
                    resolve();
                }
                }).on('error', function(err) {
                    console.log('error: ', +err);
                    reject(err);
                }).save(path.join(__dirname,'..','..','/test.mp4'));
    });

1 Answers1

2

Please check following steps and sample code,

  1. Install  ffmpeg installed on your system steps
  2. Install module fluent-ffmpeg in your project
  3. Please check following sample code

      function clipVideo() {
    
          var params = {
            input: 'input_file',
            start: 0,
            duration: 10,
            output: 'output_file'
          };
    
          return new Promise(function(resolve, reject) {
    
              ffmpeg(params.input)
                  .setStartTime(params.start)
                  .setDuration(params.duration)
                  .save(params.output)
                  .on('start', function(commandLine) {
                      console.log('start : ' + commandLine);
                  })
                  .on('progress', function(progress) {
                      console.log('In Progress !!' + Date());
                  })
                  .on('end', function() {
                      console.log("downlaod resolved");
                      return resolve(params.clippedFile);
    
                  })
                  .on('error', function(err) {
                      console.log("reject");
                      return reject(err);
                  })
          });
      }
    

Hope this will help you !!

Santosh Shinde
  • 6,045
  • 7
  • 44
  • 68