HLS-Streaming mit node JS

Ich versuche, die stream-Inhalte mit HLS node.js. Und irgendwie hat es nicht funktioniert. Es wäre eine große Hilfe, wenn mir jemand hilft.

Problem:-
Versuchen, zu dienen HLS-Inhalten aus node.js (nicht im live-stream, aber eine Reihe von .ts Dateien und .m3u8 playlist, oder in anderen Worten, VOD-Inhalt)

Ordner-Struktur

stream_test
|--- app.js
|--- node_modules
|--- streamcontent
        |--- test.m3u8
        |--- segment0.ts
        |--- segment1.ts
        .
        .
        .
        |--- segment127.ts

Meine app.js sieht wie folgt aus

var http = require('http'),
    url = require('url'),
    path = require('path'),
    fs = require('fs');
var mimeTypes = {
    "html": "text/html",
    "jpeg": "image/jpeg",
    "jpg": "image/jpeg",
    "png": "image/png",
    "js": "text/javascript",
    "css": "text/css",
    "ts": "video/MP2T",
    "m3u8": "application/vnd.apple.mpegurl"};

http.createServer(function(req, res) {
    var uri = url.parse(req.url).pathname;
    var filename = path.join(process.cwd(), unescape(uri));
    var stats;

    console.log('filename '+filename);

    try {
        stats = fs.lstatSync(filename); //throws if path doesn't exist
    } catch (e) {
        res.writeHead(404, {'Content-Type': 'text/plain'});
        res.write('404 Not Found\n');
        res.end();
        return;
    }


    if (stats.isFile()) {
        //path exists, is a file
        var mimeType = mimeTypes[path.extname(filename).split(".")[1]];
        res.writeHead(200, {'Content-Type': mimeType} );

        var fileStream = fs.createReadStream(filename);
        fileStream.pipe(res);
    } else if (stats.isDirectory()) {
        //path exists, is a directory
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.write('Index of '+uri+'\n');
        res.write('TODO, show index?\n');
        res.end();
    } else {
        //Symbolic link, other?
        //TODO: follow symlinks?  security?
        res.writeHead(500, {'Content-Type': 'text/plain'});
        res.write('500 Internal server error\n');
        res.end();
    }

}).listen(8000);

Den test.m3u8 sieht wie folgt aus

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:19
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:12.595922,
segment0.ts
.
.
.

Ich verwendet ffmpeg zum erstellen der Segmente und palylist

ffmpeg -i video-a.mp4  -c:a libmp3lame -ar 48000 -ab 64k  -c:v libx264   -b:v 128k -flags -global_header -map 0 -f segment  -segment_list test.m3u8 -segment_time 30 -segment_format mpegts segment_%05d.ts

Test Scenraio:-
Funktioniert gut, wenn Ihnen von Apache, nicht, wenn wir Ihnen von Knoten.

- Test-Tool:-
VNC-Player

Warum lassen Sie nicht express.static dies für Sie tun?
"Ich habe "<code>verbinden.statische</code>" weiter oben, aber es funktionierte nicht. Aber mit "<code>express.statische</code>" es scheint zu funktionieren. danke für die Idee."

InformationsquelleAutor Tirtha | 2014-02-19

Schreibe einen Kommentar