Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How do I use the Discoverer module with pygi GstPbutils?

Writer Andrew Mclaughlin

I'm trying to port some pygtk music player code to pygi which uses gst's discoverer module.

from gi.repository import Gst, GstPbutils
def on_discovered(discoverer, ismedia): print("%s -- %s" %( discoverer.tags.get('title', 'Unknown'), discoverer.tags.get('artist', 'Unknown')))
Gst.init(None)
location = "file:///srv/Music/molly_hatchet-the_creeper.mp3"
discoverer = GstPbutils.Discoverer()
discoverer.discover_uri(location)
discoverer.connect('discovered', on_discovered)

When I attempt to run this I get the following error:

/usr/lib/python2.7/dist-packages/gi/types.py:43: Warning: g_object_get_qdata: assertion `G_IS_OBJECT (object)' failed return info.invoke(*args, **kwargs)
/usr/lib/python2.7/dist-packages/gi/types.py:43: Warning: g_object_ref_sink: assertion `G_IS_OBJECT (object)' failed return info.invoke(*args, **kwargs)
** (python:21482): CRITICAL **: pygobject_register_wrapper: assertion `PyObject_TypeCheck(self, &PyGObject_Type)' failed
/usr/lib/python2.7/dist-packages/gi/types.py:43: Warning: g_object_unref: assertion `G_IS_OBJECT (object)' failed return info.invoke(*args, **kwargs)

Unfortunately documentation on this pygi module seems a bit sparse.

2

2 Answers

I successfully used the GstPbutils module with the following code (note that this use version 1.2 of gstreamer)

if __name__ == "__main__": if len(sys.argv) < 2: print >> sys.stderr, "usage %s <filename>" % sys.argv[0] sys.exit(1) Gst.init(None) GObject.threads_init() discoverer = GstPbutils.Discoverer() discoverer.connect('discovered', on_discovered) info = discoverer.discover_uri(sys.argv[1]) # video info print '# video' for vinfo in info.get_video_streams(): print vinfo.get_caps().to_string().replace(', ', '\n\t') # audio info print '# audio' for ainfo in info.get_audio_streams(): print ainfo.get_caps().to_string().replace(', ', '\n\t')

with which I obtain an output like the following

$ python source.py 'file:///home/gipi/Videos/Adventure Time - Season 2/Adventure time - 1x24 - Heat Signature.mp4'
# video
video/x-h264 stream-format=(string)avc alignment=(string)au level=(string)4.1 profile=(string)high codec_data=(buffer)01640029ffe1001967640029ac5208014016ec04400000fa40002ee023c60c626001000668e88ecb22c0 width=(int)1280 height=(int)720 framerate=(fraction)24000/1001 pixel-aspect-ratio=(fraction)1/1 parsed=(boolean)true
# audio
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 rate=(int)48000 channels=(int)2

The documentation is a little tricky since the various data type are not defined explicitely (for example GstDiscovererAudioInfo); BTW you can find some documentation here

1

Here is an example of generic GST discoverer invocation :

import sys
import gobject
gobject.threads_init()
import pygst
pygst.require('0.10')
import gst
from gst.extend.discoverer import Discoverer
def on_discovered(discoverer, ismedia, infile): print '\non_discovered:', infile discoverer.print_info()
if __name__ == '__main__': if len(sys.argv) >= 2: print 'Audio file: %s ' % sys.argv[0] discoverer = Discoverer(sys.argv[1]) discoverer.connect('discovered', on_discovered, sys.argv[1]) # The MainLoop mainloop = gobject.MainLoop() gobject.idle_add(discoverer.discover) mainloop.run() else: print 'Usage: %s <input_file>' % sys.argv[0]

EDIT : If you just want the tags, use this :

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.