Created
February 4, 2019 22:14
-
-
Save tylercubell/2f834991d4745897edb3eb53be4a80ef to your computer and use it in GitHub Desktop.
GStreamer Infinite Loop Version 2
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful example and works perfectly fine. Thanks