From bfdbb547d7df9304dcfc50cc9b13013c92194da2 Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Fri, 8 Jun 2018 21:34:49 +0100 Subject: [PATCH] More Python examples - this time gstproxy --- python_examples/gstproxy_01_audiotestsrc.py | 32 +++++++++++++ python_examples/gstproxy_02_playbin.py | 50 +++++++++++++++++++++ python_examples/show_test_stream.py | 8 ++-- 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 python_examples/gstproxy_01_audiotestsrc.py create mode 100755 python_examples/gstproxy_02_playbin.py diff --git a/python_examples/gstproxy_01_audiotestsrc.py b/python_examples/gstproxy_01_audiotestsrc.py new file mode 100644 index 0000000..326bd0a --- /dev/null +++ b/python_examples/gstproxy_01_audiotestsrc.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# Shows how two pipelines can be connected, using proxysink/proxysrc. +# It will output a test audio sound. +# Python equivalent of example at https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-bad-plugins/html/gst-plugins-bad-plugins-proxysrc.html +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject, Gst +import os + +Gst.init(None) +mainloop = GObject.MainLoop() + +pipe1 = Gst.parse_launch("audiotestsrc is-live=1 ! proxysink name=psink") +psink = pipe1.get_by_name('psink') + +pipe2 = Gst.parse_launch("proxysrc name=psrc ! autoaudiosink") +psrc = pipe2.get_by_name('psrc') + +psrc.set_property('proxysink', psink) + +clock = Gst.SystemClock.obtain() +pipe1.use_clock(clock) +pipe2.use_clock(clock) +clock.unref() + +pipe1.set_base_time(0) +pipe2.set_base_time(0) + +pipe1.set_state(Gst.State.PLAYING) +pipe2.set_state(Gst.State.PLAYING) + +mainloop.run() diff --git a/python_examples/gstproxy_02_playbin.py b/python_examples/gstproxy_02_playbin.py new file mode 100755 index 0000000..c8571d4 --- /dev/null +++ b/python_examples/gstproxy_02_playbin.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# Shows how two pipelines can be connected, using proxysink/proxysrc +# This example uses Playbin to read a file, and send the video and audio to separate proxies. +# Unlike just using playbin directly, this will never end, as the other pipelines will continue 'listening'. +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject, Gst +import os + +Gst.init(None) +mainloop = GObject.MainLoop() + +pipe1 = Gst.parse_launch("playbin uri=\"file://" + os.environ['SRC'] + "\"") +playsink = pipe1.get_by_name('playsink') + +psink1 = Gst.ElementFactory.make("proxysink", "psink1") +psink2 = Gst.ElementFactory.make("proxysink", "psink2") +playsink.set_property('video-sink', psink1) +playsink.set_property('audio-sink', psink2) + +pipe2 = Gst.parse_launch("proxysrc name=psrc1 ! autovideosink") +psrc1 = pipe2.get_by_name('psrc1') +psrc1.set_property('proxysink', psink1) + +pipe3 = Gst.parse_launch("proxysrc name=psrc2 ! autoaudiosink") +psrc2 = pipe3.get_by_name('psrc2') +psrc2.set_property('proxysink', psink2) + +clock = Gst.SystemClock.obtain() +pipe1.use_clock(clock) +pipe2.use_clock(clock) +pipe3.use_clock(clock) +clock.unref() + +pipe1.set_base_time(0) +pipe2.set_base_time(0) +pipe3.set_base_time(0) + +pipe1.set_state(Gst.State.PLAYING) +pipe2.set_state(Gst.State.PLAYING) +pipe3.set_state(Gst.State.PLAYING) + +def on_error(bus, message): + print(message.parse_error()) + +bus1 = pipe1.get_bus() +bus1.add_signal_watch() +bus1.connect('message::error', on_error) + +mainloop.run() diff --git a/python_examples/show_test_stream.py b/python_examples/show_test_stream.py index 07b79c6..84f2bd3 100644 --- a/python_examples/show_test_stream.py +++ b/python_examples/show_test_stream.py @@ -11,14 +11,14 @@ gi.require_version('Gst', '1.0') from gi.repository import GObject, Gst import os -Gst.init() +Gst.init(None) mainloop = GObject.MainLoop() pipeline = Gst.Pipeline.new("pipe") -videotestsrc = Gst.ElementFactory.make("videotestsrc", "videotestsrc") -videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert") -autovideosink = Gst.ElementFactory.make("autovideosink", "autovideosink") +videotestsrc = Gst.ElementFactory.make("videotestsrc") +videoconvert = Gst.ElementFactory.make("videoconvert") +autovideosink = Gst.ElementFactory.make("autovideosink") pipeline.add(videotestsrc) pipeline.add(videoconvert)