rtsp — rtsp library¶
The rtsp module on the OpenMV Cam allows you to stream video from your OpenMV Cam to any
compatible RTSP client (like VLC).
Example:
import network
import rtsp
import csi
import time
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("your-ssid", "your-password")
while not wlan.isconnected():
time.sleep_ms(100)
server = rtsp.rtsp_server(wlan)
# Called each time the server needs a new frame to send.
def image_callback(pathname, session):
return csi0.snapshot()
# Does not return; streams to any RTSP client that connects.
server.stream(image_callback, quality=70)
Connect a client to rtsp://<camera-ip>:554/ to view the stream.
class rtsp_server – rtsp_server class¶
The rtsp_server class creates a single connection RTSP web server on your OpenMV Cam.
- class rtsp.rtsp_server(network_if: Any, port: int = 554)¶
Creates an RTSP server bound to
network_if.network_ifis the network module interface created fromnetwork.LAN(),network.WLAN(), or similar.portis the TCP port to listen on. The default RTSP port is 554.- register_setup_cb(cb: Callable[[str, int], None]) None¶
Bind a callback
cbto be invoked when a client sets up an RTSP connection.The callback receives
pathname(the requested stream resource path, defaults to"/") andsession(a random session id).
- register_play_cb(cb: Callable[[str, int], None]) None¶
Bind a callback
cbto be invoked when a client starts streaming.The callback receives
pathnameandsessionas described inregister_setup_cb().
- register_pause_cb(cb: Callable[[str, int], None]) None¶
Bind a callback
cbto be invoked when a client pauses streaming.Note: VLC’s pause button does not actually notify the server.
The callback receives
pathnameandsessionas described inregister_setup_cb().
- register_teardown_cb(cb: Callable[[str, int], None]) None¶
Bind a callback
cbto be invoked when a client tears down the RTSP connection.The callback receives
pathnameandsessionas described inregister_setup_cb().
- stream(image_callback: Callable[[str, int], image.Image], quality: int = 90) None¶
Starts running the
rtsp_serverlogic and does not return.image_callbackis invoked to produce each frame and must return animage.Imageobject. It receivespathnameandsessionas described inrtsp_server.register_setup_cb().qualityis the JPEG compression quality used while streaming.