Larry
Larry

Reputation: 1765

Javascript - buffer video from blobs source?

Context:

Fiddling with javascript.

Html5 browser.

Question:

Is it possible to have, say, two video blobs and buffer their content in a video tag and play them smoothly without concatenating them at first ?

The underlying is : is it possible to dynamically add data to the video buffer in javascript in the browsers at any moment (the video may have already started to play and we still add data from a blob after that)?

All the solutions seems to need the whole data at the beginning.

Upvotes: 2

Views: 2432

Answers (1)

Antonin M.
Antonin M.

Reputation: 1784

There is the Media Source API which is, unfortunately, only available on Chrome. AFAIK it only works with webm container and vorbis and vp8 codecs.

var ms = new MediaSource();

var video = document.querySelector('video');
video.src = window.URL.createObjectURL(ms);

ms.addEventListener('sourceopen', function(e) {
    ...
    var sourceBuffer = ms.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
    sourceBuffer.appendBuffer(oneVideoWebMChunk);
    ....
}, false);

Here is a little demo

W3C draft

Upvotes: 1

Related Questions