我需要一个开源RTMP服务器,用于Linux(centos)的流式mp3,我发现了一些,但这些不要让我按需流,只是生活。感谢
答案 0 :(得分:1)
按需执行...只需安装node.js并执行:
node file_containing_below.js
并且是的,考虑它是开源的; - )
var http = require('http');
var fs = require('fs');
var util = require('util');
var port = 8888;
var host = "localhost";
http.createServer(function (req, res) {
var path = "/path/to/some/video/or/audio/file.mp3"; // mp4 or most any video/audio file
var stat = fs.statSync(path);
var total = stat.size;
if (req.headers.range) { // meaning client (browser) has moved the forward/back slider
// which has sent this request back to this server logic ... cool
var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1;
var chunksize = (end-start)+1;
console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
var file = fs.createReadStream(path, {start: start, end: end});
res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': 'video/mp4' });
file.pipe(res);
} else {
console.log('ALL: ' + total);
res.writeHead(200, { 'Content-Length': total, 'Content-Type': 'video/mp4' });
fs.createReadStream(path).pipe(res);
}
}).listen(port, host);
console.log("Server running at http://" + host + ":" + port + "/");
现在只需将一些客户端(您的浏览器)指向URL
即可http://localhost:8888/
是的,一旦播放前进/后退滑块,就会自动在任意客户端(浏览器)上工作