【问题标题】:TypeError: unknown type GstFractionTypeError:未知类型 GstFraction
【发布时间】:2020-09-08 15:17:13
【问题描述】:

我正在尝试将 Gstreamer 与 python 绑定一起使用,以便在我的系统上搜索可用的摄像头。因此,我想获取具有相应功能(宽度、高度、帧率...)的设备列表。

Gstreamer 提供了非常有用的名为 Gst.DeviceMonitor 的类来获取可用设备。但是,我在尝试从发现的设备中提取功能时遇到了问题。具体来说,我只是在获取 "pixel-aspect-ratio""framerate" 能力方面遇到了麻烦,它们都是 Gst.Fraction 类型.

这是一个最小的代码示例:

import gi

gi.require_version('Gst', '1.0')
from gi.repository import Gst

Gst.init(None)

caps = Gst.Caps.from_string('video/x-h264,width=640,height=480,framerate={30/1, 20/1, 15/1, 1/1}')
structure = caps.get_structure(0)

width = structure.get_int('width').value
height = structure.get_int('height').value
framerates = structure.get_list('framerate').array

print('width = ', width)
print('height = ', height)
for i in range(framerates.n_values):
    print(' - framerate = ', framerates.get_nth(i))

最后一行抛出如下异常:

TypeError: unknown type GstFraction

我发现here 有人在 2012 年遇到过类似的问题,但我没有找到任何解决方案。有人有什么建议吗?

PS:我使用的是Python 3.5.5Gstreamer 1.14.5

【问题讨论】:

    标签: python-3.x gstreamer gstreamer-1.0 python-gstreamer


    【解决方案1】:

    您的代码在 Ubuntu 18 上运行良好:

    $ python3 --version
    Python 3.6.9
    
    $ gst-inspect-1.0 --version
    gst-inspect-1.0 version 1.14.5
    
    
    width =  640
    height =  480
     - framerate =  30/1
     - framerate =  20/1
     - framerate =  15/1
     - framerate =  1/1
    

    所以它可能是 Python GStreamer/GObject 自省绑定中的一个错误。

    【讨论】:

    • 我已将 Python 更新到 3.8.6。我之前运行了示例代码,但仍然遇到相同的错误。我也尝试过使用 Python 3.6.9(就像你一样),结果还是一样。唯一的区别是我使用的是 Ubuntu 20。你有什么其他建议可能会有所不同吗?
    【解决方案2】:

    我遇到了完全一样的问题,终于找到了解决办法:安装包python3-gst-1.0:

    sudo apt install python3-gst-1.0
    

    我很惊讶没有该软件包其他所有东西都能正常工作。

    【讨论】:

      猜你喜欢
      • 2016-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 2018-01-02
      • 2014-04-10
      • 2014-08-17
      • 2020-11-19
      • 1970-01-01
      相关资源
      最近更新 更多