Answer the question
In order to leave comments, you need to log in
What video codec should be used to record video from an IP camera?
What is the best video codec to use to be able to record from an IP camera?
The video format can be .avi, you can also .mp4, you just need to choose a video codec, because the video does not work.
The video file is created but is 1, 0, or 6 KB in size (for .avi). Tried several different ones but didn't work. Tried XVID, DIVX, etc.
cap = cv2.VideoCapture('http://IP:Port/video')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
Answer the question
In order to leave comments, you need to log in
I figured it out on my own when I was looking for the same problems from others.
It turned out that it was necessary that the frame size was calculated from the camera's ability to record video with preservation, and not specified in the code.
I just had to change the number of frames, because. the video was accelerated many times, that is, for example, I shoot a video for 10 seconds, and the file is 1 second due to the large number in fps (it happened when fps = 20.0).
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = 6
out = cv2.VideoWriter(video1, fourcc, fps, (int(w),int(h)))
Try to make a question like this on the stack
import cv2
stream = cv2.VideoCapture('protocol://IP:port/1')
# Use the next line if your camera has a username and password
# stream = cv2.VideoCapture('protocol://username:[email protected]:port/1')
while True:
r, f = stream.read()
cv2.imshow('IP Camera stream',f)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question