Last active
November 19, 2023 13:37
-
-
Save tylercubell/1f4022ee06d93654c19309134d8a5a10 to your computer and use it in GitHub Desktop.
GStreamer Python Playbin Custom Video-sink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gi | |
gi.require_version('Gst', '1.0') | |
from gi.repository import GObject, Gst | |
Gst.init(None) | |
class Main: | |
def __init__(self): | |
self.pipeline = Gst.Pipeline.new("pipeline") | |
self.bus = self.pipeline.get_bus() | |
self.playbin = Gst.ElementFactory.make("playbin", "playbin") | |
self.playbin.set_property("uri", "file:///foo/bar/file.mp4") | |
self.pipeline.add(self.playbin) | |
self.sink = Gst.Bin.new("sink") | |
self.autovideosink = Gst.ElementFactory.make("autovideosink", "autovideosink") | |
self.sink.add(self.autovideosink) | |
self.pad = self.autovideosink.get_static_pad('sink') | |
self.ghostpad = Gst.GhostPad.new('sink', self.pad) | |
self.ghostpad.set_active(True) | |
self.sink.add_pad(self.ghostpad) | |
self.playbin.set_property("video-sink", self.sink) | |
def run(self): | |
self.pipeline.set_state(Gst.State.PLAYING) | |
while True: | |
try: | |
message = self.bus.timed_pop(Gst.SECOND) | |
if message == None: | |
pass | |
elif message.type == Gst.MessageType.EOS: | |
break | |
elif message.type == Gst.MessageType.ERROR: | |
break | |
except KeyboardInterrupt: | |
break | |
self.pipeline.set_state(Gst.State.NULL) | |
start = Main() | |
start.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need help to make a pipeline with multiple sinks and switch that pipeline in play state can switch between sinks as per my command