Last active
March 14, 2024 17:32
-
-
Save dkarchmer/635496ff9280011b3eef to your computer and use it in GitHub Desktop.
Example of NodeJS script to resize videos (to 1080P and 720P) using fluent-ffmpeg
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
(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(); | |
}); | |
})(); |
this code hasn't worked on the synchronization
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@augustocesar84
Note also I did create a docker image at the time (https://github.com/dkarchmer/docker-fluent-ffmpeg), so if you use docker, it should just be
But as I said, that was a long time ago, so it may or may not work. You are on your own here if does not.