Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
795 views
in Technique[技术] by (71.8m points)

javascript - Merge Multiple Videos using node fluent ffmpeg

requirement is to read all the files in the directory and merge them. I am using node fluent-ffmpeg to achieve this. First of all reading all the files in the directory appending concatenating the string by adding .input.

var finalresult="E:/ETV/videos/finalresult.mp4"
outputresult : It consists of all the files read in the directory.

/*Javascript*/
MergeVideo(outputresult);
function MergeVideo(outputresult){
console.log("in merge video");
var videostring = "";

for(i=1;i<5;i++)
    {
videostring = videostring+".input("+"'"+outputresult[i]+"'"+")";
}
console.log("Video String"+videostring);
    var proc = ffmpeg()+videostring
    .on('end', function() {
      console.log('files have  succesfully Merged');
        })
    .on('error', function(err) {
      console.log('an error happened: ' + err.message);
    })
    .mergeToFile(finalresult);
}

It gives the following error:

TypeError: Object .input('ETV 22-02-2015 1-02-25 AM.mp4').input('ETV 22-02-2015
9-33-15 PM.mp4').input('ETV 22-02-2015 9-32-46 AM.mp4').input('ETV 22-02-2015 8-
32-44 AM.mp4') has no method 'on'
    at MergeVideo (D:DevelopmentNode
ode-fluent-ffmpeg-master
ode-fluent-ffm
peg-masterexamplesdemo.js:140:6)
    at Object.<anonymous> (D:DevelopmentNode
ode-fluent-ffmpeg-master
ode-fl
uent-ffmpeg-masterexamplesdemo.js:129:1)
    at Module._compile (module.js:456:26)

Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this

var fluent_ffmpeg = require("fluent-ffmpeg");

var mergedVideo = fluent_ffmpeg();
var videoNames = ['./video1.mp4', './video2.mp4'];

videoNames.forEach(function(videoName){
    mergedVideo = mergedVideo.addInput(videoName);
});

mergedVideo.mergeToFile('./mergedVideo.mp4', './tmp/')
.on('error', function(err) {
    console.log('Error ' + err.message);
})
.on('end', function() {
    console.log('Finished!');
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...