MediaStreamTrackProcessor - Web APIs | MDN

Constructor

MediaStreamTrackProcessor()

Creates a new MediaStreamTrackProcessor object.

window.MediaStreamTrackProcessor() Experimental Non-standard

Creates a new MediaStreamTrackProcessor object on the main thread that can process both video and audio.

Instance properties

MediaStreamTrackProcessor.readable

Returns a ReadableStream.

Examples

The following example is from the article Unbundling MediaStreamTrackProcessor and VideoTrackGenerator. It transfers a camera MediaStreamTrack to a worker for processing. The worker creates a pipeline that applies a sepia tone filter to the video frames and mirrors them. The pipeline culminates in a VideoTrackGenerator whose MediaStreamTrack is transferred back and played. The media now flows in real time through the transform off the main thread.

js

const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const [track] = stream.getVideoTracks();
const worker = new Worker("worker.js");
worker.postMessage({ track }, [track]);
const { data } = await new Promise((r) => {
  worker.onmessage = r;
});
video.srcObject = new MediaStream([data.track]);

worker.js:

js

onmessage = async ({ data: { track } }) => {
  const vtg = new VideoTrackGenerator();
  self.postMessage({ track: vtg.track }, [vtg.track]);
  const { readable } = new MediaStreamTrackProcessor({ track });
  await readable
    .pipeThrough(new TransformStream({ transform }))
    .pipeTo(vtg.writable);
};

Specifications

Specification
MediaStreamTrack Insertable Media Processing using Streams
# mediastreamtrackprocessor

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.