Can't read an .avi file to matlab using VideoRead

AmyNerd picture AmyNerd · Apr 1, 2014 · Viewed 9.4k times · Source

Code:

A = aviread('firstAttempt_1395344631.avi');

Response:

Error using VideoReader/init (line 447)  
Failed to initialize internal resources.  

Error in VideoReader (line 132)  
            obj.init(fileName);  

Error in untitled (line 1)  
A = VideoReader('firstAttempt_1395344631.avi');  

Any suggestions? I can't use aviread, as I get the response:

Error using aviread (line 148)  
Only uncompressed AVI movies can be read on UNIX.  

Error in untitled (line 1)  
A = aviread('firstAttempt_1395344631.avi');  

Answer

Stephen picture Stephen · Feb 27, 2015

The issue is that while VideoReader supports compressed video, it doesn't support compressed video when run from Unix. If you use the (deprecated) aviread, it will give you this error message:

Error using aviread (line 147)
Only uncompressed AVI movies can be read on UNIX.

Fortunately, unix has good tools. You can use ffmpeg. On ubuntu linux, install with apt-get install ffmpeg, and on mac, if you have homebrew, then just brew install ffmpeg.

Then use ffmpeg to uncompress. Using the first reference I found on google (http://forum.doom9.org/archive/index.php/t-121280.html), something like this should work:

ffmpeg -i input.avs -an -vcodec rawvideo -y output.avi

I tried it myself, and the new file (say, output.avi) still doesn't work with aviread but now it does work with VideoReader. Easy!