I have tried to analyze video files (avi files) using OpenCV Python. In particular, I tried to see the percentage of frames processed as specified in CAP_PROP_POS_AVI_RATIO
, which should return "Relative position of the video file: 0 - start of the film, 1 - end of the film."
However, when I try to put CAP_PROP_POS_AVI_RATIO
in the VideoCapture code as followed, the AVI_RATIO only return a fixed number of 0.05. When I change the avi file to others, the AVI_RATIO is different for different avi files, like 0.1 or 0.0285714285714 etc.
import numpy as np
import cv2
playvideo = cv2.VideoCapture('output.avi')
while(playvideo.isOpened()):
ret, frame = playvideo.read()
cv2.imshow('window', frame)
if cv2.waitKey(100) & 0xFF == ord('q'):
break
video_ratio = playvideo.get(cv2.CAP_PROP_POS_AVI_RATIO)
print(video_ratio)
video_frame = playvideo.get(cv2.CAP_PROP_POS_FRAMES)
print(video_frame)
playvideo.release()
cv2.destroyAllWindows()
The CAP_PROP_POS_FRAMES
on the other hand works fine, ie. returning the frame per iteration.
This is very strange. How come the cv2.CAP_PROP_POS_AVI_RATIO
is not giving the ratio, but a fixed number for a video file?