列出可用于 gstreamer 1.0 中 ksvideosrc 视频捕获的设备名称

Sia*_*aie 5 c++ gstreamer

我正在尝试使用 c++ 中的 gstreamer 1.0 查询 Windows 上可用视频捕获设备(网络摄像头)的列表。

我使用 ksvideosrc 作为源,我能够捕获视频输入,但我无法查询可用设备(及其上限)的列表。

在 gstreamer 0.10 上,可以通过 GstPropertyProbe 实现,该功能在 gstreamer 1.0 中已被删除。文档建议使用 GstDeviceMonitor。但我也没有运气使用它。

有人成功获取设备名称列表吗?或者您能否建议另一种检索可用设备名称及其上限的方法?

nai*_*rhc 1

尽管我还没有弄清楚如何枚举设备名称,但我已经想出了一种解决方法,至少可以获取可用的ksvideosrc设备索引。下面是 Python 中的代码,但由于 GObject 自省绑定,您应该能够相当轻松地将其移植到 C++。

from gi.repository import Gst


def get_ksvideosrc_device_indexes():
    device_index = 0
    video_src = Gst.ElementFactory.make('ksvideosrc')
    state_change_code = None

    while True:
        video_src.set_state(Gst.State.NULL)
        video_src.set_property('device-index', device_index)
        state_change_code = video_src.set_state(Gst.State.READY)
        if state_change_code != Gst.StateChangeReturn.SUCCESS:
            video_src.set_state(Gst.State.NULL)
            break
        device_index += 1
    return range(device_index)


if __name__ == '__main__':
    Gst.init()
    print get_ksvideosrc_device_indexes()
Run Code Online (Sandbox Code Playgroud)

请注意,视频源device-name属性None自 Windows 上的 GStreamer 版本 1.4.5.0 起适用于ksvideosrc.