VideoReader missing codec problem

53 vues (au cours des 30 derniers jours)
MF
MF le 10 Nov 2023
Commenté : Walter Roberson le 14 Nov 2023
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?

Réponses (1)

Walter Roberson
Walter Roberson le 10 Nov 2023
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 commentaires
MF
MF le 14 Nov 2023
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?
Walter Roberson
Walter Roberson le 14 Nov 2023
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.

Connectez-vous pour commenter.

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by