Open chrisguttandin opened 11 months ago
Interesting demo! I'm surprised duration / timestamp aren't respected though MediaRecorder does a bunch of timestamp rewriting for various reasons, can you file a bug at https://crbug.com/new and I can route to the right folks to take a look?
As you've found MSTG -> MediaRecorder is indeed possible. The only downside is that you can't control encoding parameters or segmentation as precisely as one might like. Maybe that's okay though.
I was curious if this could be achieved by using a
MediaStreamTrackGenerator
. I build a little demo for it.https://stackblitz.com/edit/js-1jfqfv?file=index.js,index.html
It uses a canvas to render red and green rectangles which get then converted into
VideoFrame
s and fed into thewritabe
of aMediaStreamTrackGenerator
. It almost works.The problem is that the
MediaStreamTrackGenerator
doesn't seem to respect theduration
and thetimestamp
of aVideoFrame
. I'm not sure if this is a bug or if that's intentional. If it would respect that one could generate and "record" aMediaStream
using theMediaRecorder
at least in real time.I know that it's already possible to use
captureStream()
on a canvas to achieve a similar thing. The problem with that solution however is that the timing is unreliable. Being able to craftVideoFrame
s with a preciseduration
andtimestamp
would solve this problem.Maybe this idea could even be expanded to support faster than realtime rendering.