Stream Ingestion | Python
Stream Ingestion in VideoSDK Meeting allows capturing or processing streams from custom audio/video inputs. You can ingest streams from various custom audio/video sources such as files, HTTP streams, or buffers.
Understanding MediaPlayer
MediaPlayer
is a component provided by the vsaiortc
library for handling media streams in WebRTC applications. It enables capturing or processing streams from custom audio and video inputs, like files, HTTP streams, or buffers.
How MediaPlayer Works
- Initialization: Initialize a
MediaPlayer
instance with a source URL or file path, specifying the type of media input. - Stream Handling: The
MediaPlayer
decodes the media stream, making it accessible for further processing or transmission. - Integration: Use
MediaPlayer
to feed media streams into a VideoSDK meeting, allowing participants to view or hear the ingested content.
Basic Stream Ingestion
import asyncio
from videosdk import MeetingConfig, VideoSDK
from vsaiortc.contrib.media import MediaPlayer
VIDEOSDK_TOKEN = "<TOKEN>"
MEETING_ID = "<MEETING_ID>"
NAME = "<NAME>"
loop = asyncio.get_event_loop()
def main():
# Open a video file.
player = MediaPlayer("./example.mp4")
# Open an HTTP stream.
# player = MediaPlayer('http://example.com/video.mp4')
# Open webcam on Linux.
# player = MediaPlayer('/dev/video0', format='v4l2', options={'video_size': '640x480'})
# Open webcam on OS X.
# player = MediaPlayer('default:none', format='avfoundation', options={'video_size': '640x480'})
# Open webcam on Windows.
# player = MediaPlayer('video=Integrated Camera', format='dshow', options={'video_size': '640x480'})
# Pass track to meeting
meeting_config = MeetingConfig(
meeting_id=MEETING_ID,
name=NAME,
mic_enabled=True,
webcam_enabled=True,
token=VIDEOSDK_TOKEN,
custom_camera_video_track=player.video,
custom_microphone_audio_track=player.audio,
)
meeting = VideoSDK.init_meeting(**meeting_config)
meeting.join()
print("Joined the meeting...")
if __name__ == "__main__":
main()
loop.run_forever()
Using enable_mic()
Method
You can pass the MediaPlayer
audio track to the enable_mic()
method.
Example
import asyncio
from videosdk import MeetingConfig, VideoSDK
from vsaiortc.contrib.media import MediaPlayer
VIDEOSDK_TOKEN = "<TOKEN>"
MEETING_ID = "<MEETING_ID>"
NAME = "<NAME>"
loop = asyncio.get_event_loop()
async def main():
# Open a video file.
player = MediaPlayer("./example.mp4")
# Pass track to meeting
meeting_config = MeetingConfig(
meeting_id=MEETING_ID,
name=NAME,
token=VIDEOSDK_TOKEN
)
meeting = VideoSDK.init_meeting(**meeting_config)
print("Joining the meeting...")
await meeting.async_join()
print("Starting player audio...")
meeting.enable_mic(track=player.audio)
if __name__ == "__main__":
loop.run_until_complete(main())
loop.run_forever()
Using enable_webcam()
Method
You can pass the MediaPlayer
video track to the enable_webcam()
method.
Example
import asyncio
from videosdk import MeetingConfig, VideoSDK
from vsaiortc.contrib.media import MediaPlayer
VIDEOSDK_TOKEN = "<TOKEN>"
MEETING_ID = "<MEETING_ID>"
NAME = "<NAME>"
loop = asyncio.get_event_loop()
async def main():
# Open a video file.
player = MediaPlayer("./example.mp4")
# Pass track to meeting
meeting_config = MeetingConfig(
meeting_id=MEETING_ID,
name=NAME,
token=VIDEOSDK_TOKEN
)
meeting = VideoSDK.init_meeting(**meeting_config)
print("Joining the meeting...")
await meeting.async_join()
print("Starting player video...")
meeting.enable_webcam(track=player.video)
if __name__ == "__main__":
loop.run_until_complete(main())
loop.run_forever()
Output
API Reference
Refer to the following API documentation for methods and events used in this guide:
Got a Question? Ask us on discord