0

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
Paulo Galdo Sandoval
  • 2,173
  • 6
  • 27
  • 44
  • Have you checked if your buffer is full? I think it can only hold 150mb of data. If you deliver the entire video/audio at once it will causes the buffer to overflow. Instead add a pressure control in the stream and put a delay when sending frames. – Keyne Viana Dec 17 '17 at 10:40
  • @KeyneViana i wasn't streaming a large file, every try it took 10secs to stop and the maximum time achieved (just once) was 11min. – Paulo Galdo Sandoval Dec 17 '17 at 18:47

0 Answers0