Skip to content

Instantly share code, notes, and snippets.

@CoolOppo
Last active May 17, 2025 10:18

Revisions

  1. CoolOppo revised this gist Oct 31, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    ImageMagick Video to GIF Optimization Summary
    ----------------------------------

    # [Source](https://usage.imagemagick.org/video/)

    A software developer who uses IM to create Movie GIFs, [Benoit
    Rouleau](http://software.benetonfilms.com/), in discussion with me, gave
    me a AVI video of a [plane flying
  2. CoolOppo revised this gist Mar 8, 2015. No changes.
  3. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ frames.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -93,7 +93,7 @@ that is different from frame to frame. A later example will make this
    </tbody>
    </table>
    This naturally results in 0 local color tables, and a file size of 1060471 bytes.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -148,7 +148,7 @@ animation.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -189,7 +189,7 @@ more detail as to why this happens.
    </tbody>
    </table>
    Which has 0 local color tables, and is 110866 bytes in size.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -225,7 +225,7 @@ does not produce a different pattern from one frame to the next.
    </tbody>
    </table>
    Which has 0 local color tables, and is 303037 bytes in size.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -307,7 +307,7 @@ until I had a figure that was just within the required 256 color limit.
    </tbody>
    </table>
    Which has 0 local color tables, is 660614 bytes in size, and 235 colors.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -360,7 +360,7 @@ very well.
    </tbody>
    </table>
    Which has 0 local color tables, is 531981 bytes in size, and 236 colors.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" width="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" width="160px" height="120px"></img></td>
    </tr>
    </tbody>
    </table>
  4. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ frames.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -93,7 +93,7 @@ that is different from frame to frame. A later example will make this
    </tbody>
    </table>
    This naturally results in 0 local color tables, and a file size of 1060471 bytes.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -148,7 +148,7 @@ animation.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -189,7 +189,7 @@ more detail as to why this happens.
    </tbody>
    </table>
    Which has 0 local color tables, and is 110866 bytes in size.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -225,7 +225,7 @@ does not produce a different pattern from one frame to the next.
    </tbody>
    </table>
    Which has 0 local color tables, and is 303037 bytes in size.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -307,7 +307,7 @@ until I had a figure that was just within the required 256 color limit.
    </tbody>
    </table>
    Which has 0 local color tables, is 660614 bytes in size, and 235 colors.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -360,7 +360,7 @@ very well.
    </tbody>
    </table>
    Which has 0 local color tables, is 531981 bytes in size, and 236 colors.</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" width="100%" height="100%"></img></td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" width="100%"></img></td>
    </tr>
    </tbody>
    </table>
  5. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ frames.
    </tr>
    </tbody>
    </table></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -93,7 +93,7 @@ that is different from frame to frame. A later example will make this
    </tbody>
    </table>
    This naturally results in 0 local color tables, and a file size of 1060471 bytes.</td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_cgc.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -148,7 +148,7 @@ animation.
    </tr>
    </tbody>
    </table></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_ugc.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -189,7 +189,7 @@ more detail as to why this happens.
    </tbody>
    </table>
    Which has 0 local color tables, and is 110866 bytes in size.</td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -225,7 +225,7 @@ does not produce a different pattern from one frame to the next.
    </tbody>
    </table>
    Which has 0 local color tables, and is 303037 bytes in size.</td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_od.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -307,7 +307,7 @@ until I had a figure that was just within the required 256 color limit.
    </tbody>
    </table>
    Which has 0 local color tables, is 660614 bytes in size, and 235 colors.</td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_od2.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
    @@ -360,7 +360,7 @@ very well.
    </tbody>
    </table>
    Which has 0 local color tables, is 531981 bytes in size, and 236 colors.</td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_opt.gif)</td>
    <td align="left"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" width="100%" height="100%"></img></td>
    </tr>
    </tbody>
    </table>
  6. CoolOppo revised this gist Mar 8, 2015. No changes.
  7. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ frames.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane.gif"><img src="http://www.imagemagick.org/Usage/video/plane.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -93,7 +93,7 @@ that is different from frame to frame. A later example will make this
    </tbody>
    </table>
    This naturally results in 0 local color tables, and a file size of 1060471 bytes.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_cgc.gif"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_cgc.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -148,7 +148,7 @@ animation.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_ugc.gif"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_ugc.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -189,7 +189,7 @@ more detail as to why this happens.
    </tbody>
    </table>
    Which has 0 local color tables, and is 110866 bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -225,7 +225,7 @@ does not produce a different pattern from one frame to the next.
    </tbody>
    </table>
    Which has 0 local color tables, and is 303037 bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_od.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -307,7 +307,7 @@ until I had a figure that was just within the required 256 color limit.
    </tbody>
    </table>
    Which has 0 local color tables, is 660614 bytes in size, and 235 colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_od2.gif)</td>
    </tr>
    </tbody>
    </table>
    @@ -360,7 +360,7 @@ very well.
    </tbody>
    </table>
    Which has 0 local color tables, is 531981 bytes in size, and 236 colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_opt.gif"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" alt="[IM Output]" /></a></td>
    <td align="left">![](http://www.imagemagick.org/Usage/video/plane_opt.gif)</td>
    </tr>
    </tbody>
    </table>
  8. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -359,7 +359,7 @@ very well.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_opt_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    Which has 0 local color tables, is 531981 bytes in size, and 236 colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_opt.gif"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
  9. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -224,7 +224,7 @@ does not produce a different pattern from one frame to the next.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_od_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    Which has 0 local color tables, and is 303037 bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    @@ -250,7 +250,7 @@ This specific video however only uses a small range of colors, mostly
    various shades of blue, so it doesn't actually use a lot of the colors
    provided by a general uniform colormap.

    In fact only ![](http://www.imagemagick.org/Usage/video/plane_od_ncolors.txt.gif)
    In fact only 31
    colors were used in the last video animation!

    This is extremely low, and as such also quite visible. But it also means
    @@ -279,7 +279,7 @@ use...
    <table>
    <tbody>
    <tr class="odd">
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2_find.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_find.txt.gif" alt="[IM Text]" /></a></td>
    <td align="left">235</td>
    </tr>
    </tbody>
    </table>
    @@ -306,7 +306,7 @@ until I had a figure that was just within the required 256 color limit.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_od2_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    Which has 0 local color tables, is 660614 bytes in size, and 235 colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
  10. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -153,8 +153,8 @@ animation.
    </tbody>
    </table>

    This animation has ![](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt.gif)
    local color tables, and as a result the animation is smaller or ![](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt.gif)
    This animation has 0
    local color tables, and as a result the animation is smaller or 704091
    bytes in size.

    The problem however is that you will often see a obvious and annoying
    @@ -188,7 +188,7 @@ more detail as to why this happens.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    Which has 0 local color tables, and is 110866 bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
  11. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 21 additions and 21 deletions.
    42 changes: 21 additions & 21 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,9 @@ over](http://www.imagemagick.org/Usage/video/plane.avi), to help us
    mutually explore IM video conversion techniques.

    However while the AVI itself is quite small, the uncompressed video is a
    massive ![](http://www.imagemagick.org/Usage/video/plane_avi_size.txt.gif)
    bytes in size, and involves ![](http://www.imagemagick.org/Usage/video/plane_avi_ncolors.txt.gif)
    colors, over ![](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt.gif)
    massive 6201996
    bytes in size, and involves 32448
    colors, over 107
    frames.

    <table>
    @@ -31,7 +31,7 @@ frames.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="./index_files/plane.gif"><img src="./index_files/plane.gif" alt="[IM Output]" /></a></td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane.gif"><img src="http://www.imagemagick.org/Usage/video/plane.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -43,19 +43,19 @@ problems exist, because the video uses very few colors to start with.
    This is not always the case, especially as GIF has 256 colors per frame
    limit.

    However the animation file is ![](http://www.imagemagick.org/Usage/video/plane_size.txt.gif)
    However the animation file is 1077859
    bytes in size, which while only 1/5th the size, due to color reduction
    and GIF pixel data compression, it is still rather large.

    Also if you study the resulting animation further you will find that of
    the ![](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt.gif)
    frames in the image, ![](http://www.imagemagick.org/Usage/video/plane_ctables.txt.gif)
    the 107
    frames in the image, 106
    frames had their own own separate [local color
    table](http://www.imagemagick.org/Usage/anim_opt/#colortables) added.
    That is each and every frame in the GIF animation required there own
    color index table. That is while each frame has less that 256 colors
    (due to the GIF format limitations), the whole animation is using a
    total of ![](http://www.imagemagick.org/Usage/video/plane_ncolors.txt.gif)
    total of 7525
    colors.

    Unfortunately the GIF format does not compress color tables, so all
    @@ -92,14 +92,14 @@ that is different from frame to frame. A later example will make this
    </tr>
    </tbody>
    </table>
    This naturally results in <a href="http://www.imagemagick.org/Usage/video/plane_cgc_ctables.txt"><img src="./index_files/plane_cgc_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and a file size of <a href="http://www.imagemagick.org/Usage/video/plane_cgc_size.txt"><img src="./index_files/plane_cgc_size.txt.gif" alt="[IM Text]" /></a> bytes.</td>
    <td align="left"><a href="./index_files/plane_cgc.gif"><img src="./index_files/plane_cgc.gif" alt="[IM Output]" /></a></td>
    This naturally results in 0 local color tables, and a file size of 1060471 bytes.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_cgc.gif"><img src="http://www.imagemagick.org/Usage/video/plane_cgc.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    As you can see the resulting animation has no extra local colortables.
    Instead IM generated a single global color table of ![](http://www.imagemagick.org/Usage/video/plane_cgc_ncolors.txt.gif)
    Instead IM generated a single global color table of 256
    of the 'best' colors based on all the frames in the animation.

    Unfortunately this also resulted in the pixel data not compressing as
    @@ -148,7 +148,7 @@ animation.
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="./index_files/plane_ugc.gif"><img src="./index_files/plane_ugc.gif" alt="[IM Output]" /></a></td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_ugc.gif"><img src="http://www.imagemagick.org/Usage/video/plane_ugc.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -188,8 +188,8 @@ more detail as to why this happens.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt"><img src="./index_files/plane_ugc_nd_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt"><img src="./index_files/plane_ugc_nd_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="./index_files/plane_ugc_nd.gif"><img src="./index_files/plane_ugc_nd.gif" alt="[IM Output]" /></a></td>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif"><img src="http://www.imagemagick.org/Usage/video/plane_ugc_nd.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -224,8 +224,8 @@ does not produce a different pattern from one frame to the next.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt"><img src="./index_files/plane_od_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_od_size.txt"><img src="./index_files/plane_od_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="./index_files/plane_od.gif"><img src="./index_files/plane_od.gif" alt="[IM Output]" /></a></td>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_od_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -279,7 +279,7 @@ use...
    <table>
    <tbody>
    <tr class="odd">
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2_find.txt"><img src="./index_files/plane_od2_find.txt.gif" alt="[IM Text]" /></a></td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2_find.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_find.txt.gif" alt="[IM Text]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -306,8 +306,8 @@ until I had a figure that was just within the required 256 color limit.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt"><img src="./index_files/plane_od2_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_od2_size.txt"><img src="./index_files/plane_od2_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt"><img src="./index_files/plane_od2_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="./index_files/plane_od2.gif"><img src="./index_files/plane_od2.gif" alt="[IM Output]" /></a></td>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_od2_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt"><img src="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2.gif"><img src="http://www.imagemagick.org/Usage/video/plane_od2.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
    @@ -359,8 +359,8 @@ very well.
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt"><img src="./index_files/plane_opt_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_opt_size.txt"><img src="./index_files/plane_opt_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt"><img src="./index_files/plane_opt_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="./index_files/plane_opt.gif"><img src="./index_files/plane_opt.gif" alt="[IM Output]" /></a></td>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_opt_size.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt"><img src="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_opt.gif"><img src="http://www.imagemagick.org/Usage/video/plane_opt.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>
  12. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 11 additions and 22 deletions.
    33 changes: 11 additions & 22 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,9 @@ over](http://www.imagemagick.org/Usage/video/plane.avi), to help us
    mutually explore IM video conversion techniques.

    However while the AVI itself is quite small, the uncompressed video is a
    massive [![[IM
    Text]](./index_files/plane_avi_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_size.txt)
    bytes in size, and involves [![[IM
    Text]](./index_files/plane_avi_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_ncolors.txt)
    colors, over [![[IM
    Text]](./index_files/plane_avi_frames.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt)
    massive ![](http://www.imagemagick.org/Usage/video/plane_avi_size.txt.gif)
    bytes in size, and involves ![](http://www.imagemagick.org/Usage/video/plane_avi_ncolors.txt.gif)
    colors, over ![](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt.gif)
    frames.

    <table>
    @@ -46,23 +43,19 @@ problems exist, because the video uses very few colors to start with.
    This is not always the case, especially as GIF has 256 colors per frame
    limit.

    However the animation file is [![[IM
    Text]](./index_files/plane_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_size.txt)
    However the animation file is ![](http://www.imagemagick.org/Usage/video/plane_size.txt.gif)
    bytes in size, which while only 1/5th the size, due to color reduction
    and GIF pixel data compression, it is still rather large.

    Also if you study the resulting animation further you will find that of
    the [![[IM
    Text]](./index_files/plane_avi_frames.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt)
    frames in the image, [![[IM
    Text]](./index_files/plane_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ctables.txt)
    the ![](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt.gif)
    frames in the image, ![](http://www.imagemagick.org/Usage/video/plane_ctables.txt.gif)
    frames had their own own separate [local color
    table](http://www.imagemagick.org/Usage/anim_opt/#colortables) added.
    That is each and every frame in the GIF animation required there own
    color index table. That is while each frame has less that 256 colors
    (due to the GIF format limitations), the whole animation is using a
    total of [![[IM
    Text]](./index_files/plane_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ncolors.txt)
    total of ![](http://www.imagemagick.org/Usage/video/plane_ncolors.txt.gif)
    colors.

    Unfortunately the GIF format does not compress color tables, so all
    @@ -106,8 +99,7 @@ This naturally results in <a href="http://www.imagemagick.org/Usage/video/plane_
    </table>

    As you can see the resulting animation has no extra local colortables.
    Instead IM generated a single global color table of [![[IM
    Text]](./index_files/plane_cgc_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_cgc_ncolors.txt)
    Instead IM generated a single global color table of ![](http://www.imagemagick.org/Usage/video/plane_cgc_ncolors.txt.gif)
    of the 'best' colors based on all the frames in the animation.

    Unfortunately this also resulted in the pixel data not compressing as
    @@ -161,10 +153,8 @@ animation.
    </tbody>
    </table>

    This animation has [![[IM
    Text]](./index_files/plane_ugc_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt)
    local color tables, and as a result the animation is smaller or [![[IM
    Text]](./index_files/plane_ugc_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt)
    This animation has ![](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt.gif)
    local color tables, and as a result the animation is smaller or ![](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt.gif)
    bytes in size.

    The problem however is that you will often see a obvious and annoying
    @@ -260,8 +250,7 @@ This specific video however only uses a small range of colors, mostly
    various shades of blue, so it doesn't actually use a lot of the colors
    provided by a general uniform colormap.

    In fact only [![[IM
    Text]](./index_files/plane_od_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_od_ncolors.txt)
    In fact only ![](http://www.imagemagick.org/Usage/video/plane_od_ncolors.txt.gif)
    colors were used in the last video animation!

    This is extremely low, and as such also quite visible. But it also means
  13. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -161,7 +161,8 @@ animation.
    </tbody>
    </table>

    This animation has ![](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt.gif)
    This animation has [![[IM
    Text]](./index_files/plane_ugc_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt)
    local color tables, and as a result the animation is smaller or [![[IM
    Text]](./index_files/plane_ugc_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt)
    bytes in size.
  14. CoolOppo revised this gist Mar 8, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -161,8 +161,7 @@ animation.
    </tbody>
    </table>

    This animation has [![[IM
    Text]](./index_files/plane_ugc_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt)
    This animation has ![](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt.gif)
    local color tables, and as a result the animation is smaller or [![[IM
    Text]](./index_files/plane_ugc_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt)
    bytes in size.
  15. CoolOppo created this gist Mar 8, 2015.
    397 changes: 397 additions & 0 deletions optimal-video-to-gif-imagemagick.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,397 @@
    ImageMagick Video to GIF Optimization Summary
    ----------------------------------

    A software developer who uses IM to create Movie GIFs, [Benoit
    Rouleau](http://software.benetonfilms.com/), in discussion with me, gave
    me a AVI video of a [plane flying
    over](http://www.imagemagick.org/Usage/video/plane.avi), to help us
    mutually explore IM video conversion techniques.

    However while the AVI itself is quite small, the uncompressed video is a
    massive [![[IM
    Text]](./index_files/plane_avi_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_size.txt)
    bytes in size, and involves [![[IM
    Text]](./index_files/plane_avi_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_ncolors.txt)
    colors, over [![[IM
    Text]](./index_files/plane_avi_frames.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt)
    frames.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">IM however has no real trouble converting this video into a GIF animation. However be warned that you will probably get some unsupported 'AVI chunk' errors, which can be ignored by using a &quot;<code>-quiet</code>&quot; <a href="http://www.imagemagick.org/Usage/basics/#controls">control setting</a>.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi plane.gif</code></pre></td>
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="./index_files/plane.gif"><img src="./index_files/plane.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    This used ImageMagick's the default [Color Quantization and
    Dithering](http://www.imagemagick.org/Usage/quantize/) methods, to
    produce a very reasonable conversion of the video. Very few color
    problems exist, because the video uses very few colors to start with.
    This is not always the case, especially as GIF has 256 colors per frame
    limit.

    However the animation file is [![[IM
    Text]](./index_files/plane_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_size.txt)
    bytes in size, which while only 1/5th the size, due to color reduction
    and GIF pixel data compression, it is still rather large.

    Also if you study the resulting animation further you will find that of
    the [![[IM
    Text]](./index_files/plane_avi_frames.txt.gif)](http://www.imagemagick.org/Usage/video/plane_avi_frames.txt)
    frames in the image, [![[IM
    Text]](./index_files/plane_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ctables.txt)
    frames had their own own separate [local color
    table](http://www.imagemagick.org/Usage/anim_opt/#colortables) added.
    That is each and every frame in the GIF animation required there own
    color index table. That is while each frame has less that 256 colors
    (due to the GIF format limitations), the whole animation is using a
    total of [![[IM
    Text]](./index_files/plane_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ncolors.txt)
    colors.

    Unfortunately the GIF format does not compress color tables, so all
    those extra color tables could be using up to:   256 colors \* 3 byte
    per color \* 106 frames;   or 81,408 bytes of file space. Not a lot for
    a 1Gbyte video but still an appreciable amount of space, especially as
    we optimize the video further.

    Added to this is that the animation will not GIF frame optimize very
    well. Not only because the background is moving (due to the camera
    panning upward), but also because IM used a [Error Correction
    Dither](http://www.imagemagick.org/Usage/quantize/#dither_error)
    (Hilbert Curve Dither), which produces a pseudo-random pattern of colors
    that is different from frame to frame. A later example will make this
    'dither noise' much more visible.

    #### Common Global Color Table

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">Here I <a href="http://www.imagemagick.org/Usage/anim_opt/#colortables">Generate a Single Global Color Table</a> for all the frames of the video.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi +map plane_cgc.gif</code></pre></td>
    </tr>
    </tbody>
    </table>
    This naturally results in <a href="http://www.imagemagick.org/Usage/video/plane_cgc_ctables.txt"><img src="./index_files/plane_cgc_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and a file size of <a href="http://www.imagemagick.org/Usage/video/plane_cgc_size.txt"><img src="./index_files/plane_cgc_size.txt.gif" alt="[IM Text]" /></a> bytes.</td>
    <td align="left"><a href="./index_files/plane_cgc.gif"><img src="./index_files/plane_cgc.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    As you can see the resulting animation has no extra local colortables.
    Instead IM generated a single global color table of [![[IM
    Text]](./index_files/plane_cgc_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_cgc_ncolors.txt)
    of the 'best' colors based on all the frames in the animation.

    Unfortunately this also resulted in the pixel data not compressing as
    well as it did before, as a stronger dither was required. The result is
    a slightly worse looking animation, that is roughly the same size as the
    previous.

    For this specific video of limited colors, I could even reduce the
    number of colors used even further say to only 64 colors without too
    many problems, producing an even smaller animation file size. This
    however is very dependent on the video sequence used, and may not look
    very good.

    Your own video may have a better result or worse result, especially when
    dealing with a video that uses a lot more colors and possibly multiple
    scenes.

    #### Universal Global Color Table

    The better way to generate a 'smaller' GIF animation is to just supply a
    general universal range of colors rather than generate the 'best' global
    color table for an animation. Use one that should work well regardless
    of what colors are present in the original video.

    Another reason for doing this is that you can make you video longer
    without serious detrimental effects on the color selection, or resorting
    local color tables for each frame. Each frame is dithered to the same
    color map, completely independently of what other frames are in the
    animation.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">Here I use a <a href="http://www.imagemagick.org/Usage/quantize/#332_colormap">'332' color map</a> which is usually regarded as being a very good standard colormap when no transparency is needed. I have often seen this colormap (or a 219 color <a href="http://www.imagemagick.org/Usage/quantize/#netscape">'web-safe' colormap</a>) used often in various video formats.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi -map colormap_332.png plane_ugc.gif</code></pre></td>
    </tr>
    </tbody>
    </table></td>
    <td align="left"><a href="./index_files/plane_ugc.gif"><img src="./index_files/plane_ugc.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    This animation has [![[IM
    Text]](./index_files/plane_ugc_ctables.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_ctables.txt)
    local color tables, and as a result the animation is smaller or [![[IM
    Text]](./index_files/plane_ugc_size.txt.gif)](http://www.imagemagick.org/Usage/video/plane_ugc_size.txt)
    bytes in size.

    The problem however is that you will often see a obvious and annoying
    'noise' in areas of constant color. This noise was also present in ALL
    the previous video animations. It is only now visible due to the use of
    a more universal, and thus more widely spread out color mapping.

    The noise is actually caused by the dithering of the reduced color set
    when regenerating the image. However, this produces a pseudo-random
    pattern of colors that changes from frame to frame, resulting in the
    appearance of background noise in the image. See [Problems with
    E-Dithers](http://www.imagemagick.org/Usage/quantize/#dither_prob) for
    more detail as to why this happens.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">We could just turn off the color dithering to remove the 'dither noise'...
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi \
    +dither -map colormap_332.png plane_ugc_nd.gif</code></pre></td>
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_ctables.txt"><img src="./index_files/plane_ugc_nd_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_ugc_nd_size.txt"><img src="./index_files/plane_ugc_nd_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="./index_files/plane_ugc_nd.gif"><img src="./index_files/plane_ugc_nd.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    The resulting animation is a very small 1/60th the size of the original
    animation, generally because of the large expanses of solid color
    producing extremely good pixel compression. But while it fixes the
    dither noise, and make for a very small file size, you get color banding
    instead, which is generally regarded as a very bad trade-off.

    #### Ordered Dithered Video

    The real solution is to use a different color dithering technique, which
    does not produce a different pattern from one frame to the next.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">For example here I used a <a href="http://www.imagemagick.org/Usage/quantize/#od_posterize">Ordered Dither using Posterized Color Levels</a> to dither the same universal <a href="http://www.imagemagick.org/Usage/quantize/#332_colormap">'332' colormap</a>.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi \
    -ordered-dither o8x8,8,8,4 +map plane_od.gif</code></pre></td>
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od_ctables.txt"><img src="./index_files/plane_od_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, and is <a href="http://www.imagemagick.org/Usage/video/plane_od_size.txt"><img src="./index_files/plane_od_size.txt.gif" alt="[IM Text]" /></a> bytes in size.</td>
    <td align="left"><a href="./index_files/plane_od.gif"><img src="./index_files/plane_od.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    The above also used the `+map` operator, to ensure that all the images
    use the exact same global color map (which the ordered dither already
    reduced to a maximum of 256 colors). As the number of colors is already
    optimal, the `+map` operator does no dithering, or color reduction.

    The resulting dither pattern is not random, and does not change greatly
    from one frame to the next. Thus the 'dither noise' has been remove from
    the animation resulting in a fixed color pattern from from to frame.

    The pattern is also very repetitive allowing much better compression.

    And finally as the color map is fixed, it should work reasonably well
    regardless of what video is used.

    #### Higher Quality Ordered Dithered Video

    This specific video however only uses a small range of colors, mostly
    various shades of blue, so it doesn't actually use a lot of the colors
    provided by a general uniform colormap.

    In fact only [![[IM
    Text]](./index_files/plane_od_ncolors.txt.gif)](http://www.imagemagick.org/Usage/video/plane_od_ncolors.txt)
    colors were used in the last video animation!

    This is extremely low, and as such also quite visible. But it also means
    that this particular animation can benefit from using a large number of
    'color levels' in the ordered dither operation, so as improve the
    overall quality.

    First however we need to determine how many color levels the animation
    can handle before it reaches the 256 color limit imposed by both the GIF
    file format and the global colormap re-mapping.

    The tricky part however is that you must determine these BEFORE you save
    the animation to the limited GIF format. And here is the command I
    use...
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet plane.avi -ordered-dither o8x8,23 -append -format %k info:</code></pre></td>
    </tr>
    </tbody>
    </table>

    <table>
    <tbody>
    <tr class="odd">
    <td align="left"><a href="http://www.imagemagick.org/Usage/video/plane_od2_find.txt"><img src="./index_files/plane_od2_find.txt.gif" alt="[IM Text]" /></a></td>
    </tr>
    </tbody>
    </table>

    Basically I increased and decreased the number of color levels to use,
    until I had a figure that was just within the required 256 color limit.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">I can then apply the discovered 'color level' choice to the plane animation.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert -quiet -delay 1 plane.avi \
    -ordered-dither o8x8,23 +map plane_od2.gif</code></pre></td>
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_od2_ctables.txt"><img src="./index_files/plane_od2_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_od2_size.txt"><img src="./index_files/plane_od2_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_od2_ncolors.txt"><img src="./index_files/plane_od2_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="./index_files/plane_od2.gif"><img src="./index_files/plane_od2.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    As you can see a very high quality, ordered dithered video was
    generated, which is on a par with the 'best colormap' global color map
    version we generated earlier, but also 1/3 smaller in size, while the
    'dither noise' is now much harder to see.

    Of course as the quality is so much higher, it does require a larger
    file size, as it doesn't compress as well as the low quality version.

    On the other hand you now actually have a good control over the quality
    vs file size trade-off in the form of the number of 'color levels' used.

    Just remember this technique is a *special case*, for an animation that
    does not use too many colors. And making the video longer by adding more
    frames will also add more colors, and thus require a reduction in the
    'color level' quality control.

    This is about the best method of color optimization I have yet seen for
    general GIF animations. It removes 'dither noise', provides some quality
    control, and retains the ability to use other GIF animation optimization
    methods, such as [Frame
    Optimization](http://www.imagemagick.org/Usage/anim_opt/#frame_opt).

    #### Compression (Transparency) Optimization

    Because this video uses a panning camera, the background of the video
    changes from frame to frame. This means the GIF animation will not
    [Frame Optimize](http://www.imagemagick.org/Usage/anim_opt/#frame_opt)
    very well.

    <table>
    <colgroup>
    <col width="50%" />
    <col width="50%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left">However we can still use a simple <a href="http://www.imagemagick.org/Usage/anim_opt/#opt_trans">Transparency Optimization</a> to further reduce the final size of the GIF animation.
    <table>
    <colgroup>
    <col width="100%" />
    </colgroup>
    <tbody>
    <tr class="odd">
    <td align="left"><pre><code> convert plane_od2.gif -layers OptimizeTransparency +map plane_opt.gif</code></pre></td>
    </tr>
    </tbody>
    </table>
    Which has <a href="http://www.imagemagick.org/Usage/video/plane_opt_ctables.txt"><img src="./index_files/plane_opt_ctables.txt.gif" alt="[IM Text]" /></a> local color tables, is <a href="http://www.imagemagick.org/Usage/video/plane_opt_size.txt"><img src="./index_files/plane_opt_size.txt.gif" alt="[IM Text]" /></a> bytes in size, and <a href="http://www.imagemagick.org/Usage/video/plane_opt_ncolors.txt"><img src="./index_files/plane_opt_ncolors.txt.gif" alt="[IM Text]" /></a> colors.</td>
    <td align="left"><a href="./index_files/plane_opt.gif"><img src="./index_files/plane_opt.gif" alt="[IM Output]" /></a></td>
    </tr>
    </tbody>
    </table>

    That is one extra color, a transparent color index, was added to the
    image, and any pixel that does not change the currently displayed color
    was made transparent. This in turn generates large segments of
    transparent areas in the original animation, as well as repeats of
    similar pixel sequences, which generates a improved LZW compression in
    the final GIF image.

    Not bad, the animation is now half that of the direct conversion to GIF,
    and still a reasonably high quality.


    *If you like to add to the above, discuss the techniques to further
    improve them, please contact me, or the IM forum. I am more than happy
    to hear about your views, techniques and discussions, or look at a
    specific video/animation problem you may have.*

    One such discussion is [Finding the "right levels" for quantization with
    anim GIF](http://www.imagemagick.org/Usage/forum_link.cgi?f=1&t=20081&p=79602).