i'm trying to stream a rtsp live stream through socket.io
using ffmpeg
(this works fine), but now i need to get that video from the socket and play it on a HTML5 video tag.
To do this i'm using MediaSurce
, getting small pieces of video through the socket and then appending it to the MediaSource
This solution reproduces the video a few seconds o minutes and then suddenly stops
and it doesn't throw me any error on the Chrome console
var socket = io();
var ms = new MediaSource();
var sourceBuffer;
var queue = [];
var video = document.getElementById("video");
video.src = window.URL.createObjectURL(ms);
socket.on('start', function (response) {
console.log(response);
socket.emit('streaming', $stateParams.id);
ms.addEventListener('sourceopen', videoLoad, false);
ms.addEventListener('sourceclose', videoClosed, false);
});
function videoLoad() {
sourceBuffer = ms.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
sourceBuffer.addEventListener('update', function () {
if (queue.length > 0 && !sourceBuffer.updating) {
console.log(queue.length);
sourceBuffer.appendBuffer(queue.shift());
}
});
socket.on('data', function (response) {
var bytes = new Uint8Array(response);
var blob = new Blob(bytes);
console.log(blob.size);
if (sourceBuffer.updating || queue.length > 0) {
queue.push(bytes);
} else {
sourceBuffer.appendBuffer(bytes);
}
});
}
function videoClosed(e) {
console.log('mediaSource readyState: ' + this.readyState);
}
On my chrome://media-internals/
the video players log show me a couple of time this, and then the video stops
video_buffering_state BUFFERING_HAVE_ENOUGH