How to make video from Matplotlib plots

First, you need to ensure that your plots are saved all with the same name pattern containing the frame number (starting at 1) which must be padded with zeros! For example, your plot should be named myplot_000001.png or myplot_0123. This can be done using, for example, using


06d pads the number (in the timestep variable) up to 6 digits in total.

Now, use ffmpeg like this to create the video:

ffmpeg -f image2 -framerate 25 -i myplots/myplot_%06d.png -vcodec libx264 -crf 22 video.mp4