recipes : movies : How do I make a compressed .avi in Linux/Mac?

Problem

How do I make a compressed .avi in Linux/Mac?

Solution

On operating systems other than Windows, it can be tricky to get your MATLAB movie into a compressed avi file. The solution is make the avi as normal using VideoWriter:


aviobj = VideoWriter('myMovie.avi');
open(aviobj);
mov=randn(100,100,80); 
fig=clf;

for ii=1:size(mov,3)
  imagesc(mov(:,:,ii))
  axis equal off
  
  F=getframe(fig);
  writeVideo(aviobj,F);
end
close(fig);
close(aviobj);

Then compress the movie using the Unix ffmpeg command:

ffmpeg -i myMovie.avi -sameq /tmp/OUT.avi
mv /tmp/OUT.avi ./myMovie.avi
Discussion

If you want a different format, such as QuickTime, you can use this free video-conversion website.