I am capturing video from a chrome tab and piping it to a transformer:
const options = {
video: {
width: window.innerWidth,
height: window.innerHeight
}
};
const stream = await navigator.mediaDevices.getDisplayMedia(options);
const videoTrack = stream.getVideoTracks()[0];
const trackProcessor = new MediaStreamTrackProcessor({ track: videoTrack });
const trackGenerator = new MediaStreamTrackGenerator({ kind: 'video' });
const transformer = new TransformStream({
transform(videoFrame, controller) {
controller.enqueue(videoFrame);
}
});
trackProcessor.readable.pipeThrough(transformer).pipeTo(trackGenerator.writable);
const streamAfter = new MediaStream([trackGenerator]);
const mediaRecorder = new MediaRecorder(streamAfter);
mediaRecorder.start();
setTimeout(() => {
mediaRecorder.stop();
streamAfter.getTracks().forEach(track => track.stop());
// At this stage I get errors
}, 5000);
After stopping the video tracks, I get the following error:
Uncaught (in promise) DOMException: Failed to execute 'write' on 'UnderlyingSinkBase': Stream closed
A VideoFrame was garbage collected without being closed. Applications should call close() on frames when done with them to prevent stalls.
What is the proper way to inform the transformer that the input stream is closed so that it doesn't attempt to write to the output? How to handle this situation?