rtmp test.
[toast/stream2beamer.git] / rtmp_test.py
1 # Imports
2 import gi
3
4 gi.require_version('Gst', '1.0')
5 from gi.repository import Gst
6
7 gi.require_version('GstWebRTC', '1.0')
8 from gi.repository import GstWebRTC, GLib
9
10 gi.require_version('GstSdp', '1.0')
11 from gi.repository import GstSdp
12
13 # libgstrtspserver-1.0-dev
14 gi.require_version('GstRtspServer', '1.0')
15 from gi.repository import GstRtspServer
16
17
18 def main():
19     # OS Variables and Requirements
20     gi.require_version('Gst', '1.0')
21     # os.environ["GST_DEBUG"] = "4" # Enable Debug
22
23     # Initialize GStreamer
24     Gst.init(None) # gst-launch-1.0 !
25     pipeline = Gst.Pipeline()
26
27     # Create Video Source (Video Test Source)
28     videosrc = Gst.ElementFactory.make("videotestsrc") # videotestsrc is-live=true !
29     videosrc.set_property('is-live', True)
30     pipeline.add(videosrc)
31
32     # Convert Video (to x264enc?)
33     # videoconvert = Gst.ElementFactory.make('autovideoconvert') # videoconvert
34     videoconvert = Gst.ElementFactory.make('videoconvert') # videoconvert
35     pipeline.add(videoconvert)
36
37     # IDK
38     idk = Gst.ElementFactory.make("x264enc") # x264enc bitrate=1000 tune=zerolatency
39     idk.set_property('bitrate', 1000)
40     idk.set_property('tune', 'zerolatency')
41     pipeline.add(idk)
42
43     # Queue Data
44     queueRTMP = Gst.ElementFactory.make("queue") # queue
45     pipeline.add(queueRTMP)
46
47     # Convert to Mux
48     flvmux = Gst.ElementFactory.make("flvmux", "mux") # flvmux name=mux
49     pipeline.add(flvmux)
50
51     # Stream to RTMP Server
52     rtmpsink = Gst.ElementFactory.make("rtmpsink") # rtmpsink location='rtmp://live.twitch.tv/app/STREAM_KEY_HERE'
53     rtmpsink.set_property("location", 'rtmp://sirius/gregoa')
54     pipeline.add(rtmpsink)
55
56     ok = videosrc.link(videoconvert)
57     assert ok
58     ok = videoconvert.link(idk)
59     assert ok
60     ok = idk.link(queueRTMP)
61     assert ok
62     ok = queueRTMP.link(flvmux)
63     assert ok
64     ok = flvmux.link(rtmpsink)
65     assert ok
66
67     pipeline.set_state(Gst.State.PLAYING)
68     loop = GLib.MainLoop()
69     loop.run()
70     # time.sleep(20)
71
72
73 main()