Search code examples
pythonopencvrtsp

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


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("rtsp://192.168.0.100:554/onvif1")
while(True):
    ret, frame = cap.read()
    print(frame)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

[rtsp @ 0000016f6d5995a0] Nonmatching transport in server reply warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:834) warning: rtsp://192.168.0.100:554/onvif1 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:835)

But when I'm using ffmpeg code:

ffplay rtsp://192.168.0.100:554/onvif1 --> Capture oke
ffplay -rtsp_transport udp rtsp://192.168.0.100:554/onvif1 --> Capture oke
ffplay -rtsp_transport tcp rtsp://192.168.0.100:554/onvif1 --> Nonmatching transport in server reply

Can you help me, please?


Solution

  • As mentionned, I tried to put in the python code the following:

    import os
      os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;0"
    

    or

    import os
      os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
    

    or

    import os
      os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "dummy"
    

    unfortunately none was working as I was still running my program in the same cmd window.

    I simply opened a new cmd window and gave a try for a new run... and it works (with "rtsp_transport;0" :)