How to resolve MATLAB Problem With "aviread" or "VideoReader" command, while reading the avi file? (Unable to locate decompressor to decompress video stream)

Very often while doing our projects in image/video processing we require our MATLAB to read the video file for us. For that we use "aviread" & "VideoReader" commands, but in 50% (or may be 80%) of the cases when the video file is not an example file of MATLAB (i.e., its a downloaded file from internet or captured from a camera), its Compressed with a codec which is not supported by MATLAB. And it throws an error like..."Unable to locate decompressor to decompress video stream".

So how to resolve this issue..?
There are many ways:

1. Using a codec to re-compress the video file, with the codec supported by your matlab.

2. Use of RAW video while importing. RAW video means it is not compressed by any of the codecs, so the decompression of the same is not required. Thus MATLAB will be able to open the video file, without searching for the video codecs.

# To decompress your video file to a RAW video, first download FFMPEG application from sourceforge.net (click on the link).
# After downloading the archived file, say you extracted to the drive root D:\. Though not necessary to extract the FFMPEG to drive root you can extract it any folder, but it is advised since its a command line tool & keeping it in root of the drive will reduce the command size & likewise your work.
# suppose in the location there is the avi file that you require to open in MATLAB, of whose name is "v1.avi". (Which was previously unable to open in MATLAB.)
# open the command line through typing "cmd" in the run window.
# then type:    ffmpeg -i v1.avi -vcodec rawvideo v2.avi
#After the necessary processing, a new video file "v2.avi" will be created. Which is much larger in terms of file size than the initial as it is uncompressed.
#now use the new video file in the MATLAB. It should now be read, without any error.


Screenshots:
Use Of FFMPEG to decompress the video file
Use Of FFMPEG to decompress the video file
Command line view while decompressing theVideo thorugh FFMPEG command line tool
Command line view while decompressing theVideo thorugh FFMPEG command line tool


6 comments:

Getting The Lists All Available Video Compressors(CODECS) For Usage With "avifile" or "videowriter" in Matlab- While creation of .avi file in MATLAB

While creating the video file through MATLAB software you must know the video CODECS (compressors specifically) that will be used by MATLAB to create that. The video may be created by using image frames or direct recording by the camera device, in any case the video compressors will be used (exception: RAW Video files).

Command To Be Used:
getfourcc
--> It will return the Four Character Code (abbreviated here as cc) followed by the codec description & the dll file the codec will use.

Sample run:
>> getfourcc
  Four CC  | Description  (Driver / DLL)
-----------+---------------------------------------------- -----
  mrle       |  Microsoft - Run Length Encoding(msrle32.dll)
  msvc       |  Microsoft - Video 1(msvidc32.dll)
  i420       |  Intel - Indeo 4 codec(iyuv_32.dll)
  uyvy       |  Microsoft - UYVY(msyuv.dll)
  yuy2       |  Microsoft - YUY2(msyuv.dll)
  yvyu       |  Microsoft - YVYU(msyuv.dll)
  iyuv       |  Intel - Indeo(iyuv_32.dll)
  yvu9       |  Toshiba Video Codec(tsbyuv.dll)
  cvid       |  Supermac - Cinepak(iccvid.dll)
  tscc       |  TechSmith Screen Capture Codec(tsccvid.dll)

Here, the 4 character code like "mrle", "i420", can be used in the function "avifile" or "videowriter" can be used to specify the MATLAB, which codec to be used during compression. Otherwise it will use the default one (depending on your settings & codec availability).

NOTE: If this command is not working in your MATLAB version, go to the following link & download the file.
Extract the .m file from the downloaded archive & run, it will return the result much similar to my own sample run.


If you need more video compressors,  install one of the CODEC pack available freely on internet.

1 comments: