MATLAB: How to play movies at a size different from the original using the MOVIE function within MATLAB

avibiggerenlargeMATLABmoviereduceresizesize;smallerspecify

The MOVIE function plays my movies at their original sizes. However, I want to change this size in order to fit them inside a GUI of specified size.

Best Answer

The ability to play an AVI-file of a specified size using the MOVIE function is not available in MATLAB.
To work around this issue, try resizing your AVI-file before using the MOVIE function. For example:
First, create a sample movie.
t = linspace(0,2*pi,40);
fact = 10*sin(t);
fig=figure;
set(fig,'DoubleBuffer','on');
mov = avifile('example.avi','compression','indeo5','fps',8)
[x,y,z] = peaks;
for k=1:length(fact)
h = surf(x,y,fact(k)*z);
axis([-3 3 -3 3 -80 80])
axis off
caxis([-90 90])
F = getframe(gca);
mov = addframe(mov,F);
end
close(fig)
mov = close(mov);
Second, resize the sample movie.
% read in the movie
mov = aviread('example.avi');
% reduce the movie by 2
factor = 2;
% get dimensions of example.avi
dims = size(mov(1).cdata);
% scale axes, flip ydir for IMAGE, set units to pixels
hf = figure;
ha = axes( ...
'units','pixels', ...
'position',[0 0 dims([2 1])./factor], ...
'nextplot','replacechildren', ...
'ydir','reverse');
axis(ha,'off');
% create new movie
newmov = avifile('newexample.avi','compression','none');
for i=1:length(mov)
% display movie frame by frame on resized axis
image(mov(i).cdata);
axis(ha,'tight')
% add frame to new movie
newmov = addframe(newmov,getframe(ha));
end
% create new movie file
newmov = close(newmov);