Skip to content
Advertisement

Get data URL from video stream?

I have a video (webm) capture script that works fine. It records video then offers it as a download. The pertinent part of the code is this:

JavaScript

This works, as I say. However, the console says that passing media streams to URL.createObjectURL is deprecated, and I should use HTMLMediaElement srcObject instead.

So I changed it to:

JavaScript

…and although everything still works, I get the same warning.

Does anyone know how I can get a URL or blob data without this deprecated way?

I have also tried reading the src and currentSrc properties from the video element, but they come back empty where a stream is involved.

Advertisement

Answer

I am really surprised that your code did even work…

If stream is really a MediaStream, then the browser should not even know what size it would have to download, thus not when to stop downloading (it’s a stream).

MediaRecorder#ondataavailable will expose an Event with a data property filled with a chunk of the recorded MediaStream. In this event, you will have to store these chunks in an Array, and then you will download the concatenation of these Blobs chunks, usually in the MediaRecorder#onstop event.

JavaScript

URL.createObjectURL(MediaStream) was used for <video> elements. But this also led to some difficulties for browsers to close physical devices access, since BlobURLs can have a longer lifetime than the current document.
So it is now deprecated to call createObjectURL with a MediaStream, and one should use MediaElement.srcObject = MediaStream instead.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement