Created
November 19, 2013 16:15
-
-
Save tthew/7547863 to your computer and use it in GitHub Desktop.
This file contains 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
var Metalib = require('fluent-ffmpeg').Metadata; | |
var ffmpeg = require('fluent-ffmpeg'); | |
var q = require('q'); | |
var filename = process.argv[2] || null; | |
if (!filename) { | |
console.log('No source file provided'); | |
return; | |
} | |
console.log('Converting: ' + filename); | |
console.log('to: webm, ogv & mp4...'); | |
// make sure you set the correct path to your video file | |
var metaObject = new Metalib(filename, function(metadata, err) { | |
if (metadata.durationsec > 300) { | |
console.log('Video is longer than 5 minutes'); | |
return; | |
} | |
}); | |
var webm = q.defer(); | |
var ogv = q.defer(); | |
var mp4 = q.defer(); | |
var processOgv = new ffmpeg({ | |
source: filename, | |
timeout: 180 | |
}).withVideoBitrate(1024) | |
.withSize('1024x?') | |
.applyAutopadding(true, 'white') | |
.withVideoCodec('libtheora') | |
.withAspect('16:9') | |
.withFps(24) | |
.withAudioBitrate('128k') | |
.withAudioChannels(2) | |
.withAudioCodec('libvorbis') | |
.saveToFile('./output.ogv', function(stdout, stderr) { | |
if (stderr) { | |
ogv.reject(stderr); | |
} else { | |
ogv.resolve(stdout); | |
} | |
}); | |
var processWebm = new ffmpeg({ | |
source: filename, | |
timeout: 180 | |
}).withVideoBitrate(1024) | |
.withSize('1024x?') | |
.applyAutopadding(true, 'white') | |
.withVideoCodec('libvpx') | |
.withAspect('16:9') | |
.withFps(24) | |
.withAudioBitrate('128k') | |
.withAudioCodec('libvorbis') | |
.withAudioChannels(2) | |
.toFormat('webm') | |
.saveToFile('./output.webm', function(stdout, stderr) { | |
if (stderr) { | |
webm.reject(stderr); | |
} else { | |
webm.resolve(stdout); | |
} | |
}); | |
var processMp4 = new ffmpeg({ | |
source: filename, | |
timeout: 180 | |
}).withVideoBitrate(1024) | |
.withSize('1024x?') | |
.applyAutopadding(true, 'white') | |
.withVideoCodec('libx264') | |
.withAspect('16:9') | |
.withFps(24) | |
.withAudioBitrate('128k') | |
.withAudioChannels(2) | |
.toFormat('mp4') | |
.saveToFile('./output.mp4', function(stdout, stderr) { | |
if (stderr) { | |
mp4.reject(stderr); | |
} else { | |
mp4.resolve(stdout); | |
} | |
}); | |
q.allSettled([ | |
webm.promise, | |
ogv.promise, | |
mp4.promise, | |
]).then(function (results) { | |
var errors = []; | |
results.forEach(function (result) { | |
if (result.state === "fulfilled") { | |
var value = result.value; | |
} else { | |
errors.pop(result.reason); | |
} | |
}); | |
if (errors.length === 0) { | |
console.log('SUCCESS!'); | |
} else { | |
console.log('SOMETHING WENT WRONG'); | |
console.log(errors); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment