I'm trying to read, do some processing and then save an .mp4 video using OpenCV in python, but cap.get(cv2.CAP_PROP_FPS) returns the wrong FPS for some videos.
So I'm not gonna go in to the full details of what the code does, because its irrelevant to the problem at hand. I've noticed the output video from my program plays too fast, and when debugging I decided to just see how it looks when I simply playback the input video.
So the playback code looks something like this:
cap = cv2.VideoCapture(video_path)
video_fps = cap.get(cv2.CAP_PROP_FPS)
#returns 49.8
while cap.isOpened():
ret, frame = cap.read()
if ret:
cv2.imshow('a', frame)
cv2.waitkey(int(1000/video_fps))
else:
break
But the video plays too fast, so I go right click -> properties -> details, and sure enough it says frames per seconds: 49... but I know most of my videos are 25 fps (which is about half of 49.8), so just out of curiosity I change the delay to twice as much: cv2.waitkey(int(2000/video_fps))
And suddenly the video plays in perfect speed.
Another oddity is that when I divide the result of cap.get(cv2.CAP_PROP_POS_FRAMES) by the length of the video in seconds, I get yet again 49.8 and since I know the length must be correct, I can only guess that OpenCV gets the number of frames wrong (?)
So my questions are:
1) What the hell is going on here?
2) Is there a better\more reliable way to check video fps and frame count?