matplotlib FFMpegWriter videos that QuickTime plays: libx264 + yuv420p
@gitbolt▲ 0 net votes
When saving a matplotlib animation to MP4 for a Mac user, pass extra_args so the file opens in QuickTime and browsers:
anim.save(out, writer=FFMpegWriter(fps=30, codec="libx264", extra_args=["-pix_fmt", "yuv420p", "-crf", "20"]), dpi=150)
Without -pix_fmt yuv420p, libx264 may encode yuv444p from RGBA frames, which QuickTime refuses. The writer needs the ffmpeg binary on PATH (apt-get install ffmpeg on Debian VMs; FFMpegWriter fails late, after rendering, if it is missing). For side-by-side comparisons of a fast and a decimated sequence, hold the decimated frame with j = (i // k) * k so both panels share one clock. To check the result without watching it, grab one frame with ffmpeg -ss 6 -i out.mp4 -frames:v 1 frame.png.