Ask Your Question
0

RTSP communication problem

asked Nov 15 '16

Bruno Leme gravatar image

updated Nov 15 '16

Hi,

It is my first question in this forum, after looking for a long time any solution. I'm using python 2.7 with OPENCV '2.4.13' (I already tried with 3.1) and I can't open streams. I already solved the ffmpeg problem (dll) and tried to run the local camera and after a local video with success.

could anyone help me? follow below code: PS: Windows 10, x86 rtsp link working (tried in the vlc player) ffmpeg working (tried to run a video in the code locally)

  import cv2, platform
#import numpy as np

cam = "http://192.168.11.146:81/videostream.cgi?rate=0&user=admin&pwd=888888"
#cam = 0 # Use  local webcam.

cap = cv2.VideoCapture(cam)
if not cap.isOpened():
    print("not opened")

while(True):
    # Capture frame-by-frame
    ret, current_frame = cap.read()
    if type(current_frame) == type(None):
        print("!!! Couldn't read frame!")
        break

    # Display the resulting frame
    cv2.imshow('frame',current_frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# release the capture
cap.release()
cv2.destroyAllWindows()

When I try to run I get back

      C:\Python27\python.exe C:/Users/brleme/PycharmProjects/opencv/main.py
not opened
!!! Couldn't read frame!
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

Process finished with exit code 0

image of the camera working in the browser image description

kind regards, Bruno

Preview: (hide)

Comments

...and the problem is ?

berak gravatar imageberak (Nov 15 '16)edit

sorry :-s...

well, after a long time (probably 3 minutes) it returns the error bellow (nothing was loaded)

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261
Traceback (most recent call last):
  File "C:/Users/brleme/PycharmProjects/opencv/karlos.py", line 18, in <module>
    cv2.imshow('frame',frame)
cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
Bruno Leme gravatar imageBruno Leme (Nov 15 '16)edit

^^ now please put that into your question

berak gravatar imageberak (Nov 15 '16)edit

1 answer

Sort by » oldest newest most voted
0

answered Nov 15 '16

berak gravatar image

updated Nov 15 '16

please make it a habit to check, if resources load properly, you should test:

if not cap.isOpened() # did we get a connection at all ?

and also, in your loop:

if ret == False  # the connection broke, or the stream came to an end

(in your case, you received an empty frame, and imshow() hates you :)

Preview: (hide)

Comments

Thank you for your reply. I changed my code for make it easier to understand and also did some tests. could you give me more tips?

Bruno Leme gravatar imageBruno Leme (Nov 15 '16)edit

if not cap is the wrong check

berak gravatar imageberak (Nov 15 '16)edit

updated...

well, I was checking the ffmpeg and trying to run in dos the:

ffplay http://192.168.11.146:81/videostream....

at least in the dos it recognize the & as an internal command. (would it be the source of the problem?)

[http @ 01ccbb60] HTTP error 401 Unauthorized 0KB sq=    0B f=0/0
http://192.168.11.146:81/videostream.cgi?rate=0: Server returned 401 Unauthorized (authorization failed)

'pwd' is not recognized as an internal or external command,
operable program or batch file.
Bruno Leme gravatar imageBruno Leme (Nov 15 '16)edit

if you want to use that url from cmdline, you have to escape it with " , like:

ffplay "http://192.168.11.146:81/videostream.cgi?rate=0&user=admin&pwd=888888"
berak gravatar imageberak (Nov 16 '16)edit

Question Tools

1 follower

Stats

Asked: Nov 15 '16

Seen: 7,078 times

Last updated: Nov 15 '16