Converting MP4 to GIF inside shell on Centos7

If for any reason you need to convert video MP4 into GIF – you most likely gonna hit tons of links talking about FFMPEG doing the job. And it really does it, no doubt and no problem with that. Except few, that I was able to solve. 🙂

  • size of the output file is usually quite big;
  • when uploading result file to sites, like vk.com, which converts it back to MP4 – for some reason you loose frame rate and quality drops.

I was able to reduce output GIF image by 2-2.5 times comparing to the one, produced by bare ffmpeg and was able to solve problem with uploading result GIF to social media website by using small utility gifify. You will still need to install ffmpeg, imagemagick and lossy.

FFMPEG must be compiled with libass and fontconfig (both are availabled through yum repository)

ImageMagick must be compiled with fontconfig support.

Install and run gifify

# install npm
yum install npm

# install gifify
npm install -g gifify

# convert MP4 to GIF
# FPS=30
# Compression 50 (0 - no compression, 100 - maximum)
# resize original video to 520px width, keeping proportion
gifify --colors 255 --compress 50 --fps 30 --resize 520:-1 input.mp4 -o gifify-resized520.gif

No worries, if you will miss something, gifify will let you know! And if you fail to install all requirements, feel free to ask me and I will be glad to do it for you.

Thank you AskUbuntu for that.

Leave a Reply

Your email address will not be published. Required fields are marked *