UW | College of the Environment | School of Oceanography | Physical Oceanography
Parker MacCready : Home | Research | People | Classes | Publications | LiveOcean | Tools

Making Movies

Notes on how to get and use ffmpeg to make .mp4 movies from stacks of .png's

Krisen Thyng helped me with this. This is definintely the best tool I have found for making movies from model output. It works on my mac and my linux boxes, and can be automated as part of other code like python.

I think I already had it on my linux machine (fjord). On my mac I first had to get brew, using this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

then execute: brew install ffmpeg then "which ffmpeg" should give: /usr/local/bin/ffmpeg

As an example of how to use it, I put this alias in my .bashrc

alias make_movie='ffmpeg -r 8 -i plot_%04d.png -vcodec libx264 -pix_fmt yuv420p -crf 25 movie.mp4'

and here is a snippet from python code that calls it:

ff_str = ("ffmpeg -r 8 -i " + outdir + "plot_%04d.png -vcodec libx264 -pix_fmt yuv420p -crf 25 " + outdir + "movie.mp4")
os.system(ff_str)

these assume you have a folder full of .png plots with sequential names like plot_0001.png and so on. One quirk is that ffmpeg requires an even number of pixels in both directions. For some reason this is never a problem with matplotlib figures. When I had trouble with this in MATLAB I solved it with some formatting lines like:

set(gcf,'PaperPositionMode','auto');
set(gcf,'position',[100 100 1000.5 600]); % note the .5