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:
track (
webrtc.MediaStreamTrack) โ The track to read.max_buffer_size (
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โsDEFAULT_VIDEO_BUFFER_SIZEorDEFAULT_AUDIO_BUFFER_SIZE.
- class webrtc.interfaces.media_stream_track_processor.MediaStreamTrackProcessor(init)
Reads the media of a track as a stream.
readablegiveswebrtc.VideoFrameobjects for a video track andwebrtc.AudioDataobjects of 10 ms each for an audio track. Media is queued as it arrives, up tomax_buffer_sizeitems. When the queue is full, the oldest item is dropped and counted indiscarded_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:
- 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:
- property discarded_frames: int
How many of
total_frameswere dropped unread because the queue was full.See MDN: MediaStreamTrackProcessor/discardedFrames.
- Type: