TL / DR:
I used the following code to download all the mpeg-ts chunk files from the m3u8 link, and then programmatically converted each of them to .mp4.
I got a lot of small .mp4 files that I could add to the vlc playlist and play, but I could not programmatically merge all these mp4 files into a single mp4 file using javascript.
, ts mp4 mux.js, .
:
, m3u8_to_mpegts, MPEG_TS, m3u8 .
var TsFetcher = require('m3u8_to_mpegts');
TsFetcher({
uri: "http://api.new.livestream.com/accounts/15210385/events/4353996/videos/113444715.m3u8",
cwd: "destinationDirectory",
preferLowQuality: true,
},
function(){
console.log("Download of chunk files complete");
convertTSFilesToMp4();
}
);
.ts .mp4, mpegts_to_mp4
var concat = require('concatenate-files');
function getFiles(currentDirPath, callback) {
var fs = require('fs'),
path = require('path');
fs.readdir(currentDirPath, function (err, files) {
if (err) {
throw new Error(err);
}
var fileIt = files.length;
files.forEach(function (name) {
fileIt--;
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, (fileIt==0));
}
});
});
}
var mpegts_to_mp4 = require('mpegts_to_mp4');
var toConvertIt=0, doneConvertingIt = 0;
function convertTSFilesToMp4(){
getFiles("destinationDirectory/bandwidth-198000",
function onFileDiscovered(filePath, noMoreFiles){
var filenameParts = filePath.split("/");
var filename = filenameParts[2];
if(filename.split(".")[1]=="ts"){
console.log(filename);
mpegts_to_mp4(filePath, toConvertIt+'dest.mp4', function (err) {
if(err){
console.log("Error: "+err);
}
doneConvertingIt++
console.log("Finished converting file "+toConvertIt);
if(doneConvertingIt==toConvertIt){
console.log("Done converting vids.");
}
});
toConvertIt++;
}
});
}
: , :
- , uri
- (cwd), ts ( destinationDirectory)
- preferLowQuality false, ,
- , ts ( destinationDirectory/bandwidth-198000)
, - .
Tenacex .