使用 node fluent ffmpeg 合并多个视频 [英] Merge Multiple Videos using node fluent ffmpeg

查看:36
本文介绍了使用 node fluent ffmpeg 合并多个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求是读取目录下的所有文件并合并.我正在使用节点 fluent-ffmpeg 来实现这一点.首先读取目录中的所有文件,并通过添加 .input.

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);
}

它给出了以下错误:

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)

感谢任何帮助.

推荐答案

试试这个

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!');
});

这篇关于使用 node fluent ffmpeg 合并多个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