如何在opencv中同步两个gstreamer管线?

时间:2019-01-22 22:13:11

标签: python opencv gstreamer

当我通过控制台命令从摄像机接收视频流时,一切正常。两个视频流之间没有延迟。

命令:

gst-launch-1.0 udpsrc port=8086 caps = "application/x-rtp, media= 
(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload= 
(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink

但是当我尝试通过opencv进行相同操作时,我遇到了一个问题。 两个流之间的等待时间超过一秒钟,而且我还发现了一个可怕的错误(只有很短的灰度像素图片,没有很长时间)。

我的代码:

SERVER_PORT1 = 8086
SERVER_PORT2 = 8087

caps = """
    udpsrc port=%d
    caps = "
        application/x-rtp,
        media=(string)video,
        clock-rate=(int)90000, 
        ncoding-name=(string)H264, 
        payload=(int)96" ! 
    rtph264depay ! 
    decodebin ! 
    videoconvert ! 
    appsink"""

camL = cv2.VideoCapture(caps % SERVER_PORT1, cv2.CAP_GSTREAMER)
camR = cv2.VideoCapture(caps % SERVER_PORT2, cv2.CAP_GSTREAMER)

while True:
    # Capture frame-by-frame
    ret, imgL = camL.read()
    ret2, imgR = camR.read()

    if (imgL is not None and imgR is not None):
        cv2.imshow("Cam1", imgL)
        cv2.imshow("Cam2", imgR)

我还尝试通过视频混合器将两个视频流合并为一个视频捕获,但是没有任何变化。

caps = """
   videomixer sink_0::xpos=640 name=mixer
   ! videoconvert ! appsink
   udpsrc port=8086
   caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000,     encoding-name=(string)H264, payload=(int)96"
   ! decodebin ! videoconvert ! mixer.
   udpsrc port=8087
   caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96"
   ! decodebin ! videoconvert ! mixer."""

cap= cv2.VideoCapture(caps, cv2.CAP_GSTREAMER)

while True:
    # Capture frame-by-frame
    ret, img = cap.read()

    if (img is not None):
        cv2.imshow("Cam1", img)

如何解决?

0 个答案:

没有答案