Monday, October 17, 2011
Creating Movies in MATLAB
To convert the MATLAB movie matrix into MPEG format you will require the MPGWRITE program. This program is freely available from the MATLAB Central download archive. Once downloaded, MPGWRITE need decompression, compilation and placing in the MATLAB path.
However this program was written for MATLAB 5.1 and has certain bugs, which can be fixed as below to work with higher versions of the MATLAB.
First of all you might encounter an error like below:
Error bitio.c: 112 syntax error; found `IOtime' expecting `;'
To fix this add #include “time.h” in bitio.c file
Next you might get an error
??? Error using ==> mpgwrite
All movie frames must have the same size
Higher Versions of MATLAB (higher than 7) produces 25% of frames with different dimensions.
Assuming that the first frame size is correct you can use the below piece of code to fix the above issue:
[r1,c1,s] = size(M(1).cdata);
for i = 2:length(M)
[rk,ck] = size(M(i).cdata);
if (rk~= r1 | ck ~=c1)
M(i).cdata = M(i).cdata(1:r1, 1:c1,:);
Where M is your Matlab movie file.
It works very well once you figure out how to compile it.