Reputation: 47
I am trying out an example from this tutorial which shows how to play a video in a GTK app using PyGObject. Below is the exact code which I am trying to run:
import sys, os
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst, GObject, Gtk
# Needed for window.get_xid(), xvimagesink.set_window_handle(), respectively:
from gi.repository import GdkX11, GstVideo
class GTK_Main(object):
def __init__(self):
window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.set_title("Video-Player")
window.set_default_size(500, 400)
window.connect("destroy", Gtk.main_quit, "WM destroy")
vbox = Gtk.VBox()
window.add(vbox)
hbox = Gtk.HBox()
vbox.pack_start(hbox, False, False, 0)
self.entry = Gtk.Entry()
hbox.add(self.entry)
self.button = Gtk.Button("Start")
hbox.pack_start(self.button, False, False, 0)
self.button.connect("clicked", self.start_stop)
self.movie_window = Gtk.DrawingArea()
vbox.add(self.movie_window)
window.show_all()
self.player = Gst.ElementFactory.make("playbin", "player")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
bus.connect("sync-message::element", self.on_sync_message)
def start_stop(self, w):
if self.button.get_label() == "Start":
filepath = self.entry.get_text().strip()
if os.path.isfile(filepath):
filepath = os.path.realpath(filepath)
self.button.set_label("Stop")
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(Gst.State.PLAYING)
else:
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.EOS:
self.player.set_state(Gst.State.NULL)
self.button.set_label("Start")
elif t == Gst.MessageType.ERROR:
self.player.set_state(Gst.State.NULL)
err, debug = message.parse_error()
print ("Error: %s" % err, debug)
self.button.set_label("Start")
def on_sync_message(self, bus, message):
if message.get_structure().get_name() == 'prepare-window-handle':
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_window_handle(self.movie_window.get_property('window').get_xid())
GObject.threads_init()
Gst.init(None)
GTK_Main()
Gtk.main()
When I run the code and provide the input(video location), I get an error suggesting that the installation is missing some plug-ins. Here is the error:
('Error: gst-core-error-quark: Your GStreamer installation is missing a plug-in. (12)', 'gsturidecodebin.c(1006): no_more_pads_full (): /GstPlayBin:player/GstURIDecodeBin:uridecodebin0:\nno suitable plugins found:\ngstdecodebin2.c(4565): gst_decode_bin_expose (): /GstPlayBin:player/GstURIDecodeBin:uridecodebin0/GstDecodeBin:decodebin0:\nno suitable plugins found:\nMissing decoder: MPEG-4 AAC (audio/mpeg, mpegversion=(int)4, framed=(boolean)true, stream-format=(string)raw, level=(string)2, base-profile=(string)lc, profile=(string)lc, codec_data=(buffer)1190, max-input-size=(int)380, rate=(int)48000, channels=(int)2)\nMissing decoder: H.264 (Baseline Profile) (video/x-h264, stream-format=(string)avc, alignment=(string)au, level=(string)5.1, profile=(string)baseline, codec_data=(buffer)01428033ffe1001267428033da00f0010fa560c0c0c0da1426a001000468ce06e2, max-input-size=(int)417991, width=(int)3840, height=(int)2160, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1)\n')
I tried installing the plug-ins as suggested in GStreamer docs with root permissions but the issue remains. It seems like a different procedure is required to install the plug-ins as I am accessing GStreamer from PyGObject. I have searched everywhere possible but haven't found any indications regarding this.
My question: How can I make this code work?
My system: Python 3.5.2 Ubuntu 16.04 gi.version : '3.20.0' Gst version: 1.0
Upvotes: 1
Views: 1143
Reputation: 1285
The package ubuntu-restricted-extras
depends on gstreamer1.0-plugins-bad
, gstreamer1.0-plugins-ugly
and gstreamer1.0-libav
. The latter contains two AAC decoders:
libav: avdec_aac: libav AAC (Advanced Audio Coding) decoder
libav: avdec_aac_fixed: libav AAC (Advanced Audio Coding) decoder
Upvotes: 0
Reputation: 47
I will try to put this answer as "technically correct" as possible; edits are welcome.
Turns out that PyGObject accesses the system-wide plug-ins installed for GStreamer. So this means that apt-get install
ing the plug-ins as suggested in GStreamer docs should have worked, but didn't and I still don't understand why.
However, I realized that these plug-ins also get installed with ubuntu-restricted-extras package so I did a sudo apt-get install ubuntu-restricted-extras
and no I no more see the error.
Upvotes: 0