Track generators
Tracks of media the application writes, with VideoTrackGenerator and the non-standard MediaStreamTrackGenerator.
- class webrtc.interfaces.track_generator.VideoTrackGenerator
A video track of the frames the application writes to a stream.
The visible rect of each
webrtc.VideoFramewritten is sent ontrack, and the frame is closed. Writing anything else or a closed frame errorswritable. Closing or abortingwritableends the track.Example:
generator = webrtc.VideoTrackGenerator() pc.add_track(generator.track) writer = generator.writable.get_writer() init = webrtc.VideoFrameBufferInit(format='I420', coded_width=640, coded_height=480, timestamp=0) await writer.write(webrtc.VideoFrame(i420, init))- property track: MediaStreamTrack
The video track carrying the frames written.
See MDN: VideoTrackGenerator/track.
- Type:
- property writable: WritableStream
The stream to write
webrtc.VideoFrameobjects to.See MDN: VideoTrackGenerator/writable.
- Type:
- class webrtc.interfaces.track_generator.MediaStreamTrackGeneratorInit(kind)
The options of a
MediaStreamTrackGenerator.- Parameters:
kind (
webrtc.MediaType) โ The kind of the track,'audio'or'video'.
- class webrtc.interfaces.track_generator.MediaStreamTrackGenerator(kind)
A track of the
webrtc.VideoFrameorwebrtc.AudioDataobjects the application writes to a stream.Itโs non-standard, but itโs the only way to generate audio. For video,
VideoTrackGeneratoris the standard choice. UnlikeVideoTrackGenerator, this generator is the track itself.Each object written is sent and closed. Audio is converted to 16-bit samples and sent in 10 ms frames. Samples that donโt fill a frame wait for the next write. Writing the wrong kind of object or a closed one errors
writable. So does a sample rate the library canโt send, withwebrtc.NotSupportedError. Closing or abortingwritableends the track.See MDN: MediaStreamTrackGenerator.
- Parameters:
kind (
webrtc.MediaType,strorMediaStreamTrackGeneratorInit) โ'audio'or'video', or an init that holds it.- Raises:
TypeError โ If the kind isnโt audio or video.
Events
Handlers are registered with
on().- property writable: WritableStream
The stream to write
webrtc.VideoFrameorwebrtc.AudioDatato.See MDN: MediaStreamTrackGenerator/writable.
- Type: