I'm trying to set up a web server that will support streaming video to an HTML5 video tag using node.js. Here's my code so far:
var range = request.headers.range; var total = file.length; 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; response.writeHead(206, { "Content-Range": "bytes " + start + "-" + end + "/" + total, "Accept-Ranges": "bytes", "Content-Length": chunksize, "Content-Type": type }); response.end(file);
Where "request" represents the http request, type is either "application/ogg" or "video/ogg" (I've tried both) and "file" is the .ogv file that's been read from the file system. Here are the response headers:
Content-Range bytes 0-14270463/14270464 Accept-Ranges bytes Content-Length 14270464 Connection keep-alive Content-Type video/ogg
I've examined the response headers and this code appears to be working fine, but there are a couple of problems:
Does anyone have any ideas as to what I can do to get video streaming working via node.js?
Thanks!
Chris
Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.
Using HTML5 Video Streaming It is the most innovative approach to streaming video. Content tags (e.g., <video> tag) are part of the HTML code. Thus, using the <video> tag creates a native HTML5 video player within your browser. These tags provide direction to the HTTP protocol as to what to do with this content.
Conclusion: With simple File IO operations we can read HTML file in Node. js and by using simple modules, we can send a HTML response back to client.
I know this is a really old question, but as Google seems to like it I thought it would be worth pointing out that I wrote a Node.js video streaming module (Github, or via NPM) that's hopefully worth a look too.
I was able to get this to work with some help from the nodejs forums:
http://groups.google.com/group/nodejs/browse_thread/thread/8339e0dc825c057f/822b2dd48f36e890
Highlights from the Google Groups thread:
Google chrome is known to first make a request with the range 0-1024 and then request the range "1024-".
response.end(file.slice(start, chunksize), "binary");
Then:
I was able to get the video to play no problems in firefox by setting the "connection" header to "close"
Then:
Seems that you are incorrectly computing the content-length:
var chunksize = (end-start)+1;
If start is 0 and end is 1, in your case chunksize is 2, and it should be 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With