无法使用 Gstreamer 为两个摄像头设置参数-Python

Unable to set parameters for two cameras using Gstreamer-Python

我正在尝试使用 Gstreamer(Python3) 同时为两个相机设置相机参数(曝光和增益)。我使用相机序列 ID 创建了两个单独的管道,然后遵循用于单个(唯一)相机管道的方法。但是,在执行我的脚本时,仅为其中一个摄像机设置了参数。下面的代码中有什么我应该修改的吗? TIA.

#!/usr/bin/env python3


import time
import sys
import gi

gi.require_version("Tcam", "0.1")
gi.require_version("Gst", "1.0")

from gi.repository import Tcam, Gst


def main():

    Gst.init(sys.argv)  # init gstreamer

    serial1='05020863'
    serial2='05020864'

    pipeline1 = Gst.parse_launch("tcambin name=source1"
                                " ! video/x-raw,format=BGRx,width=720,height=540,framerate=30/1"
                                " ! tee name=t"
                                " ! queue"
                                " ! videoconvert"
                                " ! ximagesink"
                                " t."
                                " ! queue"
                                " ! videoconvert"
                                " ! avimux"
                                " ! filesink name=fsink1")

    pipeline2 = Gst.parse_launch("tcambin name=source2"
                            " ! video/x-raw,format=BGRx,width=720,height=540,framerate=30/1"
                            " ! tee name=t"
                            " ! queue"
                            " ! videoconvert"
                            " ! ximagesink"
                            " t."
                            " ! queue"
                            " ! videoconvert"
                            " ! avimux"
                            " ! filesink name=fsink2")

    if serial1 is not None:
        camera1 = pipeline1.get_by_name("source1")
        camera1.set_property("serial", serial1)

    if serial2 is not None:
        camera2 = pipeline2.get_by_name("source2")
        camera2.set_property("serial",serial2)

    file_location1 = "/home/pandey/TIS/tiscamera/examples/python/tiscamera-save-stream-1.avi"
    file_location2 = "/home/pandey/TIS/tiscamera/examples/python/tiscamera-save-stream-2.avi"

    camera1 = Gst.ElementFactory.make("tcambin")
    camera2 = Gst.ElementFactory.make("tcambin")

    camera1.set_state(Gst.State.READY)
    camera1.set_tcam_property("Exposure Auto", False)
    camera1.set_tcam_property("Gain Auto", False)

    camera2.set_state(Gst.State.READY)
    camera2.set_tcam_property("Exposure Auto", False)
    camera2.set_tcam_property("Gain Auto", False)

    camera1.set_tcam_property("Exposure Time",10)
    camera1.set_tcam_property("Gain",450)

    camera2.set_tcam_property("Exposure Time",10)
    camera2.set_tcam_property("Gain",450)


    fsink1 = pipeline1.get_by_name("fsink1")
    
    fsink1.set_property("location", file_location1)

    fsink2 = pipeline2.get_by_name("fsink2")
    
    fsink2.set_property("location", file_location2)


    pipeline1.set_state(Gst.State.PLAYING)

    pipeline2.set_state(Gst.State.PLAYING)




    print("Press Ctrl-C to stop.")

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        pipeline1.set_state(Gst.State.NULL)
        pipeline2.set_state(Gst.State.NULL)


if __name__ == "__main__":
    main()

您的问题在这里:

camera1 = Gst.ElementFactory.make("tcambin")
camera2 = Gst.ElementFactory.make("tcambin")

您为什么要创建 2 个完全独立于您的管道的新元素并将它们准备好?您应该只使用(就像您之前正确使用的那样)

camera1 = pipeline1.get_by_name("source1")
camera2 = pipeline1.get_by_name("source2")

获取对管道中实际元素的引用。