Skip to content

Instantly share code, notes, and snippets.

@erfg12
Last active June 24, 2019 19:29
Show Gist options
  • Save erfg12/e09f080be43df2280fa4a112e86fb287 to your computer and use it in GitHub Desktop.
Save erfg12/e09f080be43df2280fa4a112e86fb287 to your computer and use it in GitHub Desktop.
Run this script with a file argument to convert. Ex: convert.js myFile.avi
var ffmpeg = require('fluent-ffmpeg');
// convert to small streamable MP4
ffmpeg(process.argv[2], { timeout: 432000 }).addOptions([
'-c:v libx264',
'-pix_fmt yuv420p',
'-movflags faststart'
]).output(process.argv[2] + '.mp4')
.on('progress', function(progress) {
console.log('Processing: ' + progress.percent + '% done' + '\r\n');
})
.on('end', function() {
console.log('Finished converting');
}).run()
// convert to HLS (m3u8). Apple's favorite media format.
ffmpeg(process.argv[2], { timeout: 432000 }).addOptions([
'-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
'-level 3.0',
'-start_number 0', // start the first .ts segment at index 0
'-hls_time 10', // 10 second segment duration
'-hls_list_size 0', // Maxmimum number of playlist entries (0 means all entries/infinite)
'-f hls' // HLS format
]).output(process.argv[2] + '/index.m3u8')
.on('progress', function(progress) {
console.log('Processing: ' + progress.percent + '% done' + '\r\n');
})
.on('end', function() {
console.log('Finished converting');
}).run()
{
"name": "hls",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js hls",
"stop": "killall -SIGINT hls"
},
"engines": {
"node": "4.6.0"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"fluent-ffmpeg": "^1.7.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment