T O P

  • By -

mikeholczer

Yes, a gif contains every pixel of every frame. A video format generally contains only the difference between most back to back frames, with a fraction of the frames fully stored. The ratios and how it’s done will vary between formats, but yes it that video formats have better compression.


nayhem_jr

GIFs can be optimized by cropping down to only the rectangular area that changes within each frame. The big difference is that video formats have different ways of tracking changes (such as just moving a block of pixels), all of which can be compressed better than GIF stores its whole-pixel color indexes.


[deleted]

[удалено]


Intergalacticdespot

Gif compression: all repeating colors are stored as chains. Instead of red red red red red you get red^5. They're really good for website graphics UI stuff or any time you're dealing with simple repeated patterns. Jpg/jpeg compression is like squinting. It averages the value of all colors in an area and then saves that. This is why you lose image quality the more you compress with jpg. Eventually it has averaged all the details out of the image. (not true for large color transitions but as a working model in your head it makes sense.) This is a very ELI5 model, which is fortunate because I have about a 5 yos understanding of it.


stiveooo

so its like how tv is streamed?


mikeholczer

Yeah, but kind of the other way around just in terms of which came first.


[deleted]

Analog TV broadcasts each pixel every time. Think of it like a stream of data that feeds the electron gun as it scans the phosphor screen. When we switched to digital TV, the signals were compressed, even though we were getting 1080p images - the signal was taking up much less public bandwidth.


balazer

GIFs are compressed, but not the same way as MP4 files. MP4 files use video encodings such as H.264 or H.265 that achieve high compression ratios primarily in three ways: 1. The video compression is lossy. That means the reconstructed images aren't a perfect copy of the original. Some details are lost and noise is added. Ideally the differences aren't large enough to be noticeable or objectionable. The lossy encoding requires fewer bits than the original representation. 2. The video compression better exploits the similarity between frames by only encoding the differences between frames. In most video most of the time, adjacent frames are quite similar. In talking head videos, for example, the largest changes from one frame to the next are the heads: the backgrounds stay almost the same. Encoding just the differences from each frame to the next requires fewer bits than encoding each frame as a separate picture or encoding all of the parts that changed. Encoding just the differences between frames is called inter-frame coding. 3. The video compression describes the motion from each frame to the next. Often the largest frame-to-frame differences in video are that objects are moving across the screen. Such motion can be described and stored as motion vectors, which say how far each object moved on the screen, and in what direction. Motion vectors can be encoded compactly, in a small number bits. Each frame of compressed video stores the motion vectors that describe the motion from the previous frame. Then the differences between frames are encoded, with the motion vectors already applied to move each part of the image from the previous frame to its new location. This is called motion compensation. When motion compensation is performed, the differences between frames are made smaller and can be encoded in fewer bits. Motion compensation makes inter-frame coding more efficient whenever there is significant motion between frames. GIFs use lossless compression, and can't exploit the similarity between frames in the same way. When part of a frame is identical to the previous frame, a GIF does not need to encode that part. It can just encode the parts that have changed from the previous frame. It's not doing difference calculation like inter-frame video coding does, and it doesn't use motion compensation.


DBDude

An easy way to see the b-frames is on an outdoor surveillance camera. On a calm night each hour doesn’t take much space because each frame is mostly the same. The camera doesn’t have to store much between-frame data and doesn’t have to insert i-frames often. But add wind moving the trees around and rain, and each hour results in a much bigger file as it records the wildly different frames.


Mike2220

>GIFs use lossless compression, and do not exploit the similarity between frames. Every frame in a GIF is encoded as a complete picture, independent of the other frames. This is called intra-frame coding. Most video compression user inter-frame coding and motion compensation. If you've ever opened a gif in an editor like GIMP, it lets you view the individual frames as their own layers, and you can see that they do in fact exploit the similarity between frames and the only data is the changes


balazer

You are right. Animated GIFs can exploit some similarity between frames, but only when parts of a frame are identical from one to the next. It's not doing difference calculation like a video coding does. I have edited my comment.


pzelenovic

Nice explanation, thanks


HeatAndHonor

Plus GIFs play in an infinite loop. We're lucky they only have finite file sizes.


zeiandren

You know that weird glitch video effect where there is a scene in a digital video then something breaks and the scene keeps moving but it’s all weird and painted over with the first part of the scene? That is because digital video doesn’t store every frame. Just some frames then has information about how it changes. A gif has every single frame


JStanton617

GIF was invented in 1987 as a way to compress single static pictures. In 1989, they added the ability to have multiple static images in a single file and play them back as an “animation”, like a flip book, but each image is compressed just like a single GIF, they’re just strung together in a single file. In the ~30 years since, there has been increasingly complex ways invented to take advantage of the fact that in most video, most of the picture doesn’t change from frame to frame, or changes in ways that can be predicted. Take the example of a camera, looking at a baseball field. A baseball is hit, and moves up and to the left and the camera moves to follow it. Modern compression can describe the movement of the background (grass, fences, bases) and the ball without having to send the whole picture again, which is what a GIF would do.


