VideoCapture().read() return False, None for .avi except tree.avi

asked 2013-10-03 21:23:02 -0500

ricky gravatar image

updated 2013-10-04 00:43:38 -0500

Moster gravatar image
import numpy as np
import cv2
import sys
fn = sys.argv[1]
cam = cv2.VideoCapture(fn)
ret, img = cam.read()
while ret:
  cv2.imshow('detection', img)
  if (0xFF & cv2.waitKey(5) == 27) or img.size == 0:
    break
  ret, img = cam.read()

I tried running the above code for a sample .avi file in opencv/samples/c/ called tree.avi and the above code displays that sample video. But when I try the same script for any other .avi files no video is displayed. I tried:

print cv2.VideoCapture('myFile.avi').read()

which returned "False None". I have also tried the video.py sample script in /opencv/samples/python2. video.py displays the tree.avi file, but not my own .avi files. I am using python2.7.3 and OpenCV-2.4.6 on windows.

I don't think this is an encoding issue because I have been able to view my .avi files using Windows Media Player. Any help would appreciated. Thank you.

edit retag flag offensive close merge delete