python cv2.VideoCapture does not open

Eyal S. picture Eyal S. · Jul 18, 2016 · Viewed 10k times · Source

I have a few avi files which I'm trying to read frame by frame. I have used opencv 3.1.0 in order to read frames:

import cv2
cap = cv2.VideoCapture(file_path)

and then I just read the frames of cap. This works fine on some of the videos. I took a few more videos recently and the same code comes up empty. I checked:

cap.isOpened() # return False

and it seems like the video is not opened properly. As far as I'm concerned the only thing that changed is that the new videos are in color whereas the old ones were not. I don't know how that would change anything in the code. I checked that the videos open up just fine in other software (imageJ) so I'm confident the video itself is not the issue.

Any ideas why the new videos are not opening properly? I have not been able to find any information on how to debug this issue. Any advice would be greatly appreciated.

Answer

Eyal S. picture Eyal S. · Jul 20, 2016

I switched to imageio instead of opencv and everything works well