Search code examples
pythonopencvffmpegvideo-streamingrtsp

Reading from RTSP stream via opencv+ffmpeg results in "method SETUP failed: 501 Not Implemented"


I have a camera setup and running in my local network. I can see the video stream via VLC without any issues. Now I am trying to run the following code to also observe the stream with python + opencv.

I am using:

  • Python 3.11
  • opencv-python 4.8.1.78
import cv2

cap = cv2.VideoCapture(
    "rtsp://192.168.234.127:8554/h264", 
)

while cap.isOpened():
    status, frame = cap.read()
    
    cv2.namedWindow("frame", cv2.WINDOW_NORMAL)
    cv2.imshow("frame", frame)
    
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

This results in the script being stuck at cap.read() with the following error occuring in the background: [rtsp @ 0000020008b7cd40] method SETUP failed: 501 Not Implemented. Note that cap.isOpened() returns True.

I tried:

  • downgrading to Python 3.11 from 3.12
  • running this in jupyter notebook
  • running this directly from script
  • force reinstalling opencv-python
  • using "rtsp://192.168.234.127:8554/jpeg" instead of "rtsp://192.168.234.127:8554/h264"
    • note that both methods work in the VLC player

edit:

  • simplified code, same result.

Solution

  • Http error 501 - The request method is not supported by the server and cannot be processed. Try check your server, camera. Try use http with mp4 or like it.