How-To and Tutorials

Multimedia 101

How to Digitize Audio
Creating Audio CD's
Making Video CD's
Movie Splitter Tutorial
Movie Joiner Tutorial
DivX Compression Tutorial
Multimedia File Conversion
How to re-index WMV files
Replacement CD's
Fx Audio Editor
Fx Audio Tools
Fx Joiner and Splitter
Fx Magic Music
Fx Movie Joiner
Fx Movie Splitter
Fx MPEG Writer
Fx New Sound
Fx Video Converter
Sample Movies

 

Video Compression basics => Key frames

This page is very graphically intensive. If you have a dialup connection you may want to go to lunch now and perhaps the page will be loaded when you come back.


As we mentioned earlier, video compression often uses the removal of redundant pixels as a vehicle for reducing data size.

To illustrate that process we're going to use a GIF animation (which could just as easily be a 29 frame movie file). The GIF file uses the technique of removing redundant pixels to reduce the footprint on the server and the load time of each frame but it runs in the browser making the overhead and encumbrance of a movie player unnecessary. Of the 29 frames making up the fish tank animation, the first frame is the only frame that contains all the data. This is the first and only key frame of this sequence. Frame 2 contains only those pixels that are different than those in the key frame. In this case the only movement is water shimmer and one goldfish beginning to appear from behind the castle so there are perhaps only half as many colored pixels in the frame.
Frame 3 is more shimmer and the fish moving further to the left. With each subsequent frame you will see that only the changed data has been written to the frame data. 5
6 7 8
9 10 11
12 13 13
15 16 17
18 19 20
21 22 23
24 25 26
26 28 29

If we convert the above GIF to an AVI it will be very small but it won't load into most editors and Windows Media Player will fail when trying to fast forward since there is only one key frame. We could of course partially solve that problem by adding the first frame as frame 30 and then setting frame 30 as another key frame but fast forward would move to the end and fast rewind to the beginning.

You may be asking yourself why a tutorial would be showing you how to create a movie that crashes everything that tries to load it. The answer is to show you how easy it is to do and to point out how important key frames are to the software that plays or edits your movies. Without a key frame at every scene change and at reasonably spaced intervals, the player or editor has to load all the frames just to get a complete picture.

Similar to the above illustrations, MPEG movies use 16 pixel x by 16 pixel data squares then removes "generally" redundant squares instead of redundant pixels.

The below left image represents one 256 pixel square in the center of the below right image.

Expanded we can see each of the 256 pixels in the 16 by 16 square.

Whether or not this square would be "generally" redundant depends entirely upon the codec's settings. Some codecs that have quality/speed settings might include this square when the quality was set high but exclude it otherwise.

The technique of removing generally redundant squares produces very high compression. As you might imagine in a scene where only the faces of two people talking to each other only those squares around the speaker's mouth would need to be copied to the next frame. However, since only the changed squares are carried from one frame to the next you don't have a complete picture so a key frame that contains all the data is inserted periodically.

Let's try to examine this another way. If we select frame 5 in a movie that has no key frames we must also load frame 1, 2, 3, and 4 then stack all the squares to create frame 5. The problem here is that without key frames you can't select the exact point from which to watch the movie. That is, you can't watch half a movie and then come back later and simply fast forward to the last frame you saw because there's no reference point to key on.

The top row of the images above represents frames 1 through 5 in an uncompressed AVI file. Notice how each frame is a complete picture. The next row represent the same frames from an MPEG file. As you can see, frames 1 and 5 are Key frames showing a complete picture, but frames 2, 3, and 4 contain only the bits of information (delta frames) that are different from the previous.

A key frame should be added every few seconds (typically 5 to 10 seconds) and when a scene changes in order to track the position of the movie. In MPEG encoding key frames are called I-Frames or Intra-frames while half-frames which contain the formula to reconstruct missing frames from the differences  are called B-frames (backward frames - behind the keys) and P-frames (predicted frames - preceding the key).

Because key frames are full pictures they obviously hold much more information than partial frames so the ore key frames, the bigger the movie. Keep in mind that when you split an MPEG file between key frames video for windows players will not be able to reconstruct the movie frames until they reach the next key frame.

 

Copyright 1995-2008 J. Hepple, Inc. DBA Fx, Sound & Magic

Fx, Sound & Magic is a trademark of J Hepple, Inc.

Developer Member

OISV - Organization of Independant Software Vendors - Charter Member

Privacy Policy Statement

Report Cyber Crime

Restricted Use Policy

Affiliates

Hoax Email

Beta Testers