Converting .gif to web-safe .mp4 using ffmpeg

When recording animations for my posts I use a gif recorder. However, while not the most efficient format, .mp4 browser support is a little bit better than .webm so aside from generating .webm files, I also like to create fallback .mp4 files. This ffmpeg command converts a .gif to a more efficient .mp4 file:

ffmpeg -i file.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" file.mp4

The -px_fmt yuv420p and -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" are required for mobile browsers (mainly for mobile Safari from my experience) to be able to display the files.

Just in case the stackoverflow link ever goes away, this backup link explains it as well.