Skip to content

Instantly share code, notes, and snippets.

@tylercubell
Created February 4, 2019 22:14
Show Gist options
  • Save tylercubell/2f834991d4745897edb3eb53be4a80ef to your computer and use it in GitHub Desktop.
Save tylercubell/2f834991d4745897edb3eb53be4a80ef to your computer and use it in GitHub Desktop.
GStreamer Infinite Loop Version 2
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
import os
Gst.init(None)
# 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")
bus = pipeline.get_bus()
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)
while True:
try:
message = bus.timed_pop(0.1 * Gst.SECOND)
if message == None:
pass
elif message.type == Gst.MessageType.EOS:
pipeline.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0)
elif message.type == Gst.MessageType.ERROR:
break
except KeyboardInterrupt:
break
pipeline.set_state(Gst.State.NULL)
@jamalag
Copy link

jamalag commented Jul 29, 2024

Useful example and works perfectly fine. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment