aboutsummaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2016-09-14 10:28:11 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2016-09-14 11:04:28 +0200
commit27f9bb1c2aeebae5c1482d9b5f33e990f6cfb68b (patch)
treed7675356585728007b0bad2422564abf1848426d /example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
parentd77da93cb911a12305c6a18c2b3f317f8499a2d0 (diff)
source-*.py examples: pep8ify
* One import per line * Indent by 4 spaces * Reformat multiline strings * Spaces around infix operators * Reformat argument lists * Reformat list literals
Diffstat (limited to 'example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py')
-rwxr-xr-xexample-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py149
1 files changed, 81 insertions, 68 deletions
diff --git a/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
index 5404add..e09f0ec 100755
--- a/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
+++ b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py
@@ -1,6 +1,10 @@
#!/usr/bin/python3
-import os, sys, gi, signal
-import argparse, socket
+import os
+import sys
+import gi
+import signal
+import argparse
+import socket
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GstNet, GObject
@@ -9,83 +13,92 @@ from gi.repository import Gst, GstNet, GObject
GObject.threads_init()
Gst.init([])
-class Source(object):
- def __init__(self, settings):
- # 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_map(settings)
-
- self.clock = GstNet.NetClientClock.new('voctocore', settings['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 '+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)
+class Source(object):
- def on_eos(self, bus, message):
- print('Received EOS-Signal')
- sys.exit(1)
+ def __init__(self, settings):
+ # 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,rate=48000,
+ layout=interleaved !
+ mux.
+
+ matroskamux name=mux !
+ tcpclientsink host={IP} port=10000
+ """.format_map(settings)
+
+ self.clock = GstNet.NetClientClock.new('voctocore',
+ settings['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 ' + 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 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)
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
- parser = argparse.ArgumentParser(description='Voctocore Remote-Source')
- parser.add_argument('host')
+ 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)
+ 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])
+ print('Using IP ' + addrs[0])
- config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.sh')
- with open(config) as config:
- lines = [ line.strip() for line in config if line[0] != '#' ]
- pairs = [ line.split('=', 1) for line in lines ]
- settings = { pair[0]: pair[1] for pair in pairs }
+ config = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '../config.sh')
+ with open(config) as config:
+ lines = [line.strip() for line in config if line[0] != '#']
+ pairs = [line.split('=', 1) for line in lines]
+ settings = {pair[0]: pair[1] for pair in pairs}
- settings['IP'] = addrs[0]
+ settings['IP'] = addrs[0]
- src = Source(settings)
- mainloop = GObject.MainLoop()
- try:
- mainloop.run()
- except KeyboardInterrupt:
- print('Terminated via Ctrl-C')
+ src = Source(settings)
+ mainloop = GObject.MainLoop()
+ try:
+ mainloop.run()
+ except KeyboardInterrupt:
+ print('Terminated via Ctrl-C')
if __name__ == '__main__':
- main()
+ main()