I am trying to apply some transformations on the video frames of an ended MediaStreamTrack
. I tried using the MediaStreamTrack Insertable Media Processing using Streams API:
const stream = await navigator.mediaDevices.getDisplayMedia({ video: true });
stream.addEventListener(streamEndedEvent, async () => {
const videoTrack = stream.getVideoTracks()[0];
const trackProcessor = new MediaStreamTrackProcessor({ track: videoTrack });
const trackGenerator = new MediaStreamTrackGenerator({ kind: 'video' });
const transformer = new TransformStream({
async transform(videoFrame, controller) {
const newFrame = await transform(videoFrame);
videoFrame.close();
controller.enqueue(newFrame);
}
});
trackProcessor.readable.pipeThrough(transformer).pipeTo(trackGenerator.writable);
// use the transformed stream here
});
I am getting an error when trying to construct the MediaStreamTrackProcessor
object:
Uncaught (in promise) TypeError: Failed to construct 'MediaStreamTrackProcessor': Input track cannot be ended
If MediaStreamTrackProcessor
cannot be used, is there some other API that would allow me to parse the constituent frames of a MediaStream, apply some transformation on them and create a new stream?