I have a h.264 video stream that I am passing from the server (node.js) to the client (html, vanilla js) through a WebSocket. I have the raw h.264 console logging in the browser. I want to send that video stream to an html <video>
tag and have it display the video there in real time.
Server Side:
var wssV = new Server({ port: 3001 });
wssV.on("connection", function (ws) {
var videoPORT = 11111;//port Tello uses for video
var videoServer = dgram.createSocket('udp4');
videoServer.on('listening', function () {
var address = videoServer.address();
});
videoServer.on('message', function (message, remote) {
ws.send( message );//raw h.264 video stream sent to front end
});
videoServer.bind(videoPORT);
});
Client Side:
$(document).ready( function(){
var videoWebSocket = new WebSocket("ws://localhost:3001");
videoWebSocket.onerror = function(evt){console.log("ERROR:" + evt.data);};
videoWebSocket.onopen = function(evt) { console.log("Video Connection open ..."); };
videoWebSocket.onmessage = function(evt) {
console.log( evt.data );//raw h.264 encoded video stream
//HOW TO SEND THIS evt.data TO MY html video tag
};
videoWebSocket.onclose = function(evt) { console.log("Video Connection closed."); };
});
html:
<video id="videoPlayer">
<source src="" type="video/mp4" codec="accl.42E01E">
</video>
Questions:
- How do I attach the incoming video stream to the
<video>
tag? - What should the
src
andcodec
attribute values be set to? - Can I stream h.264 directly by setting a
codec
attribute?
If I am totally approaching this problem wrong then please help me find a way to display the h.264 video stream in the browser.