Created
September 14, 2018 08:49
-
-
Save devesh2605/27f7ac11390f190cdbe327428b0bf7eb to your computer and use it in GitHub Desktop.
Combine videos using FFMPEG in NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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