Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using websocket to stream in video tag

I'm trying to stream a (WebM or MP4) video from Node.js to HTML5 using websockets (the websocket library is Socket.IO on both server and client). The browser in use is the latest version of Chrome (version 26.0.1410.64 m).

I saw here that it's possible to push a video stream in the video tag from a file using the MediaSource object.

My idea is to read chunks of data from the websocket instead of a file. Can someone please post an example using websockets to accomplish that or explain me how to do it?

Thanks in advance.

like image 619
MastErAldo Avatar asked May 10 '13 16:05

MastErAldo


People also ask

Is WebSockets good for video streaming?

Thus we will observe that websocket proves to be a better option for video streaming over a traditional HTTP protocol. In normal HTTP protocol, first the client sends connection request, the server accepts it and connection is established. After communication the connection is closed.

Does WebRTC use WebSockets?

You need to signal the connection between the two browsers to connect a WebRTC data channel. To do this, you need them to communicate via a web server. This is achieved using a secure WebSocket or HTTPS.

Is WebSocket better than HTTP?

All the frequently updated applications used WebSocket because it is faster than HTTP Connection. When we do not want to retain a connection for a particular amount of time or reuse the connection for transmitting data; An HTTP connection is slower than WebSockets.

Is Node js good for WebSockets?

Node. js can maintain many hundreds of WebSockets connections simultaneously. WebSockets on the server can become complicated as the connection upgrade from HTTP to WebSockets requires handling. This is why developers commonly use a library to manage this for them.


1 Answers

In addition to the text (string) messages, the WebSocket API allows you to send binary data, which is especially useful to implement binary protocols. Such binary protocols can be standard Internet protocols typically layered on top of TCP, where the payload can be either a Blob or an ArrayBuffer.

// Send a Blob
var blob = new Blob("blob contents");
ws.send(blob);

// Send an ArrayBuffer
var a = new Uint8Array([8,6,7,5,3,0,9]);
ws.send(a.buffer);

Blob objects are particularly useful when combined with the JavaScript File API for sending and receiving files, mostly multimedia files, images, video, and audio.

Also i suggest to see WebRTC (Technology associated with WebSockets) Web Real-Time Communication (WebRTC) is another effort to enhance the communication capabilities of modern web browsers. WebRTC is peer-to-peer technology for the Web. The first applications for WebRTC are real-time voice and video chat. WebRTC is already a compelling new technology for media applications, and there are many available sample applications online that enable you to test this out with video and audio over the Web. Please check this link

like image 132
ShahRokh Avatar answered Sep 28 '22 09:09

ShahRokh