aboutsummaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
diff options
context:
space:
mode:
authorMaZderMind <git@mazdermind.de>2016-01-28 12:27:27 +0100
committerMaZderMind <git@mazdermind.de>2016-02-02 16:05:56 +0100
commit23fdb289436d792557227ec4d445636b2808de2d (patch)
treedb5647f708a6c37082a7cf63a77ea4d7bae2eaae /example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
parent049b95862fe7d751b40c5e448471226c8063f3d8 (diff)
rename source and make hostname a parameter
Diffstat (limited to 'example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py')
-rwxr-xr-xexample-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
new file mode 100755
index 0000000..70e838f
--- /dev/null
+++ b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python3
+import sys, gi, signal
+import argparse, socket
+
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst, GstNet, GObject
+
+# init GObject & Co. before importing local classes
+GObject.threads_init()
+Gst.init([])
+
+class Source(object):
+ def __init__(self, ip):
+ # it works much better with a local file
+ pipeline = """
+ videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 !
+ timeoverlay !
+ video/x-raw,format=I420,width=1280,height=720,framerate=25/1,pixel-aspect-ratio=1/1 !
+ mux.
+
+ audiotestsrc freq=330 !
+ audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000 !
+ mux.
+
+ matroskamux name=mux !
+ tcpclientsink host={ip} port=10000
+ """.format(
+ ip=ip
+ )
+
+ self.clock = GstNet.NetClientClock.new('voctocore', ip, 9998, 0)
+ print('obtained NetClientClock from host', self.clock)
+
+ print('waiting for NetClientClock to sync…')
+ self.clock.wait_for_sync(Gst.CLOCK_TIME_NONE)
+
+ print('starting pipeline')
+ self.senderPipeline = Gst.parse_launch(pipeline)
+ self.senderPipeline.use_clock(self.clock)
+ self.src = self.senderPipeline.get_by_name('src')
+
+ # Binding End-of-Stream-Signal on Source-Pipeline
+ self.senderPipeline.bus.add_signal_watch()
+ self.senderPipeline.bus.connect("message::eos", self.on_eos)
+ self.senderPipeline.bus.connect("message::error", self.on_error)
+
+ print("playing")
+ self.senderPipeline.set_state(Gst.State.PLAYING)
+
+
+ def on_eos(self, bus, message):
+ print('Received EOS-Signal')
+ sys.exit(1)
+
+ def on_error(self, bus, message):
+ print('Received Error-Signal')
+ (error, debug) = message.parse_error()
+ print('Error-Details: #%u: %s' % (error.code, debug))
+ sys.exit(1)
+
+def main():
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+ parser = argparse.ArgumentParser(description='Voctocore Remote-Source')
+ parser.add_argument('host')
+
+ args = parser.parse_args()
+ print('Resolving hostname '+args.host)
+ addrs = [ str(i[4][0]) for i in socket.getaddrinfo(args.host, None) ]
+ if len(addrs) == 0:
+ print('Found no IPs')
+ sys.exit(1)
+
+ print('Using IP '+addrs[0])
+
+ src = Source(addrs[0])
+ mainloop = GObject.MainLoop()
+ try:
+ mainloop.run()
+ except KeyboardInterrupt:
+ print('Terminated via Ctrl-C')
+
+
+if __name__ == '__main__':
+ main()