projects
/
experiments
/
gstreamer.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ges-cut-clip.sh: user bash in the shebang line
[experiments/gstreamer.git]
/
python
/
gst-custom-player.py
diff --git
a/python/gst-custom-player.py
b/python/gst-custom-player.py
index
cbeace2
..
c95434d
100755
(executable)
--- a/
python/gst-custom-player.py
+++ b/
python/gst-custom-player.py
@@
-2,7
+2,7
@@
# Simple media player with GStreamer
#
# Simple media player with GStreamer
#
-# Copyright (C) 2013
Antonio Ospite <ospite@studenti.unina
.it>
+# Copyright (C) 2013
-2014 Antonio Ospite <ao2@ao2
.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@
-24,10
+24,13
@@
import sys
import os
import sys
import os
-import gobject
-gobject.threads_init()
+import gi
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst
+Gst.init(None)
-import gst
+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.
# The player window will have a fixed width and height.
# This is just to demonstrate the use of capabilities.
@@
-35,61
+38,65
@@
WIDTH = 640
HEIGHT = 300
HEIGHT = 300
-class CustomVideoBin(
g
st.Bin):
+class CustomVideoBin(
G
st.Bin):
def __init__(self):
def __init__(self):
-
g
st.Bin.__init__(self, 'CustomVideoBin')
+
G
st.Bin.__init__(self, 'CustomVideoBin')
- queue =
gst.element_factory_
make('queue', 'vqueue')
+ queue =
Gst.ElementFactory.
make('queue', 'vqueue')
self.add(queue)
self.add(queue)
- rescale =
gst.element_factory_
make("videoscale", "rescale")
+ rescale =
Gst.ElementFactory.
make("videoscale", "rescale")
self.add(rescale)
self.add(rescale)
+ queue.link(rescale)
- caps =
g
st.Caps("video/x-raw-yuv,format=(fourcc)AYUV,width=%d,height=%d,pixel-aspect-ratio=1/1" % (WIDTH, HEIGHT))
- capsfilter =
gst.element_factory_
make("capsfilter", "filter")
+ caps =
G
st.Caps("video/x-raw-yuv,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)
capsfilter.set_property("caps", caps)
self.add(capsfilter)
+ rescale.link(capsfilter)
- colorspace = gst.element_factory_make("colorspace", "colorspace")
- self.add(colorspace)
+ videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
+ self.add(videoconvert)
+ capsfilter.link(videoconvert)
- videosink =
gst.element_factory_
make("autovideosink", "vidoesink")
+ videosink =
Gst.ElementFactory.
make("autovideosink", "vidoesink")
self.add(videosink)
self.add(videosink)
+ videoconvert.link(videosink)
- gst.element_link_many(queue, rescale, capsfilter, colorspace, videosink)
- sink = queue.get_pad('sink')
- self.add_pad(gst.GhostPad('sink', sink))
+ sink = queue.get_static_pad('sink')
+ self.add_pad(Gst.GhostPad('sink', sink))
-class CustomAudioBin(
g
st.Bin):
+class CustomAudioBin(
G
st.Bin):
def __init__(self):
def __init__(self):
-
g
st.Bin.__init__(self, 'CustomAudioBin')
+
G
st.Bin.__init__(self, 'CustomAudioBin')
- queue =
gst.element_factory_
make('queue', 'aqueue')
+ queue =
Gst.ElementFactory.
make('queue', 'aqueue')
self.add(queue)
self.add(queue)
- audioconvert =
gst.element_factory_
make("audioconvert", "audioconverter")
+ audioconvert =
Gst.ElementFactory.
make("audioconvert", "audioconverter")
self.add(audioconvert)
self.add(audioconvert)
+ queue.link(audioconvert)
- audiosink =
gst.element_factory_
make("autoaudiosink", "audiosink")
+ audiosink =
Gst.ElementFactory.
make("autoaudiosink", "audiosink")
self.add(audiosink)
self.add(audiosink)
+ audioconvert.link(audiosink)
- gst.element_link_many(queue, audioconvert, audiosink)
- sink = queue.get_pad('sink')
- self.add_pad(gst.GhostPad('sink', sink))
+ sink = queue.get_static_pad('sink')
+ self.add_pad(Gst.GhostPad('sink', sink))
-class CustomPlayBin(
g
st.Pipeline):
+class CustomPlayBin(
G
st.Pipeline):
__gproperties__ = {
__gproperties__ = {
- 'source': (
gst.Element, "source", "Source element", go
bject.PARAM_READABLE)
+ 'source': (
Gst.Element, "source", "Source element", GO
bject.PARAM_READABLE)
}
def __init__(self, uri=None):
}
def __init__(self, uri=None):
-
g
st.Pipeline.__init__(self, 'CustomPlayBin')
+
G
st.Pipeline.__init__(self, 'CustomPlayBin')
self._uri = uri
self._uri = uri
- self._playbin =
gst.element_factory_make("playbin2
", "playbin")
+ self._playbin =
Gst.ElementFactory.make("playbin
", "playbin")
self.add(self._playbin)
self._playbin.set_property("uri", self._uri)
self.add(self._playbin)
self._playbin.set_property("uri", self._uri)
@@
-125,8
+132,7
@@
class GstPlayer:
def on_tag(self, bus, msg):
print 'on_tag:'
taglist = msg.parse_tag()
def on_tag(self, bus, msg):
print 'on_tag:'
taglist = msg.parse_tag()
- for key in taglist.keys():
- print '\t%s = %s' % (key, taglist[key])
+ print '\t', taglist.to_string()
def on_error(self, bus, msg):
print 'on_error'
def on_error(self, bus, msg):
print 'on_error'
@@
-145,13
+151,13
@@
class GstPlayer:
self.pipeline.set_uri(location)
def play(self):
self.pipeline.set_uri(location)
def play(self):
- self.pipeline.set_state(
gst.STATE_
PLAYING)
+ self.pipeline.set_state(
Gst.State.
PLAYING)
def pause(self):
def pause(self):
- self.pipeline.set_state(
gst.STATE_
PAUSED)
+ self.pipeline.set_state(
Gst.State.
PAUSED)
def stop(self):
def stop(self):
- self.pipeline.set_state(
gst.STATE_
NULL)
+ self.pipeline.set_state(
Gst.State.
NULL)
class PlayerTUI():
class PlayerTUI():
@@
-160,12
+166,12
@@
class PlayerTUI():
self.player = GstPlayer()
self.player.eos_cb = self.quit
self.player = GstPlayer()
self.player.eos_cb = self.quit
- self.mainloop =
go
bject.MainLoop()
+ self.mainloop =
GO
bject.MainLoop()
self.player.set_location(location)
self.player.play()
self.player.set_location(location)
self.player.play()
-
gobject.io_add_watch(sys.stdin, go
bject.IO_IN, self.on_stdin)
+
GObject.io_add_watch(sys.stdin, GO
bject.IO_IN, self.on_stdin)
try:
self.mainloop.run()
try:
self.mainloop.run()
@@
-199,11
+205,9
@@
def main(args):
usage()
sys.exit(1)
usage()
sys.exit(1)
- if not gst.uri_is_valid(args[1]):
- sys.stderr.write("Error: Invalid URI: %s\n" % args[1])
- sys.exit(1)
+ uri = Gst.filename_to_uri(args[1])
- tui = PlayerTUI(
args[1]
)
+ tui = PlayerTUI(
uri
)
if __name__ == '__main__':
sys.exit(main(sys.argv))
if __name__ == '__main__':
sys.exit(main(sys.argv))