Understanding the keyframe interval

camera key frame

IP cameras use video compression for 2 reasons: to save disk space and to save network bandwidth. A camera offers various configuration parameters regarding video compression, and one of them is the keyframe rate.

IP cameras use video compression for 2 reasons: to save disk space and to save network bandwidth. A camera offers various configuration parameters regarding video compression, and one of them is the keyframe rate.

How Video Compression Works

Unlike image compression (like jpeg), video compression uses a mechanism to save even more space: intraframe and interframe encoding. The first frame of the video is compressed like a normal frame (such as a jpeg) and a reference to it is retained. The following frame is compressed differently: only the differences with the first reference frame are kept. If nothing moves in the video scene, it means that the difference between the 2 video images is very small. This results in a very high compression of frame #2, since it is almost exactly the same as frame #1. However, the more changes there are in the scene, the more space is needed for the second frame. However, frame #2 will still be smaller using this type of difference encoding.

Frame #3 will be encoded using only the differences with frame #2. Frame #4 will be from the differences with frame #3, and so on…

After a certain number of frames, this encoding chain will be interrupted and a new complete keyframe will be generated. It is this keyframe that is often referred to as I-Frame

Here is an example of setting up a Uniview camera. The parameter here is called I Frame Interval. In this case, there will be 1 keyframe every 25 frames:

Example with a Uniview camera

Here is an example with an Axis camera,. The parameter here is called GOP length. In this case, there will be 1 keyframe every 32 frames.

Example with an Axis camera

What settings should I use?

It depends. If you have little disk space, using a high keyframe rate can improve the space required to store the video. However, it may have an unwanted impact on video playback, especially when you search through the video. For example, if you try to position yourself at a specific moment in the replay, you will be positioned on the nearest keyframe. Why? Because a video decoder cannot decode an intermediate frame without decoding the previous key frame and the following frames. This can easily be noticeable when rewinding. You will notice that the rewind is a little jerky. This is because you will only see keyframes when viewing backwards.

A simple way to visualize this is to think about watching television (from your digital decoder for example). When you change the channel, sometimes it’s fast, sometimes it’s longer before you get the picture. This happens because the decoder is waiting for the next keyframe to arrive. So if the TV channel uses 1 keyframe every 2 seconds, you might have to wait up to 2 seconds when switching to the TV channel.

You will see the same effect with CCTV cameras. If the camera is configured to use 1 keyframe every 2 seconds, you may have to wait up to 2 seconds when connecting to the camera. The keyframe rate will have an effect on the speed at which you can connect to the camera.

I Frame Interval vs FPS

Each camera manufacturer uses a different nomenclature for frames per second and keyframe rate. The frame rate (fps) is the number of frames per second of the video stream. Keyframe, or I-frame interval, defines how often a keyframe is generated.

Here are some examples:

Example #1

The frame rate (fps) is fixed at 25, which means that the camera stream will be 25 frames/second. The I-frame interval is fixed at 25, which means that a keyframe will be generated every 25 frames. Doing some simple math, this means that a keyframe will be generated every 1 second.

Example #2

The frame rate is set to 10: 10 frames/second.
The I frame Interval is set to 40: 1 keyframe every 40 frames
Result: a keyframe will be generated every 4 seconds.

Here is an explanatory document which makes comparisons on the I frame rate:

https://ipvm.com/reports/test-i-frame-rate