abcf
abcf

Reputation: 695

HTTP Live Streaming Service like LiveStream/Ustream/Twitch/Youtube Live

I'm new to live streaming and it's quite hard to find good information for beginners. Could anyone recommend resources to HLS besides Apple's documentation?

I'm trying to make an app similar to LiveStream where videos can be broadcasted to multiple users in real-time.

I've run into some services like encoding.com, heywatchencoding.com, and wowza, but I'm having difficulties with what each platform provides as the documentations for each seem to be for more intermediate/experienced users.

How difficult is it to create a more simple site like LiveStream/Ustream/Twitch/Youtube live? I'm trying to start simple with ios devices and the web, but it's harder to look for online resources. Any tips are helpful

By any chance, do anyone of you guys also know if I can use wowza with Parse.com services?

Thanks

Upvotes: 1

Views: 757

Answers (1)

Scott Stensland
Scott Stensland

Reputation: 28285

Here is a very simple Node.js media server which spins up a HTTP server to stream most any video or audio format file from server to browser . Once you have nodejs installed just execute

node file_containing_below_code.js

then point your browser at URL

http://localhost:8888/

Your browser has baked in a slider widget for forward/reverse which auto sends traffic back to this server to respond in kind

enjoy ... btw no doc required just point and shoot

var http = require('http'),
    fs = require('fs'),
    util = require('util');


var path = "/path/to/audio/or/video/file/local/to/server/cool.mp4"; // put any audio or video file here


var port = 8888;
var host = "localhost";

http.createServer(function (req, res) {

  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 + "/");

Upvotes: 1

Related Questions