Can I upload all segments of the m3u8 file to a single mp4 file using web (no ffmpeg)

Is it possible to load all segments m3u8into a single file using javascript or php

I was looking for this, but I didnโ€™t find anything,

+4
source share
1 answer

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');


// Read all files and run 
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--;
            // console.log(fileIt+" files remaining");
            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){   //onFileDiscovered runs for each file we discover in the destination directory
            var filenameParts = filePath.split("/"); // if on Windows execute .split("\\");, thanks Chayemor!
            var filename = filenameParts[2];
            if(filename.split(".")[1]=="ts"){   //if its a ts file
                console.log(filename);  

                mpegts_to_mp4(filePath, toConvertIt+'dest.mp4', function (err) {
                    // ... handle success/error ...
                    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 .

+4

Source: https://habr.com/ru/post/1568623/


All Articles