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.

Parameters:
class webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor(init)

Reads the media of a track as a stream.

readable gives webrtc.VideoFrame objects for a video track and webrtc.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, 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.

Parameters:

init (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 โ€“ If the size isnโ€™t an integer from 0 to 65535.

Example:

processor = webrtc.MediaStreamTrackProcessor(webrtc.MediaStreamTrackProcessorInit(track))
async for frame in processor.readable:
    ...
    frame.close()
property readable: ReadableStream[VideoFrame | 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.

Type:

webrtc.ReadableStream

property total_frames: int

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

See MDN: MediaStreamTrackProcessor/totalFrames.

Type:

int

property discarded_frames: int

How many of total_frames were dropped unread because the queue was full.

See MDN: MediaStreamTrackProcessor/discardedFrames.

Type:

int