Animated GIFs have been around for a very long time. We're talking, like, early days of mass use of the web,
so we're talking GeoCities, mid-90's technology here,
and yet, they're still popular. They're still on every damn BuzzFeed article and every Tumblr there is,
and the reason is because they work pretty much everywhere,
and they're also a really good example of the tradeoff between space and time
or between memory and time in computing.
Animated GIFs have been around so long that they're actually a verb now --
officially recognized, "GIF," or "jiff" if you wanna pronounce it the official way that's blatantly wrong.
You can fight that one out in the comments.
Um, they are a really inefficient way of storing video,
'cause GIF wasn't designed as a format for storing what it's used for now, like actual videoclips.
It was used for simple animations, and you can see that in the restrictions that it has.
The whole gamut of colours that you can use on the web is actually the cube of the number of colours that you can use in a GIF.
So a GIF will let you have 256 colours. The web, 256 values for red, for green, and for blue.
Multiply those, you get 16,777,216 colours!
That's how many you find in a photo.
The GIF will only let you have 256, which is why you get that kind of weird, compressed, grainy effect.
More than that, the colours don't change for each frame, again with rare exceptions using really advanced GIF-makers,
but, generally, one palette for every frame.
So if you go from a beautiful sunset with all those gorgeous yellows in it
and then go to the ocean with lots of blues,
you're gonna run out of colours very, very quickly.
The other restriction with GIFs is frame rate.
Uh, this video you're watching will be either 25 or 30 frames a second -- I don't know which one you're using.
Um, GIFs generally don't go above 20,
and, mm, rare to see anything above 10 or 15,
which is where you get that slightly shaky effect from, the kind of juddery effect you see in a lot of GIFs.
The reason for that is they were designed for animation, not for video.
I mean, GIF is wonderful if what you want to compress are simple line drawings.
If you want to go beyond that, not really all that good.
The reason for that is GIF uses, well, very limited inter-frame compression.
There are two types of compression you can use in video.
Uh, there is inter-frame compression, which is what most modern formats use,
and there is intra-frame compression, which is what GIF mainly uses.
And these ones, "inter-" and "intra-," you'll have heard before for, like, "INTERgalactic space,"
where you have the space between galaxies,
and "INTRAgalactic," which is just the space within one galaxy,
and it's an important distinction, 'cause inter-frame compression is how all modern video formats work,
even back to the early MPEG ones and the, you know,
that were being used at the same time as GIF was coming out.
Uh, MPEG-2, which is what DVDs use,
and MP4, which is almost certainly what you're watching right now,
they all use inter-frame compression.
And the idea is this: you get the first picture,
which is, like, you know, regular photo compression, it's crushed down little,
and then that picture isn't stored for about 25 frames more, until there's a major change.
Until then, it just tracks the differences.
So if I stay perfectly still, as still as I can, then all that the MPEG compression will do, pretty much, is my mouth.
The rest of me, there'll be hardly any data compression there at all
because, well, hopefully the rest of me isn't moving.
On the other hand, if I start flailing about a lot like this, then suddenly --
and, yeah, if you move the camera as well --
suddenly, everything here is having to move. It's having to work a lot harder,
and what it's doing, instead of changing every frame,
instead of storing every single frame, it's saying,
"Right. In here, that big block of pixels that's red, that's that T-shirt,
that's moved a bit that way and zoomed out a bit,
and this pinkish block here that's the hand, that's moved that way a bit and the fingers moved."
So it works out the differences between each frame.
And occasionally it will store the entire image if that's more efficient,
particularly on a quick change, if you suddenly zoom -- thank you! --
um, then it will often go to a new keyframe there, as it's called.
But generally, it will just track the differences between them.
GIF isn't designed to do that. We're talking mid-90's here.
Maybe it was possible to have a video stream going,
but at the same time as you're trying to display a webpage,
at the same time you're trying to track everything else going on in the system, no. You couldn't do that.
So GIF was designed with mostly just intra-frame compression.
Intra-frame compression is like storing a series of photographs.
Each one is pretty much independent from the one before and the one after.
Now, you can see why this is less efficient.
You've got enormous space savings if you say that wall doesn't change at all.
It has limited inter-frame compression.
If nothing has changed in a pixel, you can just set it as transparent
and the one from the previous frame will sort of show through.
But other than that, if something changes, you have to encode it completely all over again,
and this is is one of the basic tradeoffs of computer science,
because in exchange for the extra file size, the extra data that you're storing,
it is a lot easier to decompress.
Instead of having to worry about storing one frame and another and then managing the differences between them
and all the little fiddly things that you have to do there,
you just show a picture, and then you show another picture, and then another.
Simple as that.
GIF, in exchange for that extra file size, that poor compression, is actually really, really easy.
I mean, back in the GeoCities days, you could have, you know, flaming skulls rotating on your webpage,
an entire background of flames as many GeoCities sites including mine might well have done
I've just realised there are people watching this who aren't gonna remember GeoCities
because they were born after it, which is really weird.
Um, GeoCities was, um, I was about to say the MySpace of its day but, no,
it was the Tumblr of its day.
Um, they gave you free webspace and you wrote up the HTML code yourself and you uploaded it,
and it was wonderful, and then it was bought by Yahoo!, and it was not wonderful anymore. Anyway!
You see this tradeoff everywhere in computer science.
Uh, if you have an app that has to do a really complicated calculation -- it might take a few seconds --
you can either let it do that calculation each time,
just send the formula to do that calculation off to the app,
so the user types in whatever number they need, they hit a button, it does the calculation,
three seconds later the response comes back to them,
or you can make the app much, much bigger.
You could include the result for every number they could possibly type in, precalculated, just calculated once beforehand,
and, instead of sending them a formula, you send them a lookup table.
It might be megabytes or gigabytes in size, but instead of having to do that calculation,
you tradeoff the time for the space,
and, instead of three seconds, you waste 500 megabytes --
those are arbitrary numbers I pulled from anywhere --
but the tradeoff is there.
And the tradeoff is there in cryptography -- I've mentioned rainbow tables before:
"... rainbow tables ... which tradeoff computation time for hard drive space.
So, rather than having to calculate millions and millions of hashes for this one password,
someone has already done it for you."
So you can spend, ah, days or weeks or months or years or millennia brute forcing a password,
or you can use megabytes or gigabytes or terabytes of data to try and jump forward in the calculation.
I'm summarizing here, and cryptography nuts will be extremely angry at me for doing that,
but essentially it's the same tradeoff.
Rather than processor time, you've traded off for space.
It's one of the fundamental principles of computer science and it's best explained with animated GIFs.
The thing about GIFs is it's one of those weird things where the medium defines the message.
Like, movies have to be between about 90 minutes and three hours, depending on the genre.
Uh, Vines have to be six seconds, well six-and-a-half seconds, actually.
This one was determined by technology,
by what bandwidth could support, by what file size was acceptable,
and it's interesting to see something where it's not been decreed,
it's not been agreed over time either.
It's just whatever happens to fit into the technology.