1

I using Python 2.7 and OpenCV 2.3.1 (Windows 7).

I try opening a video file:

stream = cv.VideoCapture("test1.avi")
if stream.isOpened() == False:
print "Cannot open input video!"
exit()

But I have warning:

warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394)

If use video camera (stream = cv.VideoCapture(0)), this code works.

Any ideas as to what I'm doing wrong?

1
  • most likely the file could simply not be found because the script ran in a Current Working Directory that is different from the directory containing the video file. I base this assertion on the fact that OpenCV has had a built-in AVI demuxer for a long time, so if that had been a valid AVI file, VideoCapture would not have proceeded to let ffmpeg have a try with that input. -- minimal reproducible example lacks detail on the video file. warning message looks incomplete to me. OpenCV v2.x long term support has ended many years ago. any value this question could have had in 2012 has long dissipated. Commented Aug 30 at 11:52

3 Answers 3

2

Try using cv.CaptureFromFile() instead.

Copy this code if you must: Watch Video in Python with OpenCV.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there any other easier way to do this?
This is the easier way.
"CaptureFromFile" looks like it used to be part of some very ancient Python adaptation of OpenCV's old API. this API has not been available in a long long time.
1

you can use the new interface of OpenCV (cv2), the object oriented one, which is binded from c++. I find it easier and more readable.

note: if your open a picture with this, the fps doesn't mean anything, so the picture stays still.

import cv2
import sys

try:
    vidFile = cv2.VideoCapture(sys.argv[1])
except:
    print "problem opening input stream"
    sys.exit(1)
if not vidFile.isOpened():
    print "capture stream not open"
    sys.exit(1)

nFrames = int(vidFile.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)) # one good way of namespacing legacy openCV: cv2.cv.*
print "frame number: %s" %nFrames
fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)
print "FPS value: %s" %fps

ret, frame = vidFile.read() # read first frame, and the return code of the function.
while ret:  # note that we don't have to use frame number here, we could read from a live written file.
    print "yes"
    cv2.imshow("frameWindow", frame)
    cv2.waitKey(int(1/fps*1000)) # time to wait between frames, in mSec
    ret, frame = vidFile.read() # read next frame, get next return code

Comments

-1

As from this answer, try copying all the .dll files from your OpenCV installation into C:\Python27.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.