Skip to content

Instantly share code, notes, and snippets.

@dkarchmer
Last active March 14, 2024 17:32
Show Gist options
  • Save dkarchmer/635496ff9280011b3eef to your computer and use it in GitHub Desktop.
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
(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();
});
})();
@shubhamkourav
Copy link

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