Reputation: 1155
here is my node js code
socket.on('stream',()=>{
let readStream = fs.createReadStream(__dirname+'/video.mp4');
readStream.on('data',(chunk)=>{
socket.emit('stream-chunk',chunk);
//res.render("hello");
});
});
and here is the client side
let chunkArray = [];
socket.on('stream-chunk', (chunk) => {
chunkArray.push(chunk);
//console.log(chunk);
//var url = URL.createObjectURL(chunk);
//alert(url);
$("#video").attr("src",url);
});
so as you can see I just want to get a video file from node server and stream it using buffers.. so far the chunks come as ArrayBuffers to client side. But I have no idea how to make use this incoming chunks to my html5 <video>
element
here is my client side html tag
<video controls type="video/mp4" src="" id="video" width="300" height="300"></video>
Upvotes: 0
Views: 3737
Reputation: 2203
This is my full ground-up example implementation using NodeJS and FFmpeg to handle HTTP Live Streams HLS + m3u8 i.e. VOD. Check it
https://github.com/pluginfactory/HLS-transcoding-nodejs
Upvotes: 1
Reputation: 163232
Just use HTTP straight-up. No need to use web sockets for one-way communication.
Use Express to serve that file statically. Then in your video tag, src="path/video.mp4"
.
Upvotes: 3