Skip to content

Instantly share code, notes, and snippets.

@dydx
Created April 8, 2016 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dydx/b8e26a11f4cf9aa7ea3bf57f466586f9 to your computer and use it in GitHub Desktop.
Save dydx/b8e26a11f4cf9aa7ea3bf57f466586f9 to your computer and use it in GitHub Desktop.
'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