How can I use the custom DIVX codec with AVIFILE and ADDFRAME in MATLAB 7.1 (R14SP3)?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 30 Apr 2021
I would like to create an AVI-file using the DIVX codec. However when I add a frame, I receive an error message.
In MATLAB 7.4 (R2007a), I receive this error
ERROR: ??? Failed to set stream format. Try specifying a different codec.
Error in ==> avifile.addframe at 226
avi('addframe',rot90(frame,-1), aviobj.Bitmapheader, ...
With MATLAB 7.3 (R2006b), I receive this error
ERROR: ------------------------------------------------------------------------
Segmentation violation detected at Mon Mar 19 15:34:04 2007
------------------------------------------------------------------------
Configuration:
MATLAB Version: 7.3.0.267 (R2006b)
<SNIP>
Stack Trace:
[0] AVIFIL32.dll:0x73b5608a(0, 1, 1, 0x171d9420)
[1] avi.mexw32:0x11001a0f(1, 0x1099ba80 "tmpmpg.avi", 1, 0x171d9420)
[2] avi.mexw32:0x11001429(0, 0x00d1e008, 9, 0x00d1e068)
[3] avi.mexw32:0x11001602(0, 0x00d1e008, 9, 0x00d1e068)
[4] libmex.dll:_mexRunMexFile(0, 0x00d1e008, 9, 0x00d1e068) + 119 bytes
[5] libmex.dll:private: void __thiscall Mfh_mex::runMexFileWithSignalProtection(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00d1e008, 9, 0x00d1e068) + 73 bytes
[6] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00d1e008, 9, 1) + 213 bytes
<SNIP>
Error in ==> avifile.addframe at 226
avi('addframe',rot90(frame,-1), aviobj.Bitmapheader, ...
Accepted Answer
MathWorks Support Team
on 30 Apr 2021
Edited: MathWorks Support Team
on 30 Apr 2021
This feature has been added in MATLAB 7.5 (R2007b) with the new MMREADER object.
The ability to write to a DIVX file is not available in previous versions of MATLAB.
You can work around this by specifying a custom compression format and ensuring that the input to the codec conforms to the standard.
The errors listed above are caused by the frame input not being of the size required by the codec.
In order to log the acquired data using the DivX codec you will needed to do the following.
1. Install the DIVX codec on your computer. This is a 3rd party codec which is available at
2. Modify "addframe.m" to recognize the DIVX codec as an MPEG-4 codec. This is required in order to resize any images to the proper size.
a. First make a backup of the ADDFRAME file. This can be done with the command:
copyfile([matlabroot,'\toolbox\matlab\audiovideo\@avifile\addframe.m'],[matlabroot,'\toolbox\matlab\audiovideo\@avifile\addframe.bak'])
b. Next open the file for editing with the command
edit addframe
c. Finally, modify the line
isMPG4 = any(strncmpi(codec, {'M4S2', 'MP43', 'MP42', 'MP4S', 'MP4V'}, 4));
to
isMPG4 = any(strncmpi(codec, {'M4S2', 'MP43', 'MP42', 'MP4S', 'MP4V','DIVX'}, 4));
3. Specify the compression property to be 'DIVX' when creating the AVIFILE object
aviobj = avifile('example.avi','compression','DIVX')
0 Comments
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!