"A GIF is literally a sequence of independent images squeezed into the same file. An mp4 video can take advantage of all kinds of fancy compression techniques like keyframes and forward-predictive frames."
That's not why the mp4 is smaller. A GIF is not [just] independent images, you can have each frame reuse pixels from previous frames.
The mp4 is smaller because lossy jpeg compression is used on each frame, while the gif stores each frames losslessly.
This has implications from the predictive frames as well - the jpeg is lossy, so two almost similar parts of the images can be considered "the same", while the gif is not, so they must be identical in order to compress that way, and the realities of video noise makes that unlikely.
GIFs store deltas, true, but they are still raster images.
H.264 on the other hand contains specific techniques for compressing sequential frames, including things like recording only pixel motion for some frames. You can see it in those "corrupt movies" gifs (which on twitter would be mp4s... talk about irony) where you take a clip and remove some keyframes from it - then transformations are applied on the wrong blocks and you get really weird things like someone's head splitting open and stuff flowing into each other.
Additionally keyframes in movies are usually compressed with even more loss than standard jpegs. In most cases only the Y channel is recorded at full resolution and the two colour channels - U and V - are recorded at half.
There is also motion-jpeg which really is literally a sequence of jpeg images.
With a good palette (which most software is terrible at) and proper delta frames (without artificial differences created by blindly applied diffusion) GIFs can be 1/4th of the size you get from an average GIF maker.
Still, it's a terrible video codec.
I think trauma caused by awful plugins like RealPlayer and QuickTime made people stuck thinking that "animated images" and "proper video" are completely different things. But with native video support in browsers IMHO there should be no divide between <video> and GIF at all. It's the same thing, except the latter wastes more bandwidth, needs more memory or CPU (to enable seeking, used when you switch tabs) and can't be hardware-accelerated.
Gif is pretty bad, yes, but somehow I can browse pages with thousands of gifs. I can't browse pages with thousand of embedded videos.
GIF basically rewrites completely a part of the picture, while the remaining part is reused. And if you consider that a rewrite of a small part of the frame to reuse the remaining part from the previous frame is just displaying a new gif on top of a part of the old one, the you can consider that it is a sequence of independent images. Maybe they don't all have the same size and are not meant to be displayed at the same position, but they are independent in the sense that you don't need a previous or future frame to display one frame.
And I wouldn't refer to GIF as lossless, except maybe if your original animation used only 256 simultaneous colors per frame. You lose information by down-sampling your colors.
Some years ago there were multiple efforts to produce animated PNGs. There was MNG (Multiple-image Network Graphics, which could contain both PNG and something called JNG) in 2001, and more recently, APNG (Animated PNG) in 2008. The problem here is the spotty support for these formats. AFAIK MNG is effectively dead. I thought APNG was as well (with Firefox being the only browser to support it), but interestingly, the Wikipedia page claims that Safari 8.0 (the upcoming version in OS X 10.10 and iOS 8) supports it. Chrome, Opera, and IE don't, but there is a Canvas-based library for rendering APNG which could presumably be used to polyfill support if you wanted to experiment with APNG.
In any case, the point here is that something like APNG probably has much better compression than GIF while still being lossless (I haven't done any actual comparisons here, but the PNG format itself has support for a lot of fancy compression stuff that GIF doesn't).
---
Reading a bit more, I'm actually really surprised to see that Safari 8.0 apparently supports APNG. It seems that the PNG Group officially rejected APNG back in 2007, which means that libpng will never support APNG.
One thing you can do with video that you can’t do with GIF is programmatically describe motion — shift frame to the left, for example. GIF, you’d have to re-draw it all.
I forsee a future where all video clips on the net have been converted back and forth between gif and video so often that they all slowly merge into a single amorphous blob of greyish-brown pixels. Actually, now that I think about it, that would almost certainly be an improvement over the current situation.
- starts playing automatically
- loops seamlessly
- never has sound
- no logos or buttons like "share" and "embed"
- no scrubber bar on the bottom
- repeated instances of the same gif play back in lockstep
- no frame around it
- pixel-perfect control
All these features make it possible to create art that wouldn't work with embedded video. (Defining art broadly; captioned movie clips are included.) In the past few years, some creative people started making really good gifs that took advantage of these features. Then the trend spread through web culture. The next generation made gifs because "making gifs is what clever artistic people do on the internet".It's always been easy to create a looped animation format that combines the feature list above with a better compression scheme. Now that gifs are so popular, someone recognized the need and made one.
IMO, the 256-color dithering was more of a necessary evil for most gif creators, although some took advantage of it. It looks nostalgic on 90s Gourard-shaded untextured computer graphics. But for movie clips, etc, I think many will be glad to get rid of it. I bet we'll see a sect of gif creators who think mp4s are not authentic while most people won't care.
Your last comment reminds me of Alvin Lucier's "I Am Sitting In A Room" (wiki/youtube). Someone repeats that idea with every lossy medium we invent. I've seen jpeg and vhs examples but I can't find the links right now.
- They are dead simple to save (or link to) and drop into your own page/blog/comment.
and claim that GIFs are just really easy to share and view. They've offered a better experience both for post and viewing a short soundless clip than could be provided by an embedded Youtube player.I'm under the impression that the format only specified 256 colors per palette, and that you could use different palettes on a per-frame basis, including frames with 0ms delays between them. and I know some software existed to make this possible, though I don't recall if it made it possible with animation at the same time...
- no choice paralysis
- dead simple
- can have sound
- easy to shoop
- drag/drop
- cut/paste
viva la GIFNow, all the browsers are pretty good at dealing with video, the codecs are hugely improved (although, there's some headaches with IP) and the plugin is dead.
Nobody ever actually wanted gifs. They want short, small videos that are guaranteed to work in their browser and that they can be pretty sure aren't going to have sound. We can now deliver that.
They want moving images that load quickly. Which has meant short/small/gifs, because most US bandwidth still sucks. And thanks to the mobile explosion it now means short/small/h264.
But I bet that as people become used to 5-10x space savings from h264, they'll quickly respond with videos having 5-10x more data. (larger/longer/higher-res clips)
Also I can't right-click-save-as.
Here's a cap: http://imgur.com/2R84ImD
http://i.imgur.com/NleqJTD.png
Another example of "use bleeding-edge tech or go fuck yourself" from the modern web.
At this point, desktop configurations that can't play mp4s are at risk of being considered "broken."
http://imgur.com/Qr3tohD http://imgur.com/Qr3tohD,8okaMlP#1
So... Flash.
This has the added bonus of stealing focus if you click on it, making the "GIF" a UX nightmare.
The upside is that users get a reliable experience. the downside is that laptop Chrome users get a reliably lower battery life, as VP8 isn't typically hardware accelerated.
Also lol @ mp4 being "bleeding edge" tech. It certainly is not. Even in the Linux community.
also lol @ your opinion about technology. even in the "linux community"
Just upgrade.
https://github.com/MediaCrush/MediaCrush
if you want to try to do this yourself, our code is a good reference.
The player is very unobtrusive and minimalist, and simple things like pronounceable random names probably appeal to the user.
Also, features that are well-known to heavy reddit users (such as easily resizeable videos) only helped with the word-of-mouth.
Gifs have built in slow motion, it's called waiting for the 10mb file to download frame by frame upon initial play-through.
I encoded the gif in 420 (subsampling), 422 and 444, having a nice quality with 444 with VLC, I embed the three different videos in a web page and when playing in my browser, they are all as bad as the twitter video! I thought that Firefox was using a standard library to play MP4?
You can encode at 4:4:4 if you want, although obviously you have no control over what twitter does.
I wrote a simple js lib for detecting the duration of a GIF for each browser. It was a fun weekend project. https://github.com/rfrench/gify
If webp gains more adoption, it's another alternative now that it supports animation.
Interesting also that 4chan recently added looping, muted WebM videos for similar reasons.
ffmpeg -i foo.gif -pix_fmt yuv420p -vf crop=floor (in_w/2)*2:floor(in_h/2)*2 foo.mp4
Works for WebM just by changing the extension, too.https://stackoverflow.com/questions/3212821/animated-gif-to-...
How long has twitter been doing this? Just out of curiousity.
(Yes I know 4chan doesn't convert but there was some talk that 4chan might be a major player in pushing webm forward. Is it even webm or x264? On mobile. Can't check right now.)
gifcat (or gyfcat idk) was before 4chan. github beat gifcat. Basically twitter is doing what gifcat does, which has been doing it for a few years.
I can understand why twitter is saving money on hosting these new "gifs"
cat x.zip >> y.gif and upload would have been nice ;)
Yeah, a 20+ years file format doesn't do compression between frames, who would have thought...
As I wrote in a different comment the actual reason is lossy jpeg compression, not intra frame compression.
Yeah, for pictures jpeg is much better (and smaller) than gif.
Not to mention in several gifs they really reduce the quality to have a smaller file size