sg.cc sg.cc - 6 months ago 9
Node.js Question

How to stream video data to a video element?

I have a Node.js process which outputs a video stream into my Node.js app.

On the client end, there is a

<video>
tag. I would like to stream the video from Node.js into the
src
attribute of the video tag. My previous experience tells me that we must use the
blob
object for this. However, I'm not a hundred percent certain how and why I would use it.

Another possible solution I'm thinking of is to create some sort of a temporary file on my server, then write the stream to that file, then serve that file as the source for the video. However, that doesn't seem intuitive. I was wondering, then, if there is a more established solution for an issue like this.

Answer

Probably you might want to look at the following options:

  1. BinaryJS. It's bidrectional realtime binary data transfer tool based on websockets.

  2. JSMpeg stream-server (in case of capturing) from Phoboslab guys. All you need to do is start ffmpeg and point it to the domain and port where the nodejs script is running. More info you can find here.

  3. Pipe a stream directly. Good answer is posted here. In few words you just need to specify Accept-Ranges, Content-Range, Content-Length and Content-Type headers, then create relevant Read stream (with start and end options) and pipe it to the response object.

Comments