VideoReader missing codec problem

I cannot open avi files with VideoReader on my MacBook (OS Ventura 13.5) with a pretty up-to-date version of MATLAB (R2023b; 23.2.0.2365128, 64-bit). When I try to open an avi file with the following code
v = VideoReader(vidFileName.avi)
I get the following error
Error using VideoReader/initReader
Unable to determine the required codec.
Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);
Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
Similarly, if I try to get information about the avi file, the code
info = mmfileinfo(vidFileName.avi)
returns the error
Unable to determine the required codec.
Some important points:
  • Yes, I know other people have posted similar problems. No clear solution to my problem is found there
  • Yes, this video file is valid and uncorrupted. It plays fine on VLC Player. It does not play on QuickTime, which does not support the avi format
  • Yes, I am aware that the solution might be "installing new codecs"--a solution mentioned in some other posts--but I need more information than that
Here's the deal: The MATLAB Central "solutions" mention installing codecs from mediaplayercodecpack.com...but that only support Windows systems. I tried installing 3rd party Mac codecs from 3ivx.com, but they didn't work. FWIW, they didn't allow QT to play avi files either, as it was supposed to do. I know nothing about video codecs, but teh interwebs tell me they are usually stored in Library/QuickTime on Macs. Sure enough, the 3ivx installation did add "3ivxVideoCodec.component" to that folder, but again, it doesn't work. The fact that VLC Player does work suggests that the necessary codec does exist somewhere on my Mac, but apparently MATLAB can't use it.
In closing, I pose these fundamental questions: Doesn't the MATLAB installation include the video codes required for the video formats VideoReader/VideoWriter supposedly supports? If yes, why am I getting this probelm? If no, where do I find the relevant codecs and how do I install them in a way that MATLAB can use?

2 Comments

Did you find a solution ?
No. The only solution I'm aware of, if you're running MATLAB on Mac, is to convert the video files to a format that Mac MATLAB will support using third-party software. There appears to be no way to add video codecs that MATLAB can use and Mathworks is not interested in addressing the problem.

Sign in to comment.

Answers (1)

Doesn't the MATLAB installation include the video codes required for the video formats VideoReader/VideoWriter supposedly supports?
No.
AVI is not a codec. AVI is a container file format. It contains blocks of data in a particular format, with each block tagged according to what kind of data it is. A single AVI can contain different sound blocks that might be encoded with different codecs.
codecs are "coder / decoders". Each codec is a different algorithm for encoding audio (or video).
In some cases the only difference is that there might be an older algorithm that is limited to 1 gigabyte or 2 gigabyte, and there might also be a newer version that uses longer length fields to permit larger files -- codecs are not necessarily hugely different.
But they can be very different -- there is, for example, a difference in what is needed for speech that has already passed through a phone line, compared to one of Neil Young's high-definition remastered audio files (somewhere around 22 bits per channel if I recall.)
To read a video file, any application must:
  • Recognize the container format (such as AVI).
  • Have access to the codec that can decode the video data stored in the file. Some codecs are part of standard Windows® and Macintosh system installations, and allow you to play video in Windows Media® Player or QuickTime®. In MATLAB, VideoReader can access most, but not all, of these codecs.
  • Properly use the codec to decode the video data in the file. VideoReader cannot always read files associated with codecs that were not part of your original system installation.
So... what you have is an AVI file that is created with a codec that is not common for MacOS. For example it might have used Indeo7 -- the creators of Indeo7 refused to create a 64 bit decoder for Indeo7.
You should use VLC to examine which codec is used by the AVI file; see https://superuser.com/questions/348159/vlc-how-do-i-see-video-files-information-resolution-encoding-information-e . You might possibly see just a 4 letter code that might have to e researched to find the name of the associated codec.
If no, where do I find the relevant codecs
There is no international standards organization that mediates use of the 4-character codec identifiers. Anyone can create a new codec and give it any arbitrary 32 bit code and start using it -- but people doing that would usually choose to avoid using any of the well-known codec codes. It is entirely permitted to create proprietary codecs -- to create AVI content that will only work with particular products. Or to create codecs that in practice have only been implemented on one operating system (there is no obligation of public disclosure of the source code for codecs.)
Taking into account these factors, it would be a practical impossibility for Mathworks to gather together all of the codecs that have ever been designed anywhere in the world, and provide drivers for all of them.

