我正在尝试将一些pygtk音乐播放器代码移植到使用gst的发现者模块的pygi。
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)
当我尝试运行此操作时,出现以下错误:
/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)
不幸的是,关于这个pygi模块的文档看起来有点稀疏。
答案 0 :(得分:3)
我使用以下代码成功使用了GstPbutils
模块(请注意,这使用了gstreamer的版本1.2
)
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')
我使用它获得如下所示的输出
$ 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
文档有点棘手,因为各种数据类型没有明确定义(例如GstDiscovererAudioInfo
);顺便说一句,你可以找到一些文档here
答案 1 :(得分:1)
以下是通用GST发现者调用的示例:
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]
编辑:如果您只想要标签,请使用this: