Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 909
sg.cc Avatar asked Mar 29 '16 03:03

sg.cc


2 Answers

m3u8 format is commonly used for streaming. Video streaming/transcoding is a resource intensive thing. I would suggest you to use third party service to do so, if you have that option.

like image 167
atinder Avatar answered Oct 12 '22 21:10

atinder


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.

like image 3
oleh.meleshko Avatar answered Oct 12 '22 20:10

oleh.meleshko