Live data from Hacker News

High quality GIF with FFmpeg

blog.pkh.me

71–80 of 131 posts

Re: High quality GIF with FFmpeg

#72

So it's using a simple Median Cut quantization... which is okay, but you can get great results using an octree quantizer, and without dithering. Dithering kills your compression savings in GIF so you'd want to avoid it if possible. In any case, you can see the difference a better quantizer makes here: http://www.leptonica.com/color-quantization.html

Any method that makes axis-aligned subdivisions (which includes both standard median cut and octree), even in a space like HSV, is going to be pretty suboptimal. There's probably been more sophisticated things done since I looked at this in the 1990's, but Xiaolin Wu's 1992 approach [1] works quite a bit better than both (including the 1991 Wu v2 implementation of an octree method linked elsewhere in this thread). It's based on recursive PCA, dynamic programming to assign colors along the principal axis, and K-means refinement in CIE L* u* v* coordinates. Not the fastest algorithm, but the topic is "high quality".

And you can still dither the image without completely destroying compression. You just have to use an ordered dither [2].

[1] Xiaolin Wu, "Color Quantization by Dynamic Programming and Principal Analysis", ACM Transactions on Graphics 11(4): 348-372, 1992. https://dl.acm.org/citation.cfm?id=146475

[2] https://xiphmont.livejournal.com/35634.html

Re: High quality GIF with FFmpeg

#73
post #70

There is no reason to create new content in .gif and not webm as of now. FFmpeg is really nice though.

I'm not going to tell you anything new here, but there are reasons to use GIF instead of video. WebM isn't supported on Safari & IE. H.264 isn't officially supported on Firefox (though I believe OS X and Window may now provide their own decoders that Firefox uses). To get a similar experience to GIF, you need two formats and it needs to be embedded in an HTML file using a tag. Compare that to the GIF experience, where you link to the image and it works the same way everywhere.

There simply is not a video-based standard that implies "short, silent, autoplayed, looped video" in the way that animated GIFs do. There are ways to approximate the behavior in HTML, but none of them are perfect in the way GIFs are.

Re: High quality GIF with FFmpeg

#74
post #50

Earlier quoted context omitted.

If only iOS (and Android?) allowed you to play inline videos the way you can on the desktop, and the way they play animated GIF's inline. Besides allowing us to adopt video throughout and save on bandwidth and have better video quality, this will be a huge productivity boost to developers: we can finally stop having the GIF vis JIF pronunciation debate.

Unless somebody's producing ads, why would he insist on having the video "inline like on the desktop" on the small screen of the mobile phone?

Yes, what kind of crazy designer would do that: https://news.ycombinator.com/item?id=4531088

Re: High quality GIF with FFmpeg

#75

ffmpeg is downright magical - just don't get caught using the one in the Ubuntu/Debian repositories. Compile your own ffmpeg if you have any need to do serious work; the Libav fork just isn't as capable. The reasons are obvious if you look into the development philosophies of the two projects. https://github.com/mpv-player/mpv/wiki/FFmpeg-versus-Libav

Use the version at http://deb-multimedia.org echo "deb http://www.deb-multimedia.org stable main non-free" > /etc/apt/sources.list.d/deb-multimedia.org.list apt-get -q update; apt-get -qy dist-upgrade apt-get -qqy install ffmpeg

I always build my own as, afaik, it's the only way to get full support for the more interesting codecs e.g. fdkaac & h265.

Re: High quality GIF with FFmpeg

#76
post #50

Earlier quoted context omitted.

Unless somebody's producing ads, why would he insist on having the video "inline like on the desktop" on the small screen of the mobile phone?

Because gifs already work that way on phones, and that's how users want it.

I never wanted any movable ads while trying to read something on the phone. Even less the movable the cat gifs. If something is not worth the click, it's certainly not worth to be inline in the text.

Re: High quality GIF with FFmpeg

#77
post #65

Earlier quoted context omitted.

Global support for h.264 video in the browser: over 90%. And on the desktop it's close to 100%. That's IMO just good enough.

That's not what I was referring to. Yes, technically videos are superior, no doubt. The nice thing about GIFs is though that they are treated like images by the browser and the OS. That makes them easier to handle by non-technical users (think imgur, Tumblr, etc.).

.mp4 is also well supported by modern operating systems. The only place where there's a problem would be a website which allows you to upload images but not videos.

I'm inclined to say that the enormous compression wins are worth getting the remaining stragglers to upgrade (both of the sites you mentioned already do this, for example, as do other common targets like Twitter, Facebook, etc.).

Re: High quality GIF with FFmpeg

#78
post #31

Earlier quoted context omitted.

Don't compile it just use the official binaries!

That's a good option if the official binaries support all the codecs you need and have all the correct hardware acceleration flags set for your particular CPU/GPU. That's ... theoretically possible, I suppose.

ffmpeg binaries come with all possible codecs and all possible CPU features. The first is actually bad, because it will do far more things than you've actually tested and can secure. (In fact, nobody on earth has tested most possible ffmpeg command lines.)

The second is the way almost all sensible x86 software should behave.

Re: High quality GIF with FFmpeg

#79
post #65

Earlier quoted context omitted.

Global support for h.264 video in the browser: over 90%. And on the desktop it's close to 100%. That's IMO just good enough.

That's not what I was referring to. Yes, technically videos are superior, no doubt. The nice thing about GIFs is though that they are treated like images by the browser and the OS. That makes them easier to handle by non-technical users (think imgur, Tumblr, etc.).

I just realised that imgur does not support webm. I thought it does. Thats kind of stupid. For other websites it'd be as simple as adding a mime type to the list of accepted uploads. Unfortunalty you are right, right now webm is still exotic.

Re: High quality GIF with FFmpeg

#80
post #47
post #38

Earlier quoted context omitted.

None that works with current browsers implantations, because they erroneous ignore no delay between frames and wait anyway. But that's a bug in the gif decoder, not a limitation of gif. OK, this is hairsplitting, but it illustrates how borken the state of gif is.

Maybe someone who cares about this should submit patches? All of the major browser engines are open-source.

> All of the major browser engines are open-source.

In a world where Internet Explorer is not a major browser.

Post reply on HN