Glossary

What are P-Frames and how are they used?

P-frames, which stand for “predicted frames,” have always existed in the middle space between I-frames, or “complete images,” and B-frames, or “highly compressed bi-directional predicted frames” – and they provide a good middle-ground in terms of file size reduction and video quality. Learn more about I-frames (and IDRs) and B-frames here.

They plays a critical role in video compression in video codecs like H.264/AVC, HEVC, and AV1 and let us see why.

How do P-frames work?

The compression power of P-frames mostly comes from their use of motion estimation. If we have a video sequence with slow and gradual movementᅳsay, a person talking with minimally changing surroundings (also known as talking heads content) – then the P-frames can analyze the prior I-frame or P-frame and save only the differences (via motion vectors and difference values) in the current frame’s data.

This saves a lot of space because we’re really only storing an instruction of how to move a certain number of pixels from one frame into the next, and any additional information.

To understand this better, read more about GOPs in this blog we wrote earlier.

Why Use P-Frames?

A P-frame offers a much better compression as compared to an I-frame. The video file size is significantly reduced by having motion content only stored for each P-frame in the compressed video sequence. And if the P-frame isn’t good enough, we even have B-frames, which offer better motion compression efficiency as compared to P-frames. But for now, let’s just stick to understanding P-frames and how they achieve this kind of better compression.

Simpler to Understand

P-frames are more straightforward to understand for a computer than B-frames are because B-frames have a tendency to refer back not just to the frame before them but also to frames even further back. This leads to a lot of arithmetic and logic, which makes B-frames more computationally complex.

P-frames, in terms of editing, are quite similar to I-frames. They reference earlier frames and as such are quite easy to edit without re-encoding the whole video. Again, like I-frames, P-frames are considered poor quality if viewed in isolation from the surrounding frames. What makes P-frames editing-friendly is that they have only difference information, so much smaller amounts of data have to be moved and copied on the editing timeline.

Efficient Compression

When it comes to compression efficiency, P-frames achieve a pretty good balance between compression and preserving video quality. The P in P-frames actually stands for “predicted.” “How is this done?” you might ask. “By predicting what will happen next, and recording only the differences between the image at the next time-step and the predicted image.” Because the way people move, on average, doesn’t change from one time-step to the next, the P-frame is always a good bet and will compress things a lot without losing much (if any) video quality.

 

Limitations to the use of P-frames

Although there are pros to P-frames, it is important to remember that they also have their cons.

Error Propogation

The reliance on preceding I-frames or P-frames for accurate decoding sets P-frames apart from I-frames. When a P-frame is being decoded, it uses information from the preceding I-frame or P-frame. Any errors during the decoding process, especially errors in the reference frame, can affect, or propagate to, subsequent P-frames.

Scenes with Lots of Motion

Rapidly moving or changing scenes might be a bit too much for P-frames to handle from a quality perspective. Sometimes the information in two frames is so different that the motion prediction isn’t that effective because they can’t find a part of the previous frame to serve as the basis for predicting the next.

Finally

P-frames are a good match for video content that has a lot of movement and changes between frames. For example, what if there’s a video of someone talking, and the only thing that’s changing is the movement of their lips and the micro movements of their face? To compress this, you can “predict” what the next frame will look like based on the previous frame (or frames). Is the person still talking? Then the next frame will probably look like the current one, just a small time step ahead. Is the person’s face still?

When you optimize the file’s size and simultaneously keep its visual appearance intact, P frames propose a very valuable tradeoff between I and B frames. If you are interested in video coding, then our articles on GOP (group of pictures) and AI-driven video compression will surely interest you.