使用python设置GStreamer Element属性

问题描述 投票:0回答:1

这个简单的Gstreamer应用程序无法使用python API

import pgi
pgi.require_version('Gst', '1.0')
from pgi.repository import Gst, GLib
import traceback

Gst.init([])

pipeline = Gst.Pipeline()
src = Gst.ElementFactory.make('videotestsrc', 'src')
sink = Gst.ElementFactory.make('autovideosink', 'sink')
pipeline.add(src)
pipeline.add(sink)
src.link(sink)
src.set_property("pattern", 0)

pipeline.set_state(Gst.State.PLAYING)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/Documents/mythic-projects/OKR_2019Q2/gstreamer_pipeline.py in <module>
     12 pipeline.add(sink)
     13 src.link(sink)
---> 14 src.set_property("pattern", 0)
     15
     16 pipeline.set_state(Gst.State.PLAYING)

~/Documents/mythic-projects/OKR_2019Q2/venv/lib/python3.6/site-packages/pgi/obj.py in set_property(self, name, value)
     73
     74         if not hasattr(self.props, name):
---> 75             raise TypeError("Unknown property: %r" % name)
     76         setattr(self.props, name, value)
     77

TypeError: Unknown property: 'pattern'

我可以确认命令行操作正常:

gst-launch-1.0 videotestsrc pattern=snow ! autovideosink

但API似乎与文档和教程不同。任何.set_property()操作都是如此。

例如http://lifestyletransfer.com/how-to-launch-gstreamer-pipeline-in-python/

我在Mac OSX,python3.6上运行,我安装了gstreamer,如下所示:Installing Gstreamer-1.0 on Mac OS X Mavericks(我也试过从.dmg安装,但结果是一样的)

python macos gstreamer
1个回答
0
投票

本教程使用import gi而不是import pgi。这可能会有所作为。

PGI页面https://github.com/pygobject/pgi说它没有维护,也应该使用PyGObject。

© www.soinside.com 2019 - 2024. All rights reserved.