# MediaStreamTrackProcessor

MediaStreamTrackProcessor, which reads the media of a track as a readable stream.

### webrtc.interfaces.media_stream_track_processor.DEFAULT_VIDEO_BUFFER_SIZE *= 1*

How many video frames are queued for reads by default, as set by the specification

### webrtc.interfaces.media_stream_track_processor.DEFAULT_AUDIO_BUFFER_SIZE *= 10*

How many 10 ms chunks of audio are queued for reads by default, which makes 100 ms in all

### *class* webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessorInit(track, max_buffer_size=None)

The options of a [`MediaStreamTrackProcessor`](#webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor).

* **Parameters:**
  * **track** ([`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack)) – The track to read.
  * **max_buffer_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – How many items are queued before the oldest one is dropped. It
    ranges from 0 to 65535, and 0 is treated as 1. If unset, it’s [`DEFAULT_VIDEO_BUFFER_SIZE`](#webrtc.interfaces.media_stream_track_processor.DEFAULT_VIDEO_BUFFER_SIZE) or
    [`DEFAULT_AUDIO_BUFFER_SIZE`](#webrtc.interfaces.media_stream_track_processor.DEFAULT_AUDIO_BUFFER_SIZE).

### *class* webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor(init)

Reads the media of a track as a stream.

[`readable`](#webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor.readable) gives [`webrtc.VideoFrame`](../models/video_frame.md#webrtc.models.video_frame.VideoFrame) objects for a video track and [`webrtc.AudioData`](../models/audio_data.md#webrtc.models.audio_data.AudioData) objects
of 10 ms each for an audio track. Media is queued as it arrives, up to `max_buffer_size` items. When the
queue is full, the oldest item is dropped and counted in [`discarded_frames`](#webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor.discarded_frames), so a slow reader never makes
memory grow. The stream closes when the track ends. Close each frame you read once you’re done with it.

See [MDN: MediaStreamTrackProcessor](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackProcessor).

* **Parameters:**
  **init** ([`MediaStreamTrackProcessorInit`](#webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessorInit)) – The track to read and how many items are queued. By
  default that’s 1 frame of video or 10 chunks of audio.
* **Raises:**
  [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the size isn’t an integer from 0 to 65535.

Example:

```default
processor = webrtc.MediaStreamTrackProcessor(webrtc.MediaStreamTrackProcessorInit(track))
async for frame in processor.readable:
    ...
    frame.close()
```

#### *property* readable *: [ReadableStream](../streams.md#webrtc.streams.ReadableStream)[[VideoFrame](../models/video_frame.md#webrtc.models.video_frame.VideoFrame) | [AudioData](../models/audio_data.md#webrtc.models.audio_data.AudioData)]*

The media of the track. It closes once the track ends.

Canceling it makes the processor stop reading the track.

See [MDN: MediaStreamTrackProcessor/readable](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackProcessor/readable).

* **Type:**
  [`webrtc.ReadableStream`](../streams.md#webrtc.streams.ReadableStream)

#### *property* total_frames *: [int](https://docs.python.org/3/builtins/functions.html#int)*

How many frames or chunks of audio the track delivered to the processor, read or not.

See [MDN: MediaStreamTrackProcessor/totalFrames](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackProcessor/totalFrames).

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

#### *property* discarded_frames *: [int](https://docs.python.org/3/builtins/functions.html#int)*

How many of [`total_frames`](#webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor.total_frames) were dropped unread because the queue was full.

See [MDN: MediaStreamTrackProcessor/discardedFrames](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackProcessor/discardedFrames).

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)
