JavaEar 专注于收集分享传播有价值的技术资料

OpenCV cap.get(cv2.CAP_PROP_FRAME_COUNT) returning -1

I recently setup opencv 3.0 for python on my ubuntu pc using the following tutorial

So I ran the following code to get the number of frames of an mp4 video

   import cv2

   cap = cv2.VideoCapture('vid.mp4')
   length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
   print length 

Strangely I get "-1" as output for "length". The video does infact load and I get accurate values for

   int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))  #480


   int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))   #640

so its a wonder why frame count doesn't work. Please Help.


  1. The problem was with the opencv build (as it also occured in c++). I ended up re-building my opencv and everything worked fine after