Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Generated GIFs are very inefficient in space #31

Closed
ahmetb opened this issue Dec 18, 2017 · 13 comments
Closed

Generated GIFs are very inefficient in space #31

ahmetb opened this issue Dec 18, 2017 · 13 comments

Comments

@ahmetb
Copy link

ahmetb commented Dec 18, 2017

Take a look at this GIF, it goes on FOR MINUTES and it's only 32 kb:

https://github.com/tianon/gosleep/blob/master/example.gif

I'm curious why we can't we have this minimality with asciicast2gif? My 30 second recording is 964 kilobytes.

Is there a way to minimalize this? I don't care about antialiasing and all those fancy stuff making the image larger.

@publicarray
Copy link
Contributor

publicarray commented Dec 30, 2017

There are many factors to the file size. The example.gif is only 497×290 pixels, uses few colours, is short (~28 seconds) and has a low area of change between frames (easier to compress).

asciicast2gif already uses gifsicle to compress the output gif, but there are more options from gifsicle that you can try.

BTW the -S option in asciicast2gif is for up-scaling, you probably want to set it to 1.

@publicarray
Copy link
Contributor

You can also ask @tianon how the gif was generated.

@tianon
Copy link

tianon commented Dec 30, 2017

Was a pretty standard byzanz (https://github.com/GNOME/byzanz) recording -- nothing very custom there.

@publicarray
Copy link
Contributor

Thanks for chiming in. Cool project for GNOME users.

@tianon
Copy link

tianon commented Dec 30, 2017

Heh, I don't use GNOME -- I actually ran it inside a Docker container, and had a small wrapper script to grab the proper X, Y, width, and height for capturing the window I was interested in. It doesn't need more than the X11 socket in order to work. 👍

@ku1ik
Copy link
Contributor

ku1ik commented Feb 4, 2018

@ahmetb can you give us a link to your recording which ends up being 964kb gif? We can play with various arguments for asciicast2gif and for gifsicle.

@ahmetb
Copy link
Author

ahmetb commented Feb 5, 2018

@publicarray
Copy link
Contributor

I've played a little with ImageMagick and gifsicle

Command Size (KB) Savings (KB)
asciicast2gif 'https://asciinema.org/a/dD9UhCIaPw13znirhmGUnNJtd.cast?dl=true' out.gif 941 0
asciicast2gif 'https://asciinema.org/a/dD9UhCIaPw13znirhmGUnNJtd.cast?dl=true' out.gif -S 1 * 348 593
gifsicle --optimize -O3 --colors 16 -o out-16.gif out.gif 336 593+12
convert out.gif -coalesce -layers RemoveDups -layers RemoveZero -layers OptimizeFrame out-dedupe.gif 321 593+27
convert out.gif -coalesce -layers RemoveDups -layers RemoveZero -layers OptimizeFrame - | gifsicle --optimize -O3 -o out-dedupe-gifsicle.gif 259 593+89
convert out.gif -coalesce -layers RemoveDups -layers RemoveZero -layers OptimizeFrame - | gifsicle --optimize -O3 --colors 16 -o out-dedupe-16.gif 253 593+95
convert out.gif -coalesce -layers RemoveDups -layers RemoveZero -layers OptimizeFrame - | gifsicle --optimize -O3 --colors 6 --use-colormap=gray -o out-dedupe-bw.gif 175 593+173

* The scaled=1 gif is used as an input for all remaining commands

@ku1ik
Copy link
Contributor

ku1ik commented Feb 6, 2018

@publicarray awesome! That's very helpful.

Another things to try:

I'm thinking that maybe asciicast2gif could have a concept of "presets", probably 3 (low, normal, high) would be enough to cover everyone's needs. But before presets, I'd like to try the above.

@ahmetb
Copy link
Author

ahmetb commented Feb 6, 2018

It'd be really cool to script these into a separate tool, or bundle in the asciicast2gif tool?

@ku1ik
Copy link
Contributor

ku1ik commented Apr 5, 2018

I've implemented some optimizations:

  • the biggest impact on filesize was too high frame-rate - it's capped at 15fps now
  • added support for giflossy (if giflossy is installed instead of gifsicle the options passed to gifsicle command are extended with -lossy=80)

I've pushed new version to npm, and there's new image on Docker hub (docker pull asciinema/asciicast2gif if you previously pulled it).

You can set GIFSICLE_OPTS env var to override the options passed to gifsicle, which is great for experimenting with different color/optimization/lossyiness combinations.

@ku1ik
Copy link
Contributor

ku1ik commented Apr 5, 2018

I've generated gif from the asciicast linked by @ahmetb using latest (today's) version, with this command:

asciicast2gif -S 1 https://asciinema.org/a/dD9UhCIaPw13znirhmGUnNJtd.cast ahmetb.gif

Or Docker version:

docker run --rm -v $PWD:/data asciinema/asciicast2gif -S 1 https://asciinema.org/a/dD9UhCIaPw13znirhmGUnNJtd.cast ahmetb.gif

The resulting gif is 213kb, which is a good improvement over initial 964kb.

ahmetb

@ahmetb
Copy link
Author

ahmetb commented Apr 5, 2018

Thanks a bunch, that's a pretty good improvement!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants