Skip to content

Instantly share code, notes, and snippets.

@gka
Last active June 23, 2025 23:20
Show Gist options
  • Select an option

  • Save gka/148bbad67871fa6ca8d0b97e4eee94b5 to your computer and use it in GitHub Desktop.

Select an option

Save gka/148bbad67871fa6ca8d0b97e4eee94b5 to your computer and use it in GitHub Desktop.

Revisions

  1. gka revised this gist Aug 20, 2016. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions make-animated-gifs-using-ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,14 @@
    Make sure ffmpeg is up-to-date:
    ```
    brew update
    brew upgrad ffmpeg
    brew upgrade ffmpeg
    ```

    Convert a MOV into frames. Tweak the `2/1` if you want more or fewer frames.

    ```
    mkdir frames
    ffmpeg -i screen-recording.mov -r 2/1 frames/%03d.png
    ```

    Optional: crop the frames to 600x400px using 824,690 as top/left
    @@ -15,13 +22,13 @@ convert ??.png -crop 600x400+824+690 cropped/
    Create the pallete.gif

    ```sh
    ffmpeg -i cropped/%02d.png -vf palettegen pallete.png
    ffmpeg -i cropped/%02d.png -vf palettegen palette.png
    ```

    Aaaand create the GIF. The `6*PTS` is added to slow down the GIF frames.

    ```sh
    ffmpeg -v warning -i cropped/%02d.png -i pallete.png -lavfi "paletteuse,setpts=6*PTS" -y out.gif
    ffmpeg -v warning -i cropped/%02d.png -i palette.png -lavfi "paletteuse,setpts=6*PTS" -y out.gif
    ```

    Bonus tip: if you want the last frame to have a longer duration, just copy your last frame image a bunch of times and use new frame numbers as filename.
  2. gka renamed this gist Aug 17, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion readme.md → make-animated-gifs-using-ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,6 @@ copy 20.png 21.png
    copy 20.png 22.png
    copy 20.png 23.png
    copy 20.png 24.png
    ```
    ```

    Sources: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
  3. gka revised this gist Aug 17, 2016. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,17 @@ Create the pallete.gif
    ffmpeg -i cropped/%02d.png -vf palettegen pallete.png
    ```

    Aaaand create the GIF
    Aaaand create the GIF. The `6*PTS` is added to slow down the GIF frames.

    ```sh
    ffmpeg -v warning -i cropped/%02d.png -i pallete.png -lavfi "paletteuse,setpts=6*PTS" -y out.gif
    ```

    Bonus tip: if you want the last frame to have a longer duration, just copy your last frame image a bunch of times and use new frame numbers as filename.

    ```sh
    copy 20.png 21.png
    copy 20.png 22.png
    copy 20.png 23.png
    copy 20.png 24.png
    ```
  4. gka created this gist Aug 17, 2016.
    25 changes: 25 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    Make sure ffmpeg is up-to-date:
    ```
    brew update
    brew upgrad ffmpeg
    ```

    Optional: crop the frames to 600x400px using 824,690 as top/left

    ```sh
    mkdir cropped
    convert ??.png -crop 600x400+824+690 cropped/
    ```

    Create the pallete.gif

    ```sh
    ffmpeg -i cropped/%02d.png -vf palettegen pallete.png
    ```

    Aaaand create the GIF

    ```sh
    ffmpeg -v warning -i cropped/%02d.png -i pallete.png -lavfi "paletteuse,setpts=6*PTS" -y out.gif
    ```