mirror of
https://github.com/matthew1000/gstreamer-cheat-sheet.git
synced 2024-11-22 00:10:59 +00:00
More Python examples - this time gstproxy
This commit is contained in:
parent
348022e3a2
commit
bfdbb547d7
3 changed files with 86 additions and 4 deletions
32
python_examples/gstproxy_01_audiotestsrc.py
Normal file
32
python_examples/gstproxy_01_audiotestsrc.py
Normal file
|
@ -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()
|
50
python_examples/gstproxy_02_playbin.py
Executable file
50
python_examples/gstproxy_02_playbin.py
Executable file
|
@ -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()
|
|
@ -11,14 +11,14 @@ gi.require_version('Gst', '1.0')
|
||||||
from gi.repository import GObject, Gst
|
from gi.repository import GObject, Gst
|
||||||
import os
|
import os
|
||||||
|
|
||||||
Gst.init()
|
Gst.init(None)
|
||||||
mainloop = GObject.MainLoop()
|
mainloop = GObject.MainLoop()
|
||||||
|
|
||||||
pipeline = Gst.Pipeline.new("pipe")
|
pipeline = Gst.Pipeline.new("pipe")
|
||||||
|
|
||||||
videotestsrc = Gst.ElementFactory.make("videotestsrc", "videotestsrc")
|
videotestsrc = Gst.ElementFactory.make("videotestsrc")
|
||||||
videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
|
videoconvert = Gst.ElementFactory.make("videoconvert")
|
||||||
autovideosink = Gst.ElementFactory.make("autovideosink", "autovideosink")
|
autovideosink = Gst.ElementFactory.make("autovideosink")
|
||||||
|
|
||||||
pipeline.add(videotestsrc)
|
pipeline.add(videotestsrc)
|
||||||
pipeline.add(videoconvert)
|
pipeline.add(videoconvert)
|
||||||
|
|
Loading…
Reference in a new issue