B-Frames OBS

Let’s say you make a one-minute video dancing in front of a wall. The wall occupies two-thirds of the space and you occupy a third. As you’re dancing, you’re constantly moving but the wall isn’t. If it is a 30 fps video, a one-minute clip will have 1800 frames. The camera just takes 30 photographs per second and plays them at the same rate. These photographs are called frames. Showing these 1800 clips in quick succession with an is what makes them a video rather than a slideshow.

B-frame is short for bi-directional predictive frame,  a form of video compression. In the 1800 frames of your one-minute video, you are the only moving object. The wall remains still and unchangeable. To cut down on the file size of your video, it is compressed. That is, only the pixels that change position from frame to frame are retained. B-frames perform compression by consulting the frames that come both before and after a frame. So if you have frames 1, 2, and 3, in order to render frame 2, a B-frame checks the pixel alignment on frames one and three. If the pixel alignment is different, then the changed pixels are the only ones that are stored on frame two and later rendered. 

With perfect compression, there would be 1800 frames of you dancing superimposed on only one frame of the wall. The actual process is far more complicated than this but you get the general idea. Only the pixels that change in both frames are stored. 

The reason compression is used is because it saves on space as raw video footage has an extremely large file size. This makes transmission and storage difficult. Compression cuts down on size by retaining changeless pixels and only changing the shifting ones.

What are B-frames in OBS? 

B-frames are a type of compression algorithm. There are three types of video compression algorithms:

  • I-frames (Intra-coded picture) – These are the least compressible as they hold a complete image, a jpeg, or a BMP file.
  • P-frames (Predicted picture) – P-frames consult the previous image and only store the changes. So, with our dancing example, if you stand still in frame one and only move your hand in frame two, the hand motion will be the only thing that is stored by a P-frame algorithm. 
  • B-frames (Bi-directional predicted picture) – B- frames are more advanced than P-frames in that the algorithm consults both the frame that comes before and the frame than comes after the frame in question. The image is only stored if it defers from both. So, if you stand still in frame 1, raise your hand in frame 2,  keep it still in frame 3, and return it to its original position in frame 4, no changes are stored for frame 3 as it is identical to frame 2. 

Do B-frames increase quality?

No. Video quality is increased by increasing the video’s resolution (say from 1280 x 720p to 1920 by 1080p) and its frame rate (say from 24 fps to 30 fps).

The purpose of B-frames isn’t to increase quality. It’s to reduce the file size of the video output. Smaller videos take up less space on your hard disk and are easier to stream as they take up little bandwidth.

Compression isn’t always guaranteed to be great. It all depends on the moving elements in the video. A one-person dance in front of a wall is bound to be far more compressible than a ten-person dance shot in front of a billowing curtain or a busy street. In the second video, almost every element is moving while in the first one only the dancer is moving while the background is static.

How many B-frames should you use?

Two B-frames per group of pictures is a good rule of thumb. The more B-frames you have per group, the more processing power you will need. So if your machine is very powerful, this can be as high as three or even four.

What should your max B-frames be on OBS?

Max B-frames depend on the computing power you have at your disposal. Two is the recommended number but you can go as high as four if your machine can handle it.

What is the keyframe interval in OBS?

A keyframe interval is the time between different keyframes, say two seconds, four seconds, or even ten seconds. This raises a new question: what even is a keyframe?

Let’s go back to our dance video example. Our one-minute video at 30 fps has 1800 frames. These frames are not compressed all at once. Instead, they’re divided into image groups. If you choose a keyframe interval of two, that means the frames are divided every two seconds. Each group of pictures contains 60 images. If you have a higher frame rate or a larger keyframe interval, you will have more images per image group.

The first image in a group of pictures is the keyframe as it is a full-frame image. Subsequent images are called delta frames. They only contain the data that changes from frame to frame. 

The keyframe interval is the time difference between two keyframes. The recommended keyframe interval for OBS is two seconds. The smaller the keyframe interval the smoother the video. This will also require more processing power, however.