-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_filesrc_to_rtsp.py
More file actions
34 lines (26 loc) · 1.1 KB
/
example_filesrc_to_rtsp.py
File metadata and controls
34 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- encoding: utf-8 -*-
import gi
# import required library like Gstreamer and GstreamerRtspServer
gi.require_version("Gst", "1.0")
gi.require_version("GstRtspServer", "1.0")
from gi.repository import Gst, GLib, GstRtspServer, GObject
if __name__ == "__main__":
Gst.init(None)
server = GstRtspServer.RTSPServer.new()
server.set_service("8554")
server.connect("client-connected", lambda x1, x2: print(f"Client connected, {x1}, {x2}"))
factory = GstRtspServer.RTSPMediaFactory.new()
# Please note launch description string must be ended an element with the name *payXX*. This is required by rtsp server.
factory.set_launch("""(
filesrc location=./data/sample-mp4-file-small.mp4
! qtdemux name=d
d. ! queue ! rtph264pay pt=96 name=pay0
)""")
factory.set_shared(True)
factory.set_transport_mode(GstRtspServer.RTSPTransportMode.PLAY)
mount_points = server.get_mount_points()
mount_points.add_factory('/0', factory)
mount_points.add_factory('/1', factory)
server.attach(None)
print("stream ready at rtsp://127.0.0.1:8554/0")
GLib.MainLoop().run()