SpiriBase-Deploy/rtsp_server.py

36 lines
1.1 KiB
Python

#!/usr/bin/env python3
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GObject
class CustomRTSPMediaFactory(GstRtspServer.RTSPMediaFactory):
def __init__(self):
super(CustomRTSPMediaFactory, self).__init__()
self.set_shared(True)
def do_create_element(self, url):
pipeline = (
'udpsrc port=5600 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! '
'rtph264depay ! h264parse ! rtph264pay name=pay0 pt=96'
)
return Gst.parse_launch(pipeline)
class CustomRTSPServer(GstRtspServer.RTSPServer):
def __init__(self):
super(CustomRTSPServer, self).__init__()
factory = CustomRTSPMediaFactory()
mount_points = self.get_mount_points()
mount_points.add_factory("/test", factory)
self.attach(None)
def main():
Gst.init(None)
server = CustomRTSPServer()
loop = GObject.MainLoop()
print("RTSP Server running at rtsp://127.0.0.1:8554/test")
loop.run()
if __name__ == "__main__":
main()