10 Comments

VLC identifies the codec as H264; it's not exactly exotic. How do I get MATLAB to use this codec to read this file?
Would it be possible to post a link to one of the AVI you are having trouble with?
MF
MF on 13 Nov 2023
Edited: Walter Roberson on 13 Nov 2023
I have included google drive links to clips of the video in question. As it turns out, the software used to make these clips encodes the video with a different codec (H264) than the original video (CRAM) by default. However, MATLAB on my Mac cannot open either version and returns the same error either way. MATLAB on a Windows machine (same MATLAB version--R2023b) can open both. On the Windows machine, mmfileinfo identifies the codec used in the clip and the original as H264 and CRAM, respectively, just as VLC does. Ultimately, I want to access CRAM-encoded video on my Mac, since re-encoding the terabytes of video I have to analyze would be extremely time-consuming. Here are 3 google drive links to videos. The first is a clip with H264 encoding, the second is a clip (from a different video) with CRAM encoding (made with the video editor that made the H264 clip), and the third is a full-length unaltered video (~4 GB).
When I look around, I find a number of people saying that H.264 inside AVI mostly doesn't work. Some details at https://forum.videohelp.com/threads/381188-is-H264-on-AVI-a-hack . This probably explains why Apple removed AVI H.264 Quicktime capability somewhere around 2008.
CRAM appears to also be known as Microsoft Video 1, MSV1 . It is one of Microsoft's original codecs. I find indication that back in 2007 people were complaining they could not get CRAM encoded AVI to work properly on Windows ME...
"Should" MATLAB have included drivers to read all known codecs in AVI files? I don't think that would be a productive use of Mathwork's time (and expenses, since they'd have to pay patent usage fees for some of them.)
I suggest doing a VLC batch conversion.
Well, you're not leaving me any other choice. Somehow, this is not a problem for media players other than QuickTime.
Well, you're not leaving me any other choice.
Of course you have choices.
  • I downloaded and installed movavi... but for reasons unknown the interface was all in German. And the free version puts in watermarks; generally requires a paid license
  • mpeg streamclip is a 32 bit executable and does not work with modern MacOS
  • DivX Convertor was able to convert the avi to mp4; this was handled by the free license
  • Permute was able to convert the avi to mp4, and the process was quite fast; generally requires a paid license
I stopped testing after that.
The CRAM sample on your google drive required sending an access permission request, which I have done.
Reminder: I do not work for Apple. I do not work for Mathworks. I do not work for Microsoft. I do not work for whichever company it is that choose to use obsolete or broken video encodings for whatever equipment it is you are using. I do not work for whoever it is that made the purchase decision of that equipment. I am, in other words, not the person who left you with a narrow set of choices.
permute was able to handle the CRAM avi, but DivX was not able to handle it.
So you have at least two options: VLC and permute. And there might be additional options as well.
I appreciate your effort and apologize for being a bit sour about this situation. There is a remaining question that has not been answered here or in other threads posted by people with similar problems. Namely, if I did find a Mac codec for CRAM or some other video format, how would I get MATLAB to recognize it and use it?
The line of code that leads to the message about not finding the plugin is
devicePluginPath = matlab.internal.videoPluginManager('getPluginForRead',fileToRead);
but matlab.internal.videoPluginManager is built-in.
Looking at the comments in surrounding code, we see
% PluginManager is a singleton who's lifetime manages the lifetime
% of a BI2 file (matlab.internal.videoPluginManager). This BI2 function holds an
% instance of a C++ PluginManager.
%
% Note that the use of ~ for the obj parameter in most of the methods
% is done on purpose. Most of the methods in this class defer
% directly to a BI2 without using obj. These methods could
% be static, but we want to bind the lifetime of the BI2 data with
% to the lifetime of this class, so the Singleton pattern was chosen.
so it looks like the real work is deferred to some undocumented C++ plugin manager.
Maybe dropping an appropriate codec into /Library/QuickTime would work... I do not know.

Sign in to comment.

Categories

Find more on Software Development Tools in Help Center and File Exchange

Products

Release

R2023b

Asked:

MF
on 10 Nov 2023

Commented:

MF
on 31 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!