“Nonmatching transport in server reply” when cv2.VideoCapture rtsp onvif camera, how to fix?

前端 未结 4 1789
滥情空心
滥情空心 2021-01-06 15:17

I\'m on windows 10 using python 3.6.4, installed opencv (3.4) through pip. Here\'s the code I\'m using:

import numpy as np
import cv2
cap = cv2.VideoCapture(         


        
4条回答
  •  醉梦人生
    2021-01-06 15:56

    To force the RTSP to use UDP insted TCP, you can change the enviroment variable OPENCV_FFMPEG_CAPTURE_OPTIONS.

    In C/C++ it can be done like that:

    #if WIN32
        _putenv_s("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp");
    #else
        setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", 1);
    #endif
    
    cap = VideoCapture("rtsp://192.168.0.100:554/onvif1", cv::CAP_FFMPEG);
    

    On Python, I think you can change the environment variable doing that:

    import os
    os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
    
    cap = cv2.VideoCapture("rtsp://192.168.0.100:554/onvif1", cv2.CAP_FFMPEG)
    

    I tested only the C++ solution, the Python one I'm not sure. Please test.

提交回复
热议问题