rtmp test.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 28 Apr 2021 20:26:51 +0000 (22:26 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 28 Apr 2021 20:26:51 +0000 (22:26 +0200)
rtmp_test.py [new file with mode: 0644]

diff --git a/rtmp_test.py b/rtmp_test.py
new file mode 100644 (file)
index 0000000..4460887
--- /dev/null
@@ -0,0 +1,73 @@
+# Imports
+import gi
+
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst
+
+gi.require_version('GstWebRTC', '1.0')
+from gi.repository import GstWebRTC, GLib
+
+gi.require_version('GstSdp', '1.0')
+from gi.repository import GstSdp
+
+# libgstrtspserver-1.0-dev
+gi.require_version('GstRtspServer', '1.0')
+from gi.repository import GstRtspServer
+
+
+def main():
+    # OS Variables and Requirements
+    gi.require_version('Gst', '1.0')
+    # os.environ["GST_DEBUG"] = "4" # Enable Debug
+
+    # Initialize GStreamer
+    Gst.init(None) # gst-launch-1.0 !
+    pipeline = Gst.Pipeline()
+
+    # Create Video Source (Video Test Source)
+    videosrc = Gst.ElementFactory.make("videotestsrc") # videotestsrc is-live=true !
+    videosrc.set_property('is-live', True)
+    pipeline.add(videosrc)
+
+    # Convert Video (to x264enc?)
+    # videoconvert = Gst.ElementFactory.make('autovideoconvert') # videoconvert
+    videoconvert = Gst.ElementFactory.make('videoconvert') # videoconvert
+    pipeline.add(videoconvert)
+
+    # IDK
+    idk = Gst.ElementFactory.make("x264enc") # x264enc bitrate=1000 tune=zerolatency
+    idk.set_property('bitrate', 1000)
+    idk.set_property('tune', 'zerolatency')
+    pipeline.add(idk)
+
+    # Queue Data
+    queueRTMP = Gst.ElementFactory.make("queue") # queue
+    pipeline.add(queueRTMP)
+
+    # Convert to Mux
+    flvmux = Gst.ElementFactory.make("flvmux", "mux") # flvmux name=mux
+    pipeline.add(flvmux)
+
+    # Stream to RTMP Server
+    rtmpsink = Gst.ElementFactory.make("rtmpsink") # rtmpsink location='rtmp://live.twitch.tv/app/STREAM_KEY_HERE'
+    rtmpsink.set_property("location", 'rtmp://sirius/gregoa')
+    pipeline.add(rtmpsink)
+
+    ok = videosrc.link(videoconvert)
+    assert ok
+    ok = videoconvert.link(idk)
+    assert ok
+    ok = idk.link(queueRTMP)
+    assert ok
+    ok = queueRTMP.link(flvmux)
+    assert ok
+    ok = flvmux.link(rtmpsink)
+    assert ok
+
+    pipeline.set_state(Gst.State.PLAYING)
+    loop = GLib.MainLoop()
+    loop.run()
+    # time.sleep(20)
+
+
+main()