npm i fluent-ffmpeg
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
(function () { var ffmpeg = require('fluent-ffmpeg'); function baseName(str) { var base = new String(str).substring(str.lastIndexOf('/') + 1); if(base.lastIndexOf(".") != -1) { base = base.substring(0, base.lastIndexOf(".")); } return base; } var args = process.argv.slice(2); args.forEach(function (val, index, array) { var filename = val; var basename = baseName(filename); console.log(index + ': Input File ... ' + filename); ffmpeg(filename) // Generate 720P video .output(basename + '-1280x720.mp4') .videoCodec('libx264') .noAudio() .size('1280x720') // Generate 1080P video .output(basename + '-1920x1080.mp4') .videoCodec('libx264') .noAudio() .size('1920x1080') .on('error', function(err) { console.log('An error occurred: ' + err.message); }) .on('progress', function(progress) { console.log('... frames: ' + progress.frames); }) .on('end', function() { console.log('Finished processing'); }) .run(); }); })(); |
node index.js video.mp4