Skip to content

Instantly share code, notes, and snippets.

@tylercubell
Created February 4, 2019 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylercubell/725960663424e3520d7b46c22f4f3ecf to your computer and use it in GitHub Desktop.
Save tylercubell/725960663424e3520d7b46c22f4f3ecf to your computer and use it in GitHub Desktop.
GStreamer Python Infinite Loop
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
import os
Gst.init(None)
mainloop = GObject.MainLoop()
# Short way:
# pipeline = Gst.parse_launch("filesrc name=filesource ! decodebin ! autovideosink")
# pipeline.get_by_name("filesource").set_property("location", "background.mov")
# Long way:
pipeline = Gst.Pipeline.new("pipeline")
filesrc = Gst.ElementFactory.make("filesrc", "filesrc")
filesrc.set_property("location", "background.mov")
pipeline.add(filesrc)
decodebin = Gst.ElementFactory.make("decodebin", "decodebin")
pipeline.add(decodebin)
autovideosink = Gst.ElementFactory.make("autovideosink", "autovideosink")
pipeline.add(autovideosink)
filesrc.link(decodebin)
def decodebin_src_pad_created(element, pad):
decodebin.link(autovideosink)
decodebin.connect("pad-added", decodebin_src_pad_created)
# Start playing.
pipeline.set_state(Gst.State.PLAYING)
def message(bus, message):
if message.type == Gst.MessageType.EOS:
pipeline.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0)
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message', message)
mainloop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment