Search code examples
javascriptvideo-streaminghtml5-videowebrtcmedia-source

Creating MediaStream Object in Chrome?


As far as I know the MediaStream object is return from getUserMedia but is there a way to create a MediaStream object from a local .mp4 or .webm file? (or any other hack-ish way)

Looking into this to in an attempt to automate some testing that's pretty specific to need this.

Edit: This is Chrome specific. There's currently a canvas operation in Firefox that does what I would need but it's not on Chrome (yet?)

Edit 2: This is what is used for Firefox https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream

Is there anything equivalent for Chrome? or is there really no way to re-create a MediaSteam object some other way . . .

Right now the only thing I can think of is to use this on Firefox for a webrtc peerconnection to send it over to a chrome peerconnection and hope that stream received is valid.


Solution

  • According to Media Capture from DOM Elements, there are two methods, captureStreamUntilEnded and captureStream that should work on both HTML media elements(audio and video) and the HTML canvas element.

    Like you said, firefox has been supporting capturing canvas for some time, but unfortunately for chrome, it is still work in progress, you could star the issue and follow for updates.