
Chromium: Add support for Animated PNG - maxst
https://chromium.googlesource.com/chromium/src/+/7d2b8c45afc9c0230410011293cc2e1dbb8943a7
======
Scaevolus
I've been waiting for this for 9 years :-)

A nice feature of APNG (and GIF) versus the more modern CSS/SVG animations is
the CPU efficiency. It's _really_ easy to accidentally waste a ton of battery
life by adding a tiny spinning gear to a page.

It varies depending on the browser and whether the GPU is used for
compositing, but it's much easier to optimize blitting a rectangle each frame
versus blitting a rotation of some complex vector shape on top of the page.

~~~
jacobolus
Animated GIFs often burn huge amounts of CPU on my machine. A page full of
GIFs can bring a modern computer to its knees. (This is one reason many image
sharing sites convert uploated GIFs to proper video files, mp4 or webm or
whatever.)

I’ve never quite understood why implementations of GIF viewers in web browsers
were so bad. In many cases it seems like they could cache every frame in GPU
memory somewhere and very cheaply loop them. Caveat: I haven’t studied this in
any detail, and am not an expert on image/video formats.

~~~
michaelbuckbee
While the browser vendors haven't done this - some of the image hosting sites
(who are far more directly affected) have.

Imgur automatically converts larger GIF files to "GIFV" (WebM or MP4). The
size difference is nuts: their example is a 50MB gif being reduced to 3.5MB

Their announcement post about it:
[http://blog.imgur.com/2014/10/09/introducing-
gifv/](http://blog.imgur.com/2014/10/09/introducing-gifv/)

~~~
Ezhik
It's such a mess though.

You have gif with all its quality loss (256 colors and etc.), and then to make
matters worse it's getting shoved through webm/mp4 encoding.

And then there's everyone from Imgur to Twitter missing the point of why gif
is even a thing. Because it is _simple_. Because gif is treated as an image
and not a video format. Because you can right click it, and save it for later
use. Can't do that with "gifv" (seriously, I had to use curl just to get the
video file from Imgur), and definitely can't do that with Twitter.

Neither webm nor mp4 can kill gif _yet_ \- mp4 is a patent mess, and webm
comes closer (4chan for example has a quite big SFW community of people
trading videos), but there are issues with Apple refusing to support it, and
lack of hardware support.

~~~
eriknstr
>Can't do that with "gifv" (seriously, I had to use curl just to get the video
file from Imgur), and definitely can't do that with Twitter.

youtube-dl works with basically everything that matters, including imgur gifv
and twitter videos.

    
    
      youtube-dl https://twitter.com/Footballogue/status/841905302438043648
    
      youtube-dl http://i.imgur.com/te50Z9W.gifv
    

youtube-dl is the best thing since sliced bread.

thanks to youtube-dl it is simple to download videos in a nice format instead
of as gif.

gif as a format has served it's purpose. let gif die.

~~~
Ezhik
That's not user-friendly at all.

~~~
versteegen
There are untold number of GUI and web wrappers around youtube-dl.

------
pjscott
In case anybody is wondering how to roll out server-side support for this with
a fallback to GIF: they've added "image/apng" to the Accept header for image
requests. It's now "image/webp,image/apng,image/ _,_ /*;q=0.8". Sites like
Imgur could start serving APNG images today.

~~~
MichaelApproved
> Sites like Imgur could start serving APNG images today

I think there'd be a problem when customers copy/paste an image from the site
into another application that doesn't support APNG. Seems like a common use-
case that would cause a lot of customer confusion.

~~~
__float
How is this worse than the "gifv" that Imgur introduced?

~~~
RKearney
gifv isn't a new file format at all. It's simply an mp4 video with gifv as the
extension.

~~~
__float
Exactly--but you can't reliably copy and paste it into another unknowing
application.

------
ksec
APNG started in 2004, I am not sure why it took so long, 13 years before it is
landed in Webkit and Blink / Chromium. The fight with MNG only lasted few
years. PNG rejected the APNG proposal multiple times ( Why ? )