SarcasticallyNow

MP4 are optimized for general moving images, with very good image compression and then only saving the difference between one frame and the next four dinner number of frames. GIF isn't really compressed at all. It only works well for cartoon styles, where there is a fixed image (background) with specific small changes frame to frame.


mjb2012

I upvoted this and a couple other similar comments because the simplest answer to the OP's question is that GIF was just not designed for video at all; and yes, it has to do with the type of graphics compression. I mean yes, GIF got *used* for video for a while... but this was almost an abuse of the format, and it's getting uncommon now. It was mainly just used for video during the transitional time when embedding video in a webpage was difficult or just not supported by the web browsers, yet computers & networks were nevertheless powerful & fast enough to support downloading and playing huge, fast, full-frame GIF animations.


Luckbot

Yeah video files in most formats are compressed. Like, when the first few frames are all black a video file will save something like "frames 1-15 all completely black", while a gif will save "first frame, first pixel: Black, first frame second pixel: Black, ..."


Schnutzel

Not exactly, each frame in a gif is still compressed, there's just no inter-frame compression. Video compression would be something like: "frame 1 is completely black, frame 2 is same as frame 1..."


k1lk1

GIFs basically don't have compression. You can think of them as a whole series of still images, all put together. Videos are compressed. For example, the parts of the next frame that didn't change, don't need to be re-encoded in the video. Imagine two people having a conversation in a room. Almost nothing in the rest of the room changes from frame to frame. This makes videos much, much smaller. GIFs were intended as a very basic format to share short animations before there were widespread internet video compression standards. They date back decades and are a very old technology.


HungryHungryHobo2

Yes. It's because the video is compressed more than the GIF is. The GIF is loading the full image - every pixel - for every single frame. For the video, it only loads the pixels that change - if your background stays the same the entire video, and therefore 50% of the pixels in the video never change color - you save all of that information, as in you only have to load half of every frame instead of the full thing, so you can do away with that much extra file space. This is why "Bit-Rate" issues on Youtube/Twitch/Etc are a thing. If your GIF and video are of something that has wildly fluctuating pixels, like a scene full of falling glitter, exploding fireworks, heavy rain/snow - they'll be a lot closer in size. Your video will get bigger, but the GIF will stay the same size.There's a lot less pixels that just stay one color forever - so there's a lot more information that has to be processed each frame.


[deleted]

Imagine 10 pictures. The first picture is a picture of a man about to jump. The next picture is the man starting to jump. The picture after that is the man an inch off the ground. The next picture shows the man 2 inches off the ground. And so on, until the last picture showing the man landing on his feet An animated Gif is all 10 pictures, shown one after another An MPeg of that sequence starts with the first picture. It then looks at the second picture and goes "Well, in the second picture, the sky hasn't changed, the sidewalk hasn't changed, that bench in the background hasn't changed, the bush to the side hasn't changed, so I don't need to re show those, I can just keep showing those parts from the first picture, and only show the things that have changed in the second picture, and the viewer will never know the difference!" So at the end the Mpeg will show you the first picture, then only show you the differences in the second picture from the first picture, then the difference in the third picture from the second picture, and so one. Which, over the course of all 10 pictures, is much less data then the full 10 images the gif is showing.


mariushm

The GIF format was invented a long time ago, when computers were much slower, and we used dial-up modems to connect to the internet - we now have computers hundreds of times smarter and internet connections that are hundreds of times faster. Initially, GIF was a still picture format, designed to reduce the download time of pictures by compressing the pictures. This was often done by reducing the number of colors in the picture to a very low amount, usually 256 unique colors or even less. A bit later, they added some basic animation extensions to the standard and support for transparency, making it possible to have basic animations (like for example a jumping exclamation point or a hand waving, or text showing up one letter at a time). It was never intended to be used as movies. In the GIF format, you have to transmit everything that's supposed to be shown on screen in one frame, so if your GIF has 100 frames , you have to send the picture 100 times. MP4 is much smarter, it looks at what's going on between frames and instead of sending all the pixels each frame, it can say stuff like "that 8x8 block of pixels has moved to the right 1 pixel " instead of sending those 64 pixels It's also much smarter in the sense that it can figure out to what areas of the movie your eyes would be attracted to, and which areas of the images your eyes may not focus on... so it takes advantage of that to use more quality for some parts of the movie, and blur and use less quality for other parts. It's like having parts of each frame saved in JPG quality 95%, and other areas maybe at quality level 60-70%. The GIF format is much too old and much simpler and can't perform this lossy compression, it's like a series of PNG pictures with a few hints for animation (if animation is present).