Closed kolserdav closed 1 year ago
Today, in order to understand the reason, I simplified the task a little, but also expanded it to test other aspects. For example, two users are connected to the room, both have video broadcast turned on, then recording starts https://github.com/kolserdav/werift-sfu-react/blob/4db3fc3ce1235e9290c51543469b9b7d26be1ed7/packages/server/src/addons/recordVideo.ts#L234 , records a few seconds and stops https://github.com/kolserdav/werift-sfu-react/blob/4db3fc3ce1235e9290c51543469b9b7d26be1ed7/packages/server/src/addons/recordVideo.ts#L255 . As you can see, everything went well. After a while, without interrupting the current conference, we start recording again, but at this moment it no longer records correctly. It's as if the media recorders that worked with these media tracks made some changes to these media tracks, after which they can no longer be recorded until you re-create a new RTC connection with other media tracks.
I found the cause, but I don't know how to fix it yet. The point is that this listener is not cleared after the media recorder is stopped. I output this line https://github.com/shinyoshiaki/werift-webrtc/blob/39c9756f27151f3db773e6edb5fd49c3f84343a8/packages/webrtc/src/nonstandard/recorder/writer/webm.ts#L74 to the log, start and stop the recording, but the output to the log continues without stopping, although it would obviously be correct if it stopped its work after the recording stopped.
When using MediaRecord, I may need to periodically restart it on a per-client basis, depending on client events. For example, the client turned on video playback and then turned it off. Thus, when client video playback is enabled, MediaRecord records in resolution, for example, 640 480 to one video file, and when it is disabled, then 1 1 to another video file, this is necessary so that at the end of the recording these parts must be assembled into one video file.
Here is my example file, in this example it only records the stream of the user who started the recording https://github.com/kolserdav/werift-sfu-react/blob/48449ba25324de48d55138b01f0f89013d9f0ef5/packages/server/src/addons/recordVideo.ts#L179
Then, at some point in the recording, the user turns on/off their camera, the
onChangeVideoTrack
https://github.com/kolserdav/werift-sfu-react/blob/48449ba25324de48d55138b01f0f89013d9f0ef5/packages/server/src/addons/recordVideo.ts#L47 event fires. With this event, I try to stop the current MediaRecorder and create a new one on the same stream, but in a different file.Writing the first file is going great. But after stopping and starting to record another file from the same stream, the video never plays and has the icon as an unsupported video format.