MediaStreamTrackProcessor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is only available in Dedicated Web Workers.

Warning: Browsers differ on which global context they expose this interface in (e.g., only window in some browsers and only dedicated worker in others), making them incompatible. Keep this in mind when comparing support.

The MediaStreamTrackProcessor interface of the Insertable Streams for MediaStreamTrack API consumes a video MediaStreamTrack object's source and generates a stream of VideoFrame objects.

Constructor

MediaStreamTrackProcessor()

Creates a new MediaStreamTrackProcessor object.

window.MediaStreamTrackProcessor()

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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
MediaStreamTrackProcessor
Chrome – Partial support
Chrome 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Edge – Partial support
Edge 94 (Release date: 2021-09-24)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 80 (Release date: 2021-10-05)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Chrome Android – Partial support
Chrome Android 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Partial support
Opera Android 66 (Release date: 2021-12-15)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
WebView Android – Partial support
WebView Android 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
WebView on iOS – Full support
WebView on iOS 18 (Release date: 2024-09-16)
footnote Full support
MediaStreamTrackProcessor() constructor
Chrome – Partial support
Chrome 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Edge – Partial support
Edge 94 (Release date: 2021-09-24)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 80 (Release date: 2021-10-05)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Chrome Android – Partial support
Chrome Android 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Partial support
Opera Android 66 (Release date: 2021-12-15)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
WebView Android – Partial support
WebView Android 94 (Release date: 2021-09-21)
footnote Partial support
footnote Exposed on Window instead of DedicatedWorker.
WebView on iOS – Full support
WebView on iOS 18 (Release date: 2024-09-16)
footnote Full support
readable
Chrome – Full support
Chrome 94 (Release date: 2021-09-21)
footnote Full support
Edge – Full support
Edge 94 (Release date: 2021-09-24)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 80 (Release date: 2021-10-05)
footnote Full support
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 94 (Release date: 2021-09-21)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 66 (Release date: 2021-12-15)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – Full support
WebView Android 94 (Release date: 2021-09-21)
footnote Full support
WebView on iOS – Full support
WebView on iOS 18 (Release date: 2024-09-16)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support

See also