Track - Python
Introduction
The Track
classes in the Video SDK provide a way to handle media streams, specifically video and audio tracks. The CustomVideoTrack
and CustomAudioTrack
classes are dummy implementations that generate green video frames and silent audio frames, respectively. These can be subclassed to create more useful implementations tailored to specific use cases.
Track Properties
CustomVideoTrack
- kind: str
- Type of media, in this case, "video".
- _start: float
- Timestamp indicating when the track started.
- _timestamp: int
- The current timestamp of the track.
CustomAudioTrack
- kind: str
- Type of media, in this case, "audio".
- _start: float
- Timestamp indicating when the track started.
- _timestamp: int
- The current timestamp of the track.
Track Methods
CustomVideoTrack Methods
async recv() -> Frame
Receives the next VideoFrame
, which is a green frame with a resolution of 640x480 pixels at 30fps.
- Returns:
Frame
: The next video frame.
CustomAudioTrack Methods
async recv() -> Frame
Receives the next AudioFrame
, which is a silent audio frame.
- Returns:
Frame
: The next audio frame.
Example Usage
Here's an example of how you might subclass CustomVideoTrack
to create a custom video track:
class MyCustomVideoTrack(CustomVideoTrack):
async def recv(self) -> Frame:
# Your custom implementation here
pass
And similarly, for the audio track:
class MyCustomAudioTrack(CustomAudioTrack):
async def recv(self) -> Frame:
# Your custom implementation here
pass
Conclusion
The Track
classes in the Video SDK are designed to provide a flexible and extensible way to handle media streams in your applications. By subclassing CustomVideoTrack
and CustomAudioTrack
, you can create custom implementations tailored to your specific needs.
Implementation Guide
Got a Question? Ask us on discord