Reputation: 11
So far I have used OpenCV for streamming ip camera from Raspberry pi + pi camera. I want to save the video from ip camera with codec H.264 and it didn't work. I find out from this post https://github.com/skvark/opencv-python/issues/100 which told me that only manually built opencv library would support H264 codec. So i followed this link to manually build opencv https://www.learnopencv.com/install-opencv3-on-ubuntu/ and succeeded. But when I use manually built opencv, I can no longer access my ip camera, the cap.open() always return None. Here is my code:
import cv2
cap = cv2.VideoCapture("http://10.10.1.240:8081/")
while True:
ret, frame = cap.read()
frame2 = cv2.flip(frame, 1)
cv2.imshow("frame2", frame)
key = cv2.waitKey(25)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
In the above code, ret is always False. I have been stucked in this for 2 days without a real solution and explaination. Any help would be appriciated, thanks!
Upvotes: 1
Views: 1603
Reputation: 802
Make sure the ip address of your computer and your camera are in the same subnet mask.
Upvotes: 0
Reputation: 263
But when I use manually built opencv, I can no longer access my ip camera, the cap.open() always returns none.
Have you tried, checking if your ip camera is working properly and present on your network after building opencv from source? Did you try to stream from the camera using any media player after installation off opencv from source?.
As far as your code is concerned, try the following format for cv2.VideoCapture
cap = cv2.VideoCapture()
cap.open("rtsp://yourusername:[email protected]:555/Streaming/channels/2/")
yourusername-username given to your ip camera. yourpassword-password for the given user name.
You can try the following as well.
cv2.VideoCapture("rstp://admin:[email protected]/doc/page/previw.asp")
Thanks.
Upvotes: 1