5

I am on Windows and using Python 3.6.4. I've installed OpenCV (3.4) via pip. Here is the code I am using:

import numpy as np
import cv2

cap = cv2.VideoCapture('rtsp://192.168.15.116:554/onvif1')

while(cap.isOpened()):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

I am getting the following error:

[rtsp @ 03858a40] Nonmatching transport in server reply
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: rtsp://192.168.15.116:554/onvif1 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)

I can go to cmd and type

ffplay rtsp://192.168.15.116/onvif1

and the video will run as well as in VLC using the same rtsp address. Using

cv2.VideoCapture(0)

also works with my webcam.

I've tried copying the file "opencv_ffmpeg340.dll" into all path folders but to no avail. I've also checked build and all video I/O show up with "YES" except for Gstreamer. Any help would be appreciated. Thank you.

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45

2 Answers2

1

I installed OPENCV onto Windows 10 using Microsoft's VCPKG. After which, OPENCV worked fine - except it would not open videos files.

Without success, I tried many suggestions. Finally, what worked for me was very SIMPLE. I included opencv's BIN folder as a PATH in Windows Environment System Variables. That's it. Now, video files are opened and played just fine.

Lawes
  • 41
  • 4
  • When you say "video files" does that include (or better if exclusively) onvif rtsp videos? – Projetos Prince Tower Mar 09 '18 at 20:26
  • @ProjetosPrinceTower - Thank you for calling me out on this. I should have been more specific. My tests were successful with MP4, AVI, and RSTP. I tested RSTP videos using the following URL and it streamed in just fine. capVideo.open("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"); – Lawes Mar 13 '18 at 20:10
  • 2
    I see, unfortunately I can also run rtsp protocol with a video file specified like that. My issue is specifically with my onvif webcam. But thank you anyway, I'm sure it will be helpful to someone. – Projetos Prince Tower Mar 14 '18 at 21:22
0

I've just encountered this problem and after digging it looks like OPENCV 3.1+ defaults to TCP for the RTSP transport (my ESCAM QF600 only supports RTSP over UDP). You can prevent this from happening via setting the environment variable OPENCV_FFMPEG_CAPTURE_OPTIONS to something (e.g. dummy).

For completeness; see https://ffmpeg.org/ffmpeg-protocols.html for all options that can be set. Keys and values are separated with ';' and pairs are separated via '|'.

The offending code begins at line 809 in cap_ffmpeg_impl.hpp (https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_ffmpeg_impl.hpp)

Props to the following posts for sending me in the right direction:

ffmpeg rtsp error: Nonmatching transport in server reply

Cant get RTSP stream - nonmatching

  • Can you please give me some guidance on how to set that environment variable? Is it in the code, parameter when running the program, operational system? – Projetos Prince Tower Mar 14 '18 at 21:35
  • Hi, I was just experimenting with node+opencv on Windows so I just needed to do `set OPENCV_FFMPEG_CAPTURE_OPTIONS=dummy` on the command line before running my node app for it to work. If you're running an server application/service in python you could look into os.environ in the python os module to set it in your program if it's an issue setting in your OS. – Ben Thomas Mar 16 '18 at 06:26
  • I was wondering if this could be achieved in a python script before calling cv.VideoCapture – Vikram Dattu Apr 18 '18 at 08:05