【问题标题】:How do I use the Discoverer module with pygi GstPbutils?如何将 Discoverer 模块与 pygi GstPbutils 一起使用?
【发布时间】:2012-07-04 07:40:29
【问题描述】:

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

【问题讨论】:

  • 你有没有想过如何完成这项工作?
  • 实际上从未这样做过。由于这个和其他一些问题,我最终从 gstreamer 切换到 vlc。

标签: python introspection gstreamer


【解决方案1】:

我成功使用了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

【讨论】:

  • This answer ROCKS :) 鉴于我们现在已经深入 Python3 时代,恕我直言,这应该是公认的,而不是我的
【解决方案2】:

这是一个通用 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

【讨论】:

猜你喜欢
  • 2021-12-26
  • 2012-10-18
  • 2018-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
  • 2015-12-27
相关资源
最近更新 更多