How to get specific start & end time in ffmpeg by Node JS?

依然范特西╮ 提交于 2020-04-14 08:52:47

问题


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:


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 !!



来源:https://stackoverflow.com/questions/47090699/how-to-get-specific-start-end-time-in-ffmpeg-by-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!