Skip to content

Instantly share code, notes, and snippets.

@devesh2605
Created September 14, 2018 08:49
Show Gist options
  • Save devesh2605/27f7ac11390f190cdbe327428b0bf7eb to your computer and use it in GitHub Desktop.
Save devesh2605/27f7ac11390f190cdbe327428b0bf7eb to your computer and use it in GitHub Desktop.
Combine videos using FFMPEG in NodeJS
const inputJson = require('./list.json'),
ffmpeg = require('fluent-ffmpeg');
const fileList = inputJson.paths;
const runFfmpeg = function(){
new Promise((resolve, reject) => {
console.log('Starting task of combining ', fileList.length, 'files');
console.log('Added file ', fileList[0], ' to the list');
const ffmpegJob = ffmpeg(fileList[0]);
for(var i = 1; i < fileList.length; i++) {
console.log('Added file ', fileList[i], ' to the list');
ffmpegJob.input(fileList[i]);
}
ffmpegJob.on('progress', function(progress) {
console.log('Processing', progress.percent, '% done');
})
.on('error', function(err) {
console.log('An error occurred: ', err.message);
reject(err);
})
.on('end', function() {
console.log('Merging finished for file ');
resolve();
})
.mergeToFile('./output.mp4');
});
}
runFfmpeg();
/*
list.json
{
"paths": ["./files/file1.mp4", "./files/file2.mp4"]
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment