From 39c8cb3a0e3813ef77c61c601d0028281c04ad2d Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 6 Dec 2015 20:28:02 +0100 Subject: [example-scripts] overhaul and test all example scripts, fixes #5 --- .../gstreamer/source-background-loop.py | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 example-scripts/gstreamer/source-background-loop.py (limited to 'example-scripts/gstreamer/source-background-loop.py') diff --git a/example-scripts/gstreamer/source-background-loop.py b/example-scripts/gstreamer/source-background-loop.py new file mode 100755 index 0000000..be59d18 --- /dev/null +++ b/example-scripts/gstreamer/source-background-loop.py @@ -0,0 +1,66 @@ +#!/usr/bin/python3 +import sys, gi, signal + +gi.require_version('Gst', '1.0') +from gi.repository import Gst, GObject + +# init GObject & Co. before importing local classes +GObject.threads_init() +Gst.init([]) + +class LoopSource(object): + def __init__(self): + # it works much better with a local file + pipeline = """ + uridecodebin name=src uri=http://c3voc.mazdermind.de/testfiles/bg.ts ! + videoscale ! + videoconvert ! + video/x-raw,format=UYVY,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 ! + matroskamux ! + tcpclientsink host=localhost port=16000 + """ + + self.senderPipeline = Gst.parse_launch(pipeline) + 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, Seeking to start') + self.src.seek( + 1.0, # rate (float) + Gst.Format.TIME, # format (Gst.Format) + Gst.SeekFlags.FLUSH, # flags (Gst.SeekFlags) + Gst.SeekType.SET, # start_type (Gst.SeekType) + 0, # start (int) + Gst.SeekType.NONE, # stop_type (Gst.SeekType) + 0 # stop (int) + ) + + 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) + + src = LoopSource() + + mainloop = GObject.MainLoop() + try: + mainloop.run() + except KeyboardInterrupt: + print('Terminated via Ctrl-C') + + +if __name__ == '__main__': + main() -- cgit v1.2.3