I am trying to cut specific parts out from a video and then merge all those parts into a single video file using nodejs and ffmpeg.
Here's my code and currently I can cut only one part out of the video from .setStartTime
to .setDuration
and that part is being saved.
var ffmpeg = require('fluent-ffmpeg');
var command = ffmpeg()
.input('./videos/placeholder-video.mp4')
.setStartTime('00:00:03')
.setDuration('02')
.output('./videos/test.mp4')
.on('start', function(commandLine) {
console.log('Started: ' + commandLine);
})
.on('end', function(err) {
if(!err)
{
console.log('conversion Done');
}
})
.on('error', function(err){
console.log('error: ', +err);
}).run();
How do I cut out multiple parts out from the video and merge them in a single video file. I know about .mergeToFile
method but how do I use it after cutting different parts from my video.
I tried using .setStartTime
and .setDuration
twice like below but the first one's are being ignored.
.input('./videos/placeholder-video.mp4')
.setStartTime('00:00:03')
.setDuration('02')
.setStartTime('00:00:15')
.setDuration('05')
.output('./videos/test.mp4')
PLEASE READ UPDATE
Could not test it yet, but try following: Set the input video two times, like this:
Then you can merge the multiple inputs with
.mergeToFile
.UPDATE
My answer cannot work due to restriction of
.setDuration
. It is an output option, so it defines how long transcoding to the output file is done: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg It is not used to define the length/duration of the input.Another option would be
.loop
, but apparently it is not supported for this purpose: https://video.stackexchange.com/questions/12905/repeat-loop-input-video-with-ffmpeg/12906#12906If you really want to use nodejs, you need multiple commands
Something like this:
Big problem: your nodejs script will not start if temporary files are not present. So it would be much more easier to use a bash or batch script.