Last active
June 21, 2021 10:24
-
-
Save nitpum/6c467eb9df6e6a667fdbb1bfd7d21b5e to your computer and use it in GitHub Desktop.
Download streaming video all .ts from .m3u8
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
/* | |
Requirement: | |
ffmpeg: https://ffmpeg.org/ | |
Command line: | |
ffmpeg -i <URL> -vcodec copy -acodec copy -f mpegts "<OUTPUT>.mp4" | |
Example: | |
ffmpeg -i 'http://www.github.com' -vcodec copy -acodec copy -f mpegts "output.mp4" | |
*/ | |
// Node.js | |
const path = require('path'); | |
const exec = require('child_process').exec; | |
var urls = [ | |
]; | |
var headers = { | |
}; | |
function loadVideo(des, url, headers) { | |
var header = ''; | |
if (headers) { | |
header = ' -headers "'; | |
var headerCount = 0; | |
for (var h in headers) { | |
header += h + ': '; | |
header += headers[h]; | |
if (headerCount < headers.length - 1) | |
header += ','; | |
headerCount++; | |
} | |
header += '"'; | |
} | |
console.log("Downloading video : " + url); | |
cmd = 'start "" cmd.exe /k'; // Open new command window | |
cmd += ' ffmpeg'+ header +' -i "' + url + '" -vcodec copy -acodec copy -f mpegts "'+ des + '"'; | |
// Run cmd | |
exec(cmd, function(error, stdout, stderr) { | |
console.log('End process'); | |
console.log('stdout: ' + stdout); | |
console.log('stderr: ' + stderr); | |
if (error !== null) { | |
console.log(' exec error: ' + error); | |
} | |
}); | |
} | |
for (var i = 0; i < urls.length;i++) { | |
loadVideo('./video-' + i + '.mp4', urls[i], headers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment