Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Tuesday, July 14, 2015 at 00:10

To easily convert a MP4 video into a GIF image, you can use ffmpeg and ImageMagick convert in Linux. First, you extract the video into frames in JPEG with ffmpeg. Second, you join all JPEG frames into a single GIF image with ImageMagick convert. I use MP4 format as example but you may use another as long as it is supported by ffmpeg. Below I explain the steps.

Extract the Video


  • Create a folder named frames in the same directory with your MP4 file.
  • Use command ffmpeg -i video_file_name.mp4  -r 5 'frames/frame-%03d.jpeg'. For example, see picture below.
  • Check frames folder. It should contains all frame images from the MP4. How many, it depends on your video size. 

Join All Frames


  • Use command convert frames/frame*.jpeg output.gif.
  • You get your GIF named output.gif in the same directory with your MP4. How long the process, depends on your processor.

Explanation

  • -r 5 in ffmpeg is option for FPS value. Bigger means better quality, but slow. Smaller means lower quality, but faster.
  • %03d is a variable for sequential number. It gives your JPEG frames sequential filename numbers in decimal form.
  • The convert command above is intended to unite all sequential JPEG images into single GIF image.
  • You may modify commands above my reading man ffmpeg and man convert to suite your needs. You will get many examples to try. Explore them yourself.