Re: Blobs and MediaStreams (Re: getUserMedia API: How to use the LocalMediaStream object ?)

On Tue, Mar 6, 2012 at 3:44 PM, Randell Jesup <randell-ietf@jesup.org>wrote:

> So we need "something" to transform blobs into mediastreams (and the same
> principle would apply for recordings, at least of data from a camera/mic or
> decoded remote data).
>
> There are a few ways to deal with this:
>  1) self-identifying streams and a 'smart' decoder
>  2) out-of-band information as to the encoding (i.e. specified by the app
> directly or indirectly)
>
> Streams on the web typically are handled by out-of-band information (MIME
> types), so any solution we make should at least support that, and perhaps
> even use that as the primary solution.
>

A Blob object already has a MIME type along with the data. There is no
problem here.

I suppose (noodling without really knowing what I'm talking about ;-) ) you
> could have a disconnected <video> or <audio> element with a blob as a
> source with a mime type supplied, and add a 'dest' or 'output' attribute
> which would be a MediaStream.  This might even make sense... And you'd have
> an obvious way to do things like provide initial scaling of the video, or
> insertion of subtitles, etc.  Hmmm.
>
> I do want to get away from URL.createObjectURL(**MediaStream) for setting
> the src for a <video> element, and I think there's a bigger opportunity
> here to unify media handling in a way that will make future work easier.
>

The MediaStreams Processing spec extends media elements' "src" attribute so
you can set it directly to a MediaStream: "video.src = stream;". I've
implemented that in my patches. It also adds an API to capture a
MediaStream from a media element, e.g. "stream =
video.captureStreamUntilEnded()".

It would also make sense to extend the "src" attribute to directly accept
Blob objects as well. The behavior is just like assigning to the result of
createObjectURL, except it has better GC behavior since you don't have to
manually revoke the URL.

Then you could do, e.g.,
  var video = document.createElement("video");
  video.src = blob;
  var stream = video.captureStreamUntilEnded();
  video.play();

Rob
-- 
“You have heard that it was said, ‘Love your neighbor and hate your enemy.’
But I tell you, love your enemies and pray for those who persecute you,
that you may be children of your Father in heaven. ... If you love those
who love you, what reward will you get? Are not even the tax collectors
doing that? And if you greet only your own people, what are you doing more
than others?" [Matthew 5:43-47]

Received on Tuesday, 6 March 2012 23:21:31 UTC