node.js를 사용하여 HLS 컨텐츠를 스트리밍하려고합니다. 그리고 어떻게 든 작동하지 않습니다. 누군가가 나를 도와 주면 큰 도움이 될 것입니다.HLS 노드 JS를 사용한 스트리밍
문제 : - Node.js를에서 HLS의 콘텐츠를 제공하기 위해 노력 (스트림을 살 수 없다,하지만 .TS 파일 세트와 .m3u8 재생 목록, 또는 다른 말로 VOD 컨텐츠)
폴더 구조
stream_test
|--- app.js
|--- node_modules
|--- streamcontent
|--- test.m3u8
|--- segment0.ts
|--- segment1.ts
.
.
.
|--- segment127.ts
내 app.js
이
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);
0123처럼 보인다
test.m3u8 내가
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
테스트 Scenraio을 세그먼트를 만들고 palylist하기는 FFmpeg 사용이
#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
.
.
.
과 같다 : - 아파치에서 제공하는 경우 가 잘 작동하면하지 않습니다 노드에서 제공됩니다.
테스트 도구 : - VNC 플레이어 브래드에서 아이디어를
왜'express.static'이 당신에게 이것을시키지 않겠습니까? – Brad
"이전에"
connect.static
"을 사용했지만 작동하지 않았습니다. 그러나"express.static
"으로 작동하는 것 같습니다. 감사합니다." – Tirtha