Ayyyyyy, I've done quite a bit of node.js programming so periodically I'll be releasing some of my projects and/or useful scripts.
This script really only needs to be modified to point to the mp4 path, other than that just run it and you'll have a webserver dedicated to efficiently streaming videos to multiple clients. Uses for this script range from using a simultaneous video streaming service (I've used it to stream to large groups on cytu.be, but they changed it so you have to be running HTTPS) to streaming a movie to TV boxes like Chromecast, Amazon Penis, and Android boxes.
Code:
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = '/path/to/your/video.mp4';
var stat = fs.statSync(path);
var total = stat.size;
if (req.headers['range']) {
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(80);
console.log('Mp4 file is streaming directly to port 80.');