Ask Your Question

(python) VideoCapture() returns zero for all CV cap props

asked 2016-09-08 04:13:10 -0500

Hello everybody,

I am trying to create a plot as overlay in my video (uisng openCV and matplotlib). The first thing would be to detect the frames of the video. This is what I am trying to do:

cap = cv2.VideoCapture('C:/PyDev/workspace/MyProject/src/files/video.mp4')
pos_frame = cap.get(

Using the debugger, the variable cap hold the value

 VideoCapture: <VideoCapture 000000000425D310>

but the value of pos_frame is 0.0.

I already tried other videos and other formats. Also I installed the K-Lite Codec Pack. Unfortunately it didn't help. I don't really understand if the video is loaded successfully (I think yes, as cap is not empty). Also calling


retuns False.

Does anyone know how to solve this problem?

edit retag flag offensive close merge delete


Not sure what you did here VideoCapture: <VideoCapture 000000000425D310>, but did you already tried visualising the frames first?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-08 04:49:45 -0500 )edit

1st thing: please check, if your video was loaded: cap.isOpened() == True

(the VideoCapture object itself will always be valid, video loaded or not)

berak gravatar imageberak ( 2016-09-08 05:01:29 -0500 )edit

@StevenPuttemans: This is just the value of the cap variable during runtime. I can't visualize the frames, as the video seems not to be loaded correctly. @berak: Thanks, I tried it and isOpened() returns False. Which means there is a problem loading the video. The path is correct. What else could I try?

user7761 gravatar imageuser7761 ( 2016-09-08 05:11:01 -0500 )edit

to rule out a codec issue, could you try one of the vids from opencv/samples/data ? e.g. the 768x576.avi ?

(if that works, you know, it's a mp4 problem, and you have to hunt for codecs to install.

berak gravatar imageberak ( 2016-09-08 05:17:07 -0500 )edit

Thank you very much @berak. By using the sample video I could find out, that this is a codec problem. Installed K-Lite Codec Pack and Windows 7 Codec Pack but unfortunetaly it didn't help. Can you give an advice, in which direction i should go with my research?

user7761 gravatar imageuser7761 ( 2016-09-08 05:36:10 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-09-08 06:09:56 -0500

I converted the video to avi using the following ffmpeg command: ffmpeg -i input.mp4 -c:v libxvid output.avi. It works fine now. Many thanks for the help!

edit flag offensive delete link more


My video is already in .avi but still same problem. I can read the first frame and display it however cv2.CAP_PROP_FRAME_COUNT returns 0.0

Akanksha Rathore gravatar imageAkanksha Rathore ( 2019-02-25 06:15:25 -0500 )edit

Question Tools

1 follower


Asked: 2016-09-08 04:12:04 -0500

Seen: 2,204 times

Last updated: Sep 08 '16