-#!/usr/bin/env python
+#!/usr/bin/env python3
# Simple media player with GStreamer
#
from gi.repository import Gst
Gst.init(None)
+from gi.repository import GLib
from gi.repository import GObject
-GObject.threads_init()
# The player window will have a fixed width and height.
# This is just to demonstrate the use of capabilities.
self.add(rescale)
queue.link(rescale)
- caps = Gst.Caps("video/x-raw-yuv,format=(fourcc)AYUV,width=%d,height=%d,pixel-aspect-ratio=1/1" % (WIDTH, HEIGHT))
+ caps = Gst.Caps("video/x-raw,format=(fourcc)AYUV,width=%d,height=%d,pixel-aspect-ratio=1/1" % (WIDTH, HEIGHT))
capsfilter = Gst.ElementFactory.make("capsfilter", "filter")
capsfilter.set_property("caps", caps)
self.add(capsfilter)
class CustomPlayBin(Gst.Pipeline):
__gproperties__ = {
- 'source': (Gst.Element, "source", "Source element", GObject.PARAM_READABLE)
+ 'source': (Gst.Element, "source", "Source element", GObject.ParamFlags.READABLE)
}
def __init__(self, uri=None):
Gst.Pipeline.__init__(self, 'CustomPlayBin')
- self._uri = uri
-
self._playbin = Gst.ElementFactory.make("playbin", "playbin")
self.add(self._playbin)
- self._playbin.set_property("uri", self._uri)
self._playbin.set_property("video-sink", CustomVideoBin())
self._playbin.set_property("audio-sink", CustomAudioBin())
+ if uri:
+ self.set_uri(uri)
+
def set_uri(self, uri):
self._uri = uri
self._playbin.set_property("uri", self._uri)
bus.connect('message::state-changed', self.on_state_changed)
def on_eos(self, bus, msg):
- print 'on_eos'
+ print('on_eos')
self.stop()
if self.eos_cb:
self.eos_cb()
def on_tag(self, bus, msg):
- print 'on_tag:'
+ print('on_tag:')
taglist = msg.parse_tag()
- print '\t', taglist.to_string()
+ print('\t', taglist.to_string())
def on_error(self, bus, msg):
- print 'on_error'
+ print('on_error')
error, debug = msg.parse_error()
- print "Error: %s" % error, debug
+ print("Error: %s" % error, debug)
self.stop()
def on_state_changed(self, bus, msg):
- print 'on_state_changed'
+ print('on_state_changed')
if msg.src != self.pipeline:
return
self.player = GstPlayer()
self.player.eos_cb = self.quit
- self.mainloop = GObject.MainLoop()
+ self.mainloop = GLib.MainLoop()
self.player.set_location(location)
self.player.play()
- GObject.io_add_watch(sys.stdin, GObject.IO_IN, self.on_stdin)
+ GLib.io_add_watch(sys.stdin, GLib.IO_IN, self.on_stdin)
try:
self.mainloop.run()
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
PIPELINE_SRC = """
class Player:
def __init__(self):
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.pipeline_src = Gst.parse_launch(PIPELINE_SRC)
self.pipeline_sink = Gst.parse_launch(PIPELINE_SINK)
player.on_rotate()
return True
- GObject.io_add_watch(sys.stdin, GObject.IO_IN, stdin_cb)
- GObject.timeout_add(100, timeout_cb)
+ GLib.io_add_watch(sys.stdin, GLib.IO_IN, stdin_cb)
+ GLib.timeout_add(100, timeout_cb)
print("\nPress Enter to freeze the video\n")
player.run()
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
# The following pipeline works
class Player:
def __init__(self):
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.pipeline = Gst.parse_launch(PIPELINE)
self.selector = self.pipeline.get_by_name('selector')
player.on_switch()
return True
- GObject.io_add_watch(sys.stdin, GObject.IO_IN, stdin_cb)
+ GLib.io_add_watch(sys.stdin, GLib.IO_IN, stdin_cb)
print("\nPress Enter to switch the source\n")
player.run()
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple looping player.
# Version 1, based on EOS handling.
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple looping player.
# Version 2, based on "about-to-finish" handling.
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def __init__(self, uri):
self._uri = uri
- self._player = Gst.ElementFactory.make("playbin", "player")
+ self._player = Gst.ElementFactory.make("playbin3", "player")
self._player.set_property("uri", uri)
self._player.connect("about-to-finish", self.on_about_to_finish)
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def __init__(self):
- self.loop = GObject.MainLoop()
- self.pipeline = Gst.ElementFactory.make("playbin", "player")
+ self.loop = GLib.MainLoop()
+ self.pipeline = Gst.ElementFactory.make("playbin3", "player")
files = ["sample_440hz.webm", "sample_880hz.webm"]
self.uris = [Gst.filename_to_uri(f) for f in files]
player.on_switch()
return True
- GObject.io_add_watch(sys.stdin, GObject.IO_IN, stdin_cb)
+ GLib.io_add_watch(sys.stdin, GLib.IO_IN, stdin_cb)
print("\nPress Enter to switch the source\n")
player.run()
gi.require_version('GstPlayer', '1.0')
from gi.repository import GstPlayer
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player(object):
self.player.connect("end-of-stream", self.end_of_stream_cb)
self.player.connect("state-changed", self.state_changed_cb)
- self.mainloop = GObject.MainLoop()
+ self.mainloop = GLib.MainLoop()
def end_of_stream_cb(self, player):
self.mainloop.quit()
-#!/usr/bin/env python
+#!/usr/bin/env python3
# test program for the "perspective" geometric transform element
from gi.repository import Gst
Gst.init(None)
+from gi.repository import GLib
from gi.repository import GObject
-GObject.threads_init()
def calc_matrix():
perspective = Gst.ElementFactory.make("perspective", None)
pipeline.add(perspective)
- print perspective.get_property("matrix")
+ print(perspective.get_property("matrix"))
M = calc_rotation_matrix()
- perspective.set_property("matrix", M)
- print perspective.get_property("matrix")
+ M2 = GObject.ValueArray()
+ for v in M:
+ M2.append(float(v))
+ perspective.set_property("matrix", M2)
+ print(perspective.get_property("matrix"))
# This should fail!
perspective.set_property("matrix", [0])
- print perspective.get_property("matrix")
+ print(perspective.get_property("matrix"))
videoconvert = Gst.ElementFactory.make("autovideoconvert", None)
pipeline.add(videoconvert)
pipeline.set_state(Gst.State.PLAYING)
- loop = GObject.MainLoop()
+ loop = GLib.MainLoop()
loop.run()
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple "trick-mode" looping player.
# Version 1, based on EOS handling.
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
def on_state_changed(self, bus, msg):
if msg.src != self._player:
return
- print 'on_state_changed'
+ print('on_state_changed')
old_state, new_state, pending = msg.parse_state_changed()
- print "%s -> %s" % (old_state, new_state)
+ print("%s -> %s" % (old_state, new_state))
if old_state == Gst.State.READY and new_state == Gst.State.PAUSED:
self.set_rate(self._rate)
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple "trick-mode" looping player.
# Version 2, based on "about-to-finish" handling.
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
self._uri = uri
self._rate = rate
- self._player = Gst.ElementFactory.make("playbin", "player")
+ self._player = Gst.ElementFactory.make("playbin3", "player")
self._player.set_property("uri", uri)
self._player.connect("about-to-finish", self.on_about_to_finish)
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
def on_state_changed(self, bus, msg):
if msg.src != self._player:
return
- print 'on_state_changed'
+ print('on_state_changed')
old_state, new_state, pending = msg.parse_state_changed()
- print "%s -> %s" % (old_state, new_state)
+ print("%s -> %s" % (old_state, new_state))
if old_state == Gst.State.READY and new_state == Gst.State.PAUSED:
self.set_rate(self._rate)
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple "trick-mode" looping player.
# Version 3, based on segment seeking.
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
def on_state_changed(self, bus, msg):
if msg.src != self._player:
return
- print 'on_state_changed'
+ print('on_state_changed')
old_state, new_state, pending = msg.parse_state_changed()
- print "%s -> %s" % (old_state, new_state)
+ print("%s -> %s" % (old_state, new_state))
if old_state == Gst.State.READY and new_state == Gst.State.PAUSED:
self.set_rate(self._rate)
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# A simple "trick-mode" player to play a file at a given speed rate.
#
from gi.repository import Gst
Gst.init(None)
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
class Player:
def run(self):
self._player.set_state(Gst.State.PLAYING)
- self.loop = GObject.MainLoop()
+ self.loop = GLib.MainLoop()
self.loop.run()
def quit(self):
def on_error(self, bus, msg):
(err, debug) = msg.parse_error()
- print "Error: %s" % err, debug
+ print("Error: %s" % err, debug)
self.quit()
def on_state_changed(self, bus, msg):
if msg.src != self._player:
return
- print 'on_state_changed'
+ print('on_state_changed')
old_state, new_state, pending = msg.parse_state_changed()
- print "%s -> %s" % (old_state, new_state)
+ print("%s -> %s" % (old_state, new_state))
if old_state == Gst.State.READY and new_state == Gst.State.PAUSED:
self.set_rate(self._rate)