This is 2017, and when we look forward to 2020, we still dont have anything to
replace gif, jpeg, apng, png. With Video we went from MPEG-1, MPEG-2, MPEG-4 (
Divx, Xvid, Rmvb, WMV, VP8 era ) H.264/AV to H.265/HEVC. Our Screen went from
Low Res to 4K.

Surely all these browser Vendor can sit down and at least talk about this. How
about supporting bpg for a start?

And lastly, I was naively thinking having APNG now would means x years before
it is roll out to large number of consumers. But to my surprise even Chrome
has a very high usage in China, 60% and growing. China is historically a
region of IE6, I remember IE was still 40 - 50% in 2013 or 2014. You could now
start to use APNG and soon have 60%+ of your users seeing it. Amazing.

~~~
gpvos
_> PNG rejected the APNG proposal multiple times ( Why ? )_

Because it is not a still image, and therefore should have a different file
signature, MIME type, and file name extension. It is simply out of scope for
PNG. When designing PNG as a replacement for GIF, they very deliberately and
decidedly dropped the animation feature. Implementing APNG as an extension of
PNG confuses categories that should not be confused.

~~~
aljungberg
You have to admit it's a little funny that if PNG's one goal in life was to
replace GIF, they chose to not support the one thing GIF is used for today.

You had one job PNG. One job!

~~~
gpvos
The popularity of animated GIFs, or the use at any scale of them at all
really, only came after PNG was finalized.

The design of PNG started in January 1995 and PNG 1.0 was published in October
1996. Netscape Navigator added animated GIF support in September 1995, and if
I remember correctly, it wasn't immediately used at large scale. Anyway, by
that time, the PNG team had IIRC already decided to put animation in a yet-to-
be-designed MNG.

~~~
aljungberg
And to be fair GIF was used in many many places where we now use PNG.

None the less, a funny end result.

------
paxcoder
So Firefox, Safari and now Chrome. Provided image hosting sites start
accepting APNG this may finally mean the end of GIF. Why now though?

~~~
jeroenhd
I assume Google wants to push their own image format (animated webp) instead
of supporting an old format nobody has been using for years.

This is good news though; finally we can start to abandon the cruddy old GIF
format and move to something more modern.

~~~
pornel
> something more modern.

Technically it is _more_ modern — replaces 1989 tech with 1995 tech.

But it's far from being modern. It's very lacking even compared to MPEG-1 from
1993.

~~~
Dylan16807
> It's very lacking even compared to MPEG-1

Not if you have aliased frames.

------
caio1982
Could anyone more familiar with the field explain why is this better than the
now-forgotten-well-i-guess MNG?

~~~
nayuki
It is said that the MNG decoder uses a few hundred kilobytes of code whereas
APNG reuses more code from the PNG library. APNG is sort of a hack where the
first frame is a normal PNG and subsequent frames are hidden in custom chunks.

