I once wrote a social media website and one optimization we had is we would take gifs, mark them for processing, have a celery task queue run this command, and replace the gif with a mp4.
Worked wonders. A few years later gifycat exploded and we were all kicking ourselves xD
`ffmpeg -i 6069b7c2057597000422abc7_original.gif -c:v libx264 -crf 30 -pix_fmt yuv420p output.mp4`
791 KB - :)