MaixCAM MaixPy Video Streaming WebRTC Push Streaming
2025-12-12
Update history
| Date | Version | Author | Update content |
|---|---|---|---|
| 2025-12-12 | 1.0.0 | 916BGAI | Initial documentation |
WebRTC streaming requires a browser that supports the WebRTC protocol. Please use the latest version of Chrome for testing.
Introduction
This document explains how to push camera video using WebRTC.
Usage
from maix import time, webrtc, camera, image
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
server = webrtc.WebRTC()
server.bind_camera(cam)
server.start()
print(server.get_url())
while True:
time.sleep(1)
Steps:
Import the
time,webrtc,camera, andimagemodulesfrom maix import time, webrtc, camera, imageInitialize the camera
# Initialize the camera with output resolution 640x480 and NV21 format cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)- Note: The WebRTC module currently only supports NV21 format, so the camera must be configured to output NV21.
Initialize and start the WebRTC server
server = webrtc.WebRTC() server.bind_camera(cam) server.start()server = webrtc.WebRTC()creates aWebRTCinstance.server.bind_camera(cam)binds aCamerainstance to the WebRTC server. After binding, the originalCameraobject should no longer be used directly.server.start()starts the WebRTC streaming service.
Print the WebRTC stream URL
print(server.get_url())server.get_url()returns the playback URL for the WebRTC stream.
Done — after running the script above, open the printed URL in your browser to view the camera stream.