I. Installation

sudo apt-get install ffmpeg

II. First Way Use

This way the video is cut and converted into a gif.

  1. Cut the video to be in accordance with the duration we want:

    ffmpeg -i original.mp4 -ss 00:03:20 -c copy -t 00:00:30 output.mp4
    

    Notes:

    • -i: Input file.
    • original.mp4: Video name.
    • -ss: Create video from minute 00:03:20.
    • -t: Video duration is 30 seconds.
    • output.mp4: Name of new video.
  2. Change the video whose duration we have set into a Gif.

    ffmpeg -i original.mp4 -r 15 -vf scale=512:-1 -loop 0 Switch.gif
    

    Notes:

    • -r 15: amount of FPS, the higher the value, the clearer it will be, but the size of the gif file becomes large. The recommendations are 5, 10, dan 15.
    • vf scale=512:-1: Create GIF with height 512 px and weight following the ratio. The recommendations are 512, dan 320.
    • -loop 0: Create Infinite Loop.

III. Second Way Use (Alternative)

In this way the video is not cut, but converted into a collection of png/jpg in one directory and converted to GIF.

  1. Install imagemagick:

    sudo apt-get install imagemagick
    
  2. Create video become png/jpg:

    mkdif frames
    ffmpeg -i video.mp4  -r 5 'frames/frame-%03d.png'
    

    Note:

    • %03d: Create number for sequential naming.
  3. Create png/jpg become gif:

    cd frames
    convert -resize 20% -delay 20 -loop 0 *.png myimage.gif
    

    Notes:

    • -resize 20%: To reset the size of the gif can also be replaced with 768x576.

Bibliography