diff options
Diffstat (limited to 'example-scripts')
5 files changed, 203 insertions, 5 deletions
diff --git a/example-scripts/control-server/generate-cut-list.py b/example-scripts/control-server/generate-cut-list.py index 23a0b33..959ab58 100755 --- a/example-scripts/control-server/generate-cut-list.py +++ b/example-scripts/control-server/generate-cut-list.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import socket import datetime import sys diff --git a/example-scripts/ffmpeg/source-nostream-music.sh b/example-scripts/ffmpeg/source-nostream-music.sh index 5f10caf..23db81d 100755 --- a/example-scripts/ffmpeg/source-nostream-music.sh +++ b/example-scripts/ffmpeg/source-nostream-music.sh @@ -9,4 +9,6 @@ while true; do -c:a pcm_s16le \ -f matroska \ tcp://localhost:18000 + + sleep 1; done diff --git a/example-scripts/gstreamer/source-background-loop.py b/example-scripts/gstreamer/source-background-loop.py index 8b65088..2f13edf 100755 --- a/example-scripts/gstreamer/source-background-loop.py +++ b/example-scripts/gstreamer/source-background-loop.py @@ -1,4 +1,5 @@ -import sys, gi, signal +#!/usr/bin/env python3 +import os, sys, gi, signal gi.require_version('Gst', '1.0') from gi.repository import Gst, GObject @@ -8,17 +9,18 @@ GObject.threads_init() Gst.init([]) class LoopSource(object): - def __init__(self): + def __init__(self, settings): # 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=I420,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 ! + video/x-raw,format=I420,width={WIDTH},height={HEIGHT},framerate={FRAMERATE}/1,pixel-aspect-ratio=1/1 ! matroskamux ! tcpclientsink host=localhost port=16000 - """ + """.format_map(settings) + print('starting pipeline '+pipeline) self.senderPipeline = Gst.parse_launch(pipeline) self.src = self.senderPipeline.get_by_name('src') @@ -52,7 +54,13 @@ class LoopSource(object): def main(): signal.signal(signal.SIGINT, signal.SIG_DFL) - src = LoopSource() + config = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.sh') + with open(config, 'r') 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 } + + src = LoopSource(settings) mainloop = GObject.MainLoop() try: diff --git a/example-scripts/gstreamer/source-remote-desktop-as-cam1.py b/example-scripts/gstreamer/source-remote-desktop-as-cam1.py new file mode 100755 index 0000000..7d1c7f2 --- /dev/null +++ b/example-scripts/gstreamer/source-remote-desktop-as-cam1.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 +import os, 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, settings): + pipeline = """ + ximagesrc use-damage=0 startx=0 starty=0 endx=1919 endy=1079 ! + queue ! + videoscale ! + videorate ! + timeoverlay ! + videoconvert ! + video/x-raw,format=I420,width={WIDTH},height={HEIGHT},framerate={FRAMERATE}/1,pixel-aspect-ratio=1/1 ! + queue ! + mux. + + pulsesrc ! + audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate={AUDIORATE} ! + queue ! + 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 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]) + + 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] + + src = Source(settings) + mainloop = GObject.MainLoop() + try: + mainloop.run() + except KeyboardInterrupt: + print('Terminated via Ctrl-C') + + +if __name__ == '__main__': + main() 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..5404add --- /dev/null +++ b/example-scripts/gstreamer/source-remote-videotestsrc-as-cam1.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +import os, 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, 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) + + + 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]) + + 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] + + src = Source(settings) + mainloop = GObject.MainLoop() + try: + mainloop.run() + except KeyboardInterrupt: + print('Terminated via Ctrl-C') + + +if __name__ == '__main__': + main() |