[https://en.wikipedia.org/wiki/APNG](https://en.wikipedia.org/wiki/APNG)

[https://en.wikipedia.org/wiki/Multiple-
image_Network_Graphic...](https://en.wikipedia.org/wiki/Multiple-
image_Network_Graphics)

~~~
striking
It's not that the first frame is a normal PNG and that the rest of the frames
are hidden. That's close, but it's not exact.

PNGs are stored as files with multiple kinds of chunks inside. The relevant
one here is the IDAT chunk, which holds image data. Most PNGs have just one
IDAT, but APNGs carry multiple (one for each frame). Readers that don't care
about animating will simply display the first IDAT and stop reading there.

So it's a bunch of PNGs, coalesced into one, with some frame timing data. And
the code for reading them is tiny if you already have a PNG library, because
you display them like you would a regular PNG, but making sure to read out
every IDAT, at the speed denoted by the acTL and fcTL chunks.

~~~
TwoBit
Hopefully there's some delta compression between the frames. Or something
other than a dumb array of independent images.

~~~
Dylan16807
There's no true inter-frame compression, but frames layer on top of each other
by default. Unchanged areas can be transparent.

~~~
laurent123456
So a player is basically compositing many alpha-transparent images on top of
each others to create the video?

~~~
maxst
Something like that: [http://littlesvr.ca/apng/inter-
frame.html](http://littlesvr.ca/apng/inter-frame.html)

------
mindcrime
Sounds good, but I think they should add MathML support before this. It
strikes me as absurd that Chrome doesn't yet support MathML. :-(

------
usernam
When testing APNG for a local project last year which involved only Firefox, I
was trying to save some space and have better color support using APNG.

I found it to be quite buggy, slow, and even occasionally leading to crashes.
I switched to webp. APNG was never given enough love, despite being a very
useful format.

------
habitue
Benefits of apng vs. video?

~~~
pornel
Hard to find any. It's a primitive format ignoring 20 years of video
compression research. It tries to be replacement for GIF by repeating its
mistakes: it has very basic inter-frame compression, lacks motion vectors,
doesn't guarantee keyframes, RGB-only, and frame decoding isn't
parallelizable.

In 8-bit mode it supports even fewer colors than GIF (GIF can combine frames
to achieve thousands of colors), and in 24-bit mode it's larger than GIF.

For full-motion video it requires 10x-15x more data than VP9 to be
decompressed by the CPU, and there's no hardware acceleration.

[https://kornel.ski/efficient-gifs](https://kornel.ski/efficient-gifs)

There's false dichotomy between "animations" and "videos", mostly due to
historical reasons and that older codecs (and AWebP) used 4:2:0 subsampling
which made them blurry. VP9 supports alpha, 4:4:4 mode, and it's cheaper to
decode (it's more complex, but using 10x less data offsets that), so it'd be
best to forget that GIF and APNG ever existed.

~~~
dasfasf
Which makes the timing all the more inscrutable. AV1 is supposed to have its
bitstream finalized this month. Why now, when WebM is so widespread and there
are new formats on the horizon, resurrect APNG after neglecting it at the only
time it was relevant?

~~~
robterrell
APNG is the format Apple is using for sticker packs in iMessage. I'm gonna go
out on a limb and guess Google is ramping up to announce a sticker store for
Allo... sticker pack devs could port them over without any effort.

~~~
aorth
What is a sticker pack and why do you need to buy them?

~~~
maxst
It's serious business.

[http://www.ubergizmo.com/2016/06/line-270m-a-year-sticker-
sa...](http://www.ubergizmo.com/2016/06/line-270m-a-year-sticker-sales/)

------
mdf
APNG is great, but animated FLIFs[1] would be even better. Looks like many of
their former todos have been completed, and from the remaining ones, only
three are related to the file format per se. Hopefully these, too, get
completed in time. Although, seems like getting support for new file formats
in browsers takes time...

[1] [http://flif.info/animation.html](http://flif.info/animation.html)

------
Sephr
Why? I thought animated WebP was superior in every aspect.

~~~
londons_explore
It is, but WebP has lots of politics involved since it is closely related to
WebM, and there are staunch non-supporters of that.

I would hazard a guess this is getting implemented now to try to make WebP
look worse.

~~~
haldean
Why would Google implement something in their own browser to make their own
image format look worse?

------
quasarj
Fucking finally! I've been following this bug for at least 5 years. 5 years
ago, when it was first proposed, this could have been a big deal. Not sure
these days.. but I sure would love to see GIFs disappear..

------
tropo
I'd like all formats for both IMG and VIDEO tags.

The gif animations are really video. They play in IMG tags; they are silent
and do not have video controls. Put them in VIDEO tags and they ought to get
video controls.

Putting a proper video format in an IMG tag should work like an animated gif
does: silent, without video controls.

A plain image is a 1-frame video. It should work in a VIDEO tag, just to keep
things consistent and orthogonal and all. A 1-frame video is an image; it
should work with an IMG tag.

------
janus24
If Edge follow we can almost use APNG in production
[http://caniuse.com/#feat=apng](http://caniuse.com/#feat=apng)

------
callesgg
What about interframe compression?

~~~
maxst
Supported [http://littlesvr.ca/apng/inter-
frame.html](http://littlesvr.ca/apng/inter-frame.html)

~~~
therealmarv
Thanks for this link. Also a good test case for Chrome Canary (59)

------
wildpeaks
I'd be curious to know why they chose APNG over MNG.

------
samk117
been waiting for this FOREVER

