Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Using Node to stream Video to HTML5

Using Node to stream Video to HTML5

Problem

I've been playing around with Node and websockets and built a small test app that streams audio using websockets. The server breaks apart the mp3 using createReadStream, throttles the Stream using node-throttle and sens the binary data using the "ws" module. On the client side I pick up the chunks on the websocket and use decodeAudioData (http://www.html5rocks.com/en/tutorials/webaudio/intro/) to decode and play the chunk. It all works relatively ok.

What I was curious to do next was to stream video in the same manner to the HTML5 video tag. But I can't really find any reference material on the web to achieve this in the same manner as my audio test above.

Is there a video equivalent for "decodeAudioData"?

Can I feed chunks of data into a video tag?

I've got a similar sample running that I picked up from...

https://gist.github.com/paolorossi/1993068

But this isn't really what I am looking for. First of all it doesn't really seem to be streaming to me. The client buffers it all before playing it. Also, similar to my audio test I want the stream to be throttled on the server side so that when a new client connects they join the video at whatever point it is currently at. i.e. 30 minutes in or whatever.

Thanks

Problem courtesy of: fatlog

Solution

OK,

I found a Solution to this after much searching.

The MediaSource API is what I was looking for...

var mediaSource = new MediaSource();
var sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
sourceBuffer.append(new Uint8Array(data));

This link provided the solution...

http://html5-demos.appspot.com/static/media-source.html

Solution courtesy of: fatlog

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Using Node to stream Video to HTML5

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×