Created
April 8, 2016 03:44
-
-
Save dydx/b8e26a11f4cf9aa7ea3bf57f466586f9 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var ffmpeg = require('fluent-ffmpeg'); | |
var fs = require('fs'); | |
var config = { | |
input: 'files', | |
output: 'files/encoded' | |
} | |
var watcher = fs.watch(config.input); | |
function m3u8ify (filename) { | |
return filename.slice(0, -3) + 'm3u8'; | |
} | |
watcher.on('change', function (event, filename) { | |
// get a stream for the file | |
let stream = fs.createReadStream(config.input + '/' + filename); | |
// transcode it | |
ffmpeg(stream) | |
.addOption('-hls_time', 60) | |
.addOption('-hls_list_size', 0) | |
.on('end', function () { | |
console.log('Completed Encoding'); | |
}) | |
// I'd like to make this better | |
.on('error', function (err, stdout, stderr) { | |
console.log('Error:', err); | |
console.log('stdout:', stdout); | |
console.log('stderr:', stderr); | |
}) | |
// save it in the output dir with the right name | |
.save(config.output + '/' + m3u8ify(filename)) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment