5

我正在尝试将一些 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 模块的文档似乎有点稀疏。

4

2 回答 2

5

我通过以下代码成功使用了GstPbutils模块(注意这个使用版本1.2的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')

我得到如下输出

$ 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);顺便说一句,您可以在此处找到一些文档

于 2013-12-02T21:48:03.390 回答
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]

编辑:如果你只想要标签,使用这个

于 2013-08-11T03:28:53.757 回答