mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 01:45:33 +00:00
bindings: Add simple python examples
This commit is contained in:
parent
df4040a106
commit
3097efec7f
2 changed files with 75 additions and 0 deletions
44
bindings/python/examples/material.py
Normal file
44
bindings/python/examples/material.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from gi.repository import Gst, GES, GLib
|
||||
|
||||
import os
|
||||
|
||||
class Simple:
|
||||
def __init__(self, uri):
|
||||
timeline = GES.Timeline()
|
||||
trackv = GES.Track.video_raw_new()
|
||||
self.layer = GES.TimelineLayer()
|
||||
self.pipeline = GES.TimelinePipeline()
|
||||
self.pipeline.add_timeline(timeline)
|
||||
|
||||
|
||||
timeline.add_track(trackv)
|
||||
timeline.add_layer(self.layer)
|
||||
|
||||
GES.Asset.new_async(GES.TimelineFileSource, uri, None, self.discoveredCb, None)
|
||||
self.loop = GLib.MainLoop()
|
||||
self.loop.run()
|
||||
|
||||
def discoveredCb(self, asset, result, blop):
|
||||
self.layer.add_asset(asset, long(0), long(0), long(10 * Gst.SECOND), 1.0, GES.TrackType.VIDEO)
|
||||
self.start()
|
||||
|
||||
def busMessageCb(self, bus, message, udata):
|
||||
if message.type == Gst.MessageType.EOS:
|
||||
print "EOS"
|
||||
self.loop.quit()
|
||||
if message.type == Gst.MessageType.ERROR:
|
||||
print "ERROR"
|
||||
self.loop.quit()
|
||||
|
||||
def start(self):
|
||||
self.pipeline.set_state(Gst.State.PLAYING)
|
||||
self.pipeline.get_bus().add_watch(GLib.PRIORITY_DEFAULT, self.busMessageCb, None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(os.sys.argv) < 2:
|
||||
print "You must specify a file URI"
|
||||
exit(-1)
|
||||
GES.init()
|
||||
|
||||
# And try!
|
||||
Simple(os.sys.argv[1])
|
31
bindings/python/examples/simple.py
Normal file
31
bindings/python/examples/simple.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from gi.repository import Gst, GES, GLib
|
||||
|
||||
class Simple:
|
||||
def __init__(self, uri):
|
||||
timeline = GES.Timeline()
|
||||
trackv = GES.Track.video_raw_new()
|
||||
layer = GES.TimelineLayer()
|
||||
self.pipeline = GES.TimelinePipeline()
|
||||
self.pipeline.add_timeline(timeline)
|
||||
|
||||
timeline.add_track(trackv)
|
||||
timeline.add_layer(layer)
|
||||
|
||||
src = GES.TimelineFileSource.new(uri=uri)
|
||||
src.set_start(long(0))
|
||||
src.set_duration(long(10 * Gst.SECOND))
|
||||
print src
|
||||
layer.add_object(src)
|
||||
|
||||
def start(self):
|
||||
self.pipeline.set_state(Gst.State.PLAYING)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(os.sys.argv) < 2:
|
||||
print "You must specify a file URI"
|
||||
exit(-1)
|
||||
|
||||
loop = GLib.MainLoop()
|
||||
widget = Simple()
|
||||
widget.start()
|
||||
loop.run()
|
Loading…
Reference in a new issue