gstreamer/examples/python/gst-player.py
Thibault Saunier b24d1918f8 examples: python: Simplify the simple example
We shouldn't show assets usage in the simplest example we have
as it is useful for more advanced use cases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/252>
2021-05-21 21:26:19 +00:00

50 lines
1.2 KiB
Python
Executable file

#!/usr/bin/python3
import sys
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GES', '1.0')
gi.require_version('GstPlayer', '1.0')
gi.require_version('GLib', '2.0')
from gi.repository import Gst, GES, GLib, GstPlayer
if __name__ == "__main__":
if len(sys.argv) < 2:
print("You must specify a file URI")
sys.exit(-1)
Gst.init(None)
GES.init()
timeline = GES.Timeline.new_audio_video()
layer = timeline.append_layer()
start = 0
for uri in sys.argv[1:]:
if not Gst.uri_is_valid(uri):
uri = Gst.filename_to_uri(uri)
clip = GES.UriClip.new(uri)
clip.props.start = start
layer.add_clip(clip)
start += clip.props.duration
player = GstPlayer
player = GstPlayer.Player.new(None, GstPlayer.PlayerGMainContextSignalDispatcher.new(None))
player.set_uri("ges://")
player.get_pipeline().connect("source-setup",
lambda playbin, source: source.set_property("timeline", timeline))
loop = GLib.MainLoop()
player.connect("end-of-stream", lambda x: loop.quit())
def error(player, err):
loop.quit()
print("Got error: %s" % err)
sys.exit(1)
player.connect("error", error)
player.play()
loop.run()