-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MediaRecorder needs to define effect of adding / removing tracks in its input MediaStream #4
Comments
Somebody raised a use case on the Chrome launch bug to be able to switch video tracks in a single recording: https://code.google.com/p/chromium/issues/detail?id=261321#c62 I believe we should support the case where a stream have its tracks changing. From what I remember of our discussion at TPAC, this actually might happen without the app's action when using |
Chrome's CL [1] brought the question in the Title. Previous to #46, it seemed that a Track addition to/removal from a MediaStream being recorded should signal some error condition and stop the recording. The argument in said CL is that the JS should decide what to do, since the addition/removal might be desired, and even if it was not, it's unclear what the Application might deem appropriate: start recording the new track seamlessly, stop the recording altogether, stop and restart with the new Track... I propose not being dogmatic, signal to the App the condition and let it decide what to do -- in that line of reasoning, perhaps firing an Error when a Track is added/removed might also not be a good idea. What about a new @mreavy I don't see any firing/throwing being implemented in Gecko now [2], correct? [1] https://crrev.com/1578973002 |
@miguelao Correct, we don't fire anything on add/remove. I'm also thinking that even firing a mediastreammodified event won't have the utility you suggest -- since it may not be processed for a while, and in the meantime we need to continue recording. So by the time the app could react, the stream may already have recorded some of the new track (likely it will have). Unless we want to make some sort of synchronous blocking interface here (or force it to slice), I don't think this gains us much. (The app could independently watch the source via other means to know that tracks were added or removed.) |
If the app wants to control which tracks are recorded, it can create a MediaStream object and manually add tracks to it that it wants recorded. This is can all be done with existing APIs outside of the scope of this document, no need for adding any events. IMHO, the MediaRecorder should just record whatever is in the MediaStream instance. |
Resurrecting this; I'm trying to understand this behavior for some work I'm currently doing, and it's not entirely clear to me what should be correct here. Playing around with [1], I observed the following behavior in Chrome 51:
The default behavior I'd propose for all of this would be to follow suit with muting; I think if a track is muted, stopped or removed, then MediaRecorder should simply insert blank frames. If the track is unmuted or added again, start recording from it. One weird situation with adding a track is if something starts as audio-only/video-only, and then someone later adds a video/audio track. Handling that situation might be challenging for implementations, since most media containers will not handle this well. One option for this might be if someone specifies a mime type that contains both audio and video (e.g. [1] https://webrtc.github.io/samples/src/content/getusermedia/record/ |
I suppose the ability to use a |
I lied: the canvas feature does not appear to help because the canvas isn't active when it isn't visible. Darn. |
Regarding the canvas not capturing if not visible, that sounds like a Chrome implementation bug. The Media Capture from DOM Elements spec doesn't say anything about the need for the element to be active. Anyway, regarding the manipulation of tracks for a Now I'm not sure if adding and removing tracks in the middle of a recording is supported by the webm container, so maybe we can pre-provision the container using a hint in the mimeType like @jnoring suggests? This does sound a bit hackish though, and doesn't solve the use case of recording a media stream captured from a VideoElement that has tracks getting added and removed outside of the app's control. |
@mhofman I agree, the canvas thing seems like it's probably an implementation bug. I don't quite follow you when you say "I do believe it should just record any tracks in the stream, whether they are added / removed in the middle of recording." Do you mean if I start with two tracks and remove one track midway through, it should continue recording the removed track? Chrome does indeed behave this way, and that feels like a bug to me: I'd expect a removed track to no longer record. |
No it should add / remove track from the output when the media stream changes, mirroring everything. Chrome continuing to record a removed track sounds like a bug too. At the very least it should mute that track in the output. |
Got it--I agree. Was just making sure I understood what you were saying. In my ideal world, |
The spec reads as an error when the number of tracks changes (https://w3c.github.io/mediacapture-record/MediaRecorder.html#event-summary):
and that's also the behaviour in Chrome. |
I think we should define how to gracefully (not aborting or ignoring) handle track set changes, or change the API to take MediaStreamTracks instead. |
@Pehrsons I think we are saying the same thing, i.e. what you propose is equivalent to making MR take a "snapshot" of the MediaStream's Tracks at construction time, but a Alternatively, we could remove the |
@miguelao I think that goes semantically against the API. You hand it a MediaStream so you expect it to be able to handle it. Otherwise the API should take an array of tracks, as that is really nothing more than "a bag of tracks" (and it doesn't solve issues like the one below). I have been hinting in a couple of places about making blobs individually playable MSE-style, as I see that solving a number of issues, including handling track changes gracefully as the most prominent one. The reason I keep pushing for it is that I haven't heard any good arguments against it. If you have some I'd love to hear them. Take for example an api that gives you a MediaStream, that inherently from that api will change its track set. A good candidate for this is media element capture, [1]. That api gives you a MediaStream, and if the application changes the selected VideoTrack, the one VideoStreamTrack in that MediaStream will be replaced with a new one. This is painfully difficult to record. You could record all tracks separately and remux on a server somewhere, but then you need to solve syncing. You could record audio and video together and start a new recording whenever there's a track set change, then stitch it together in a remuxing step afterwards. However if video changes, that results in a gap in audio. And so on. We need something better. [1] https://w3c.github.io/mediacapture-fromelement/#html-media-element-media-capture-extensions |
I have naive recording needs, so I don't consider myself a stakeholder here. However, I'm biased against "What should happen?" issues. I'm a fan of use-cases driving functionality, not the other way around. We also seem to be talking about at least two things:
On the first point, RTCPeerConnection switched from But even if we were to pivot to tracks in MediaRecorder, I'd have the same questions about what kinds of modification functionality we desire. |
Why cannot Currently the behaviour is that For example
the |
Similarly, if we set the |
@jnoring @Pehrsons Using The could possibly be a flag included at |
Can the participants summarize their points of view on what the next steps are? |
@aboba FWIW From perspective here tracks added to a One use case is recording multiple media fragments with a single instance of The above is possible at Firefox using multiple However, trying to capture and recorder a |
I still think we need a way to support changes to the track set, since there's no way to plug video tracks in and out under a video track at will, like you can with web audio for audio tracks. The simplest use case showing that this is needed is recording a captured video element like @guest271314 mentions, since that wouldn't survive a change of The best proposal (clearly I'm biased, but I don't recall seeing any other proposals either) I've seen for fixing this is defining a mode for individually playable chunks [1][2][3], as this would make the track problem an MSE problem (where changing the track set is permitted AIUI). I.e., on a track set change you'd finish the existing chunk and start gathering into a new chunk. It would also fix #119 natively, and #67, in the process. If there was a way to plug video tracks like I mentioned in the beginning, I could live without supporting track set changes. The only way currently is canvas capture but it has major drawbacks such as running on main thread, not staying in sync with audio, not rendering in background tabs or when hidden, etc. FWIW I think individually playable chunks could still be worthwhile just for the sake of #119 and #67. As for a next step.. get the discussion going to see where people stand? [1] #67 (comment) |
@Pehrsons Am still not sure how the tab crash at Chromium will get printed at test results page, though the test at web-platform-tests/wpt#15816 (comment) is applicable to https://github.com/web-platform-tests/wpt/tree/master/mediacapture-fromelement, https://github.com/web-platform-tests/wpt/tree/master/media-source, and https://github.com/web-platform-tests/wpt/tree/master/mediacapture-record. How to create a pull request which adds the test to each of the relevant wpt directories? |
@Pehrsons #166. Technically concatenating recorded video is possible using If more than one
the Else, if such a proposal would conflict with the original scope of |
@Pehrsons In an attempt to create a version of https://github.com/guest271314/MediaFragmentRecorder which outputs the same result at both Mozilla Firefox and Chromium/Chrome substituted using However, the code now outputs the roughly the expected result at Chromium/Chrome (save for audio clipping) though not at Mozilla Firefox, where the video does not contain all captured images, video playback stalls, and the audio has gaps. Encountered this issue once before though unfortunately no longer have access to the OS where ran and saved the tests. If you find the time, for interop, can you run the code at both Chromium/Chrome and Mozilla Firefox and provide any feedback as to what the issue could be?
|
@Pehrsons Found a previous version of the above code https://bugs.chromium.org/p/chromium/issues/attachmentText?aid=328544 from previous experiments at this Chromium bug Issue 820489: Capturing MediaStream from HTMLMediaElement where src is set to MediaSource crashes tab https://bugs.chromium.org/p/chromium/issues/detail?id=820489. Essentially the same issue that occurs at the above code. Audio and video are not rendered correctly (1:1 output). |
@Pehrsons Finally composed two versions of code that records multiple videos in sequence using a single of each The one issue is that Mozilla Firefox does not output the final 1 second of the last recorded audio. Searched https://bugzilla.mozilla.org though could not find any similar issue. Can post the code here or at a bug report if that would be a more appropriate venue. Do you have any idea why the last 1 second of audio is not output at the resulting |
@Pehrsons Re #4 (comment) the code https://github.com/guest271314/MediaFragmentRecorder/blob/canvas-webaudio/MediaFragmentRecorder.html plnkr https://plnkr.co/edit/WaAn8v6vjn3j65RoTNs2?p=preview. Not sure how to describe the issue/bug, and not certain if the problem is caused by |
@guest271314 this is not the right venue for discussing implementation bugs. Please file a bug at our bugzilla if you see unexpected things in Firefox, and we'll take a look. |
Composed code that utilizes The functionality of |
Interestingly, the |
I think this issue needs to close. The behavior on track change is well defined (recording stops), new issues can propose changing it. |
Shijun Sun 2014-05-20 20:13:29 UTC
The "stream" attribute on the MediaRecorder is readonly, but it seems the spec does not prevent the app from dynamically adding/removing tracks from the stream object.
If the intention of defining the attribute as readonly is to block dynamic changes to the stream object, it will be better to define a getStream() method to return a copy of the internal MediaStream object.
Comment 1 Adam Bergkvist 2014-05-21 13:01:40 UTC
The readonly only prevents the script from assigning the attribute to an entirely new MediaStream. Returning a copy with getStream() wouldn't help since you can still have the reference to the stream you passed in to the MediaRecorder() constructor. To prevent this, we would have to have a "readonly mode" for the stream. I'm not sure we want/need that.
Comment 2 Martin Thomson 2014-05-21 15:24:12 UTC
The point here is that we need some sort of rules for handling the cases where tracks are added and removed from a stream that is in active use.
Comment 3 Harald Alvestrand 2014-06-13 08:41:18 UTC
Changing the subject of the bug to say what it's about (based on discussion).
The alternative would be to close as WONTFIX/WAI.
The text was updated successfully, but these errors were encountered: