Ask Your Question
1

Unable to open some avi files in OpenCV-Python -- Why?

asked 2013-12-20 11:46:57 -0600

virsto gravatar image

updated 2013-12-21 04:37:47 -0600

I installed OpenCV vers. 2.4.7.2 on a Windows Vista (32-bit) platform, with no reported errors. Then the following file:

C:\opencv\build\python\2.7\x86\cv2.pyd

was moved to:

C:\python27\Lib\site-packages\

I have been testing openCV with both images and video (*.avi) files. I have no problems (yet) when working with images. However, I have found a problem when trying to open avi files. First, an example that works fine:

import cv2 
path = 'D:/Videos/'
video = 'julius.avi'   # this file can be obtained form me ([email protected])
vid = cv2.VideoCapture(path+video)
result = vid.isOpened()

[result returns True for this avi]

However, if I use

import cv2 
path = 'D:/Videos/'
video = 'toy_plane_liftoff.avi' # http://cinelerra.org/footage/
vid = cv2.VideoCapture(path+video)
result = vid.isOpened()

[result returns False for this avi]

Note, I have tried several other avi files (test avi's downloaded from the web) and most of them will not open. What can be done to open any "good" avi file? By good avi file I mean one that plays with Windows media player and VLC 2.1.2. I have two dll's in C:\opencv\sources\3rdparty\ffmpeg, opencv_ffmpeg.dll and opencv_ffmpeg_64.dll and I copied both of them to C:\python27 --- this did not solve the problem. Here is some information on the avi that works ok (julius.avi) and the one that does not open (toy_plane_liftoff.avi). For julius.avi: Codec: Microsoft Video 1 (CRAM), Resolution: 320x249, Frame rate: 15, Decoded format: 15 bits RGB. For toy_plane_liftoff.avi: Codec: Motion JPEG Video (MJPG), Resolution: 640x480, Frame rate: 25, Decoded format: Planar 4:2:2 YUV full scale.

edit retag flag offensive close merge delete

Comments

Unfortuantely I have not an answer here, but it seems that it is not a problem of python. I have the same problem with java, and C++. I can read none of the video files I tried in various formats. The author of this questoin kindly sent me the file julius.avi, and I can read this one. With java, and with C++.

Matthias gravatar imageMatthias ( 2013-12-21 02:51:38 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-12-21 07:19:28 -0600

Matthias gravatar image

I still cannot answer the question why, but I found a workaround which helps at least for now:

Download mplayer. This package contains also the program mencoder. Now take a video file (in.avi), and run this command:

mencoder.exe in.avi -nosound -ovc raw -vf format=i420 -o out.avi

out.avi will have no sound. If you need it, you can omit -nosound, but you will probably have to give another command line argument.

out.avi will be very large, but at least you can open it with OpenCV on Windows.

edit flag offensive delete link more

Comments

I found the solution for me: I set the OPENCV_DIR to the x86 directory of the libs. But in fact I used a x64 java. Changing the OPENCV_DIR solved the problem for me.

Matthias gravatar imageMatthias ( 2014-01-09 08:00:53 -0600 )edit

import cv2 cap = cv2.VideoCapture('m.avi') print cap.grab() this code always returns FALSE wheras when opening a video 'b.avi' which was captured by webcam using opencv it returns TRUE

soumyadeep gravatar imagesoumyadeep ( 2015-07-19 23:58:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-20 11:46:57 -0600

Seen: 9,583 times

Last updated: Dec 21 '13