summaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer
diff options
context:
space:
mode:
Diffstat (limited to 'example-scripts/gstreamer')
-rwxr-xr-xexample-scripts/gstreamer/ingest.py230
1 files changed, 113 insertions, 117 deletions
diff --git a/example-scripts/gstreamer/ingest.py b/example-scripts/gstreamer/ingest.py
index a9e06c4..efb7be2 100755
--- a/example-scripts/gstreamer/ingest.py
+++ b/example-scripts/gstreamer/ingest.py
@@ -9,7 +9,6 @@ Features:
Mix and match audio and video sources muxed into one streem.
Can display video locally, including frame count and fps.
Defaults to test audio and video sent to local core.
-
"""
import argparse
@@ -27,8 +26,8 @@ GObject.threads_init()
Gst.init([])
# this is to use the same code tha gui uses to get config from core
-sys.path.insert(0, '../..' )
-sys.path.insert(0, '.' )
+sys.path.insert(0, '../..')
+sys.path.insert(0, '.')
import voctogui.lib.connection as Connection
@@ -39,142 +38,143 @@ def mk_video_src(args, videocaps):
video_device = "device={}".format(args.video_dev) \
if args.video_dev else ""
- monitor = """tee name=t ! queue !
- videoconvert ! fpsdisplaysink sync=false
- t. ! queue !""" \
- if args.monitor else ""
+ monitor = """
+ tee name=t !
+ queue !
+ videoconvert !
+ fpsdisplaysink sync=false
+ t. ! queue !
+ """ if args.monitor else ""
if args.video_source == 'dv':
video_src = """
- dv1394src name=videosrc {video_device}!
- dvdemux name=demux !
- queue !
- dvdec !
- {monitor}
- deinterlace mode=1 !
- videoconvert !
- videorate !
- videoscale !
- """
-
+ dv1394src name=videosrc {video_device} !
+ dvdemux name=demux !
+ queue !
+ dvdec !
+ {monitor}
+ deinterlace mode=1 !
+ videoconvert !
+ videorate !
+ videoscale !
+ """
+
elif args.video_source == 'hdv':
video_src = """
hdv1394src {video_device} do-timestamp=true name=videosrc !
- tsdemux name=demux!
- queue !
- decodebin !
- {monitor}
- deinterlace mode=1 !
- videorate !
- videoscale !
- videoconvert !
- """
+ tsdemux name=demux!
+ queue !
+ decodebin !
+ {monitor}
+ deinterlace mode=1 !
+ videorate !
+ videoscale !
+ videoconvert !
+ """
elif args.video_source == 'hdmi2usb':
# https://hdmi2usb.tv
# Note: this code works with 720p
video_src = """
v4l2src {video_device} name=videosrc !
- queue !
- image/jpeg,width=1280,height=720 !
- jpegdec !
- {monitor}
- videoconvert !
- videorate !
- """
+ queue !
+ image/jpeg,width=1280,height=720 !
+ jpegdec !
+ {monitor}
+ videoconvert !
+ videorate !
+ """
elif args.video_source == 'ximage':
video_src = """
- ximagesrc name=videosrc
- use-damage=false !
- {monitor}
- videoconvert !
- videorate !
- videoscale !
- """
- # startx=0 starty=0 endx=1919 endy=1079 !
+ ximagesrc name=videosrc
+ use-damage=false !
+ {monitor}
+ videoconvert !
+ videorate !
+ videoscale !
+ """
+ # startx=0 starty=0 endx=1919 endy=1079 !
elif args.video_source == 'blackmagichdmi':
video_src = """
decklinkvideosrc mode=17 connection=2 !
- {monitor}
- videoconvert !
- videorate !
- videoscale !
- """
+ {monitor}
+ videoconvert !
+ videorate !
+ videoscale !
+ """
elif args.video_source == 'test':
video_src = """
- videotestsrc name=videosrc
- pattern=ball
+ videotestsrc name=videosrc
+ pattern=ball
foreground-color=0x00ff0000 background-color=0x00440000 !
- {monitor}
- """
+ {monitor}
+ """
- video_src = video_src.format(
- video_device=video_device,
- monitor=monitor)
+ video_src = video_src.format(video_device=video_device, monitor=monitor)
video_src += videocaps + "!\n"
return video_src
-def mk_audio_src(args, audiocaps):
+def mk_audio_src(args, audiocaps):
audio_device = "device={}".format(args.audio_dev) \
if args.audio_dev else ""
- if args.audio_source in [ 'dv', 'hdv' ]:
+ if args.audio_source in ['dv', 'hdv']:
# this only works if video is from DV also.
# or some gst source that gets demux ed
audio_src = """
demux. !
- audioconvert !
- """
+ audioconvert !
+ """
elif args.audio_source == 'pulse':
audio_src = """
- pulsesrc {audio_device} name=audiosrc !
- """.format(audio_device=audio_device)
+ pulsesrc {audio_device} name=audiosrc !
+ """.format(audio_device=audio_device)
elif args.audio_source == 'alsa':
audio_src = """
- alsasrc {audio_device} name=audiosrc !
- """.format(audio_device=audio_device)
+ alsasrc {audio_device} name=audiosrc !
+ """.format(audio_device=audio_device)
elif args.audio_source == 'blackmagichdmi':
audio_src = """
decklinkaudiosrc !
- """
+ """
elif args.audio_source == 'test':
audio_src = """
audiotestsrc name=audiosrc freq=330 !
- """
+ """
audio_src += audiocaps + "!\n"
return audio_src
-def mk_mux(args):
+def mk_mux(args):
mux = """
- mux.
- matroskamux name=mux !
- """
+ mux.
+ matroskamux name=mux !
+ """
return mux
+
def mk_client(args):
core_ip = socket.gethostbyname(args.host)
- client = """
- tcpclientsink host={host} port={port}
- """.format(host=core_ip, port=args.port)
+ client = """
+ tcpclientsink host={host} port={port}
+ """.format(host=core_ip, port=args.port)
return client
def mk_pipeline(args, server_caps):
-
video_src = mk_video_src(args, server_caps['videocaps'])
audio_src = mk_audio_src(args, server_caps['audiocaps'])
mux = mk_mux(args)
@@ -183,22 +183,21 @@ def mk_pipeline(args, server_caps):
pipeline = video_src + "mux.\n" + audio_src + mux + client
# remove blank lines to make it more human readable
- pipeline = pipeline.replace("\n\n","\n")
+ pipeline = pipeline.replace("\n\n", "\n")
return pipeline
-def get_server_caps():
-
+def get_server_caps():
# fetch config from server
server_config = Connection.fetchServerConfig()
server_caps = {'videocaps': server_config['mix']['videocaps'],
- 'audiocaps': server_config['mix']['audiocaps']}
+ 'audiocaps': server_config['mix']['audiocaps']}
return server_caps
-def run_pipeline(pipeline, args):
+def run_pipeline(pipeline, args):
core_ip = socket.gethostbyname(args.host)
clock = GstNet.NetClientClock.new('voctocore', core_ip, 9998, 0)
@@ -212,17 +211,16 @@ def run_pipeline(pipeline, args):
senderPipeline.use_clock(clock)
src = senderPipeline.get_by_name('src')
- def on_eos(self, bus, message):
+ def on_eos(bus, message):
print('Received EOS-Signal')
sys.exit(1)
- def on_error(self, bus, message):
+ def on_error(bus, message):
print('Received Error-Signal')
(error, debug) = message.parse_error()
print('Error-Details: #%u: %s' % (error.code, debug))
sys.exit(1)
-
# Binding End-of-Stream-Signal on Source-Pipeline
senderPipeline.bus.add_signal_watch()
senderPipeline.bus.connect("message::eos", on_eos)
@@ -230,7 +228,7 @@ def run_pipeline(pipeline, args):
print("playing")
senderPipeline.set_state(Gst.State.PLAYING)
-
+
mainloop = GObject.MainLoop()
try:
mainloop.run()
@@ -243,65 +241,64 @@ def run_pipeline(pipeline, args):
return
-def get_args():
+def get_args():
parser = argparse.ArgumentParser(
- description='''Vocto-ingest Client with Net-time support.
+ description='''Vocto-ingest Client with Net-time support.
Gst caps are retrieved from the server.
Run without parameters: send test av to localhost:10000
- ''')
-
+ '''
+ )
+
parser.add_argument('-v', '--verbose', action='count', default=0,
- help="Also print INFO and DEBUG messages.")
+ help="Also print INFO and DEBUG messages.")
- parser.add_argument( '--video-source', action='store',
- choices=[
- 'dv', 'hdv', 'hdmi2usb', 'blackmagichdmi',
- 'ximage',
- 'test', ],
- default='test',
- help="Where to get video from")
+ parser.add_argument('--video-source', action='store',
+ choices=['dv', 'hdv', 'hdmi2usb',
+ 'blackmagichdmi', 'ximage', 'test'],
+ default='test',
+ help="Where to get video from")
- parser.add_argument( '--video-dev', action='store',
- help="video device")
+ parser.add_argument('--video-dev', action='store',
+ help="video device")
- parser.add_argument( '--audio-source', action='store',
- choices=['dv', 'alsa', 'pulse', 'blackmagichdmi', 'test'],
- default='test',
- help="Where to get audio from")
+ parser.add_argument('--audio-source', action='store',
+ choices=['dv', 'alsa', 'pulse',
+ 'blackmagichdmi', 'test'],
+ default='test',
+ help="Where to get audio from")
- parser.add_argument( '--audio-dev', action='store',
- default='hw:CARD=CODEC',
- help="for alsa/pulse, audio device")
- # maybe hw:1,0
+ # maybe hw:1,0
+ parser.add_argument('--audio-dev', action='store',
+ default='hw:CARD=CODEC',
+ help="for alsa/pulse, audio device")
- parser.add_argument( '--audio-delay', action='store',
- default='10',
- help="ms to delay audio")
+ parser.add_argument('--audio-delay', action='store',
+ default='10',
+ help="ms to delay audio")
parser.add_argument('-m', '--monitor', action='store_true',
- help="fps display sink")
+ help="fps display sink")
- parser.add_argument( '--host', action='store',
- default='localhost',
- help="hostname of vocto core")
+ parser.add_argument('--host', action='store',
+ default='localhost',
+ help="hostname of vocto core")
- parser.add_argument( '--port', action='store',
- default='10000',
- help="port of vocto core")
+ parser.add_argument('--port', action='store',
+ default='10000',
+ help="port of vocto core")
args = parser.parse_args()
return args
-
+
def main():
-
args = get_args()
core_ip = socket.gethostbyname(args.host)
# establish a synchronus connection to server
- Connection.establish(core_ip)
+ Connection.establish(core_ip)
server_caps = get_server_caps()
@@ -310,6 +307,5 @@ def main():
run_pipeline(pipeline, args)
-
if __name__ == '__main__':
main()