ONE STAGE OF A CHAIN — WHAT ARRIVES, WHAT LEAVES, WHAT BREAKS DOWNSTREAM
Where This Sits In The Encoding Pipeline
A video encoder is not one algorithm but eight stages in a fixed order, and the order is not arbitrary: each stage exists because the one before it made its job possible. This tool models one of them. The chain below links to the other seven.
GOP Structure Visualizer — decides which frames are coded standalone and which are coded as differences
- What arrives
- A run of sampled frames, none of them coded yet.
- What leaves
- An assignment: I-frames coded alone, P and B frames coded against reference frames.
- What the next stage assumes
- Motion estimation runs only on P and B frames. An I-frame skips it completely.
- What goes wrong here
- This stage decides whether the next one runs at all for a given frame, so it gates stage 04 rather than merely preceding it. Long gaps between I-frames compress much better and make seeking worse, because a player has to decode forward from the last I-frame to reach any point you ask for.
Problem solved in full
-
Frame mix and average frame size for 48 frames at 24 fps 6 steps
A Blu-ray-style group of pictures: 48 frames, 3 consecutive B-frames between references, played at 24 fps. Take an I-frame to cost 100 relative units, a P-frame 12 and a B-frame 6. Find the frame mix and the average frame size, then work out how much compression a longer GOP could still buy.
-
One I-frame opens the group, which leaves 47 slots. Those slots repeat a 4-frame unit — 3 B-frames and the P-frame that anchors them — and 47 is not a multiple of 4. 47 = 11 × 4 + 3, so 11 complete units and a tail of 3 B-frames left hanging.
-
That gives 11 P-frames and 33 + 3 = 36 B-frames. Check it: 1 + 11 + 36 = 48.
-
Weight each type by its cost. 100 + 132 + 216 = 448 units for the whole group, and 448 / 48 = 9.3 per frame. An all-intra stream pays 100 for every frame, so this structure is 10.7 times smaller for the same 48 pictures.
-
The bill for that arrives as latency. You cannot start decoding in the middle of a group — every P- and B-frame is defined relative to something else — so seeking lands you on the I-frame and you decode forward from there. The worst case is the full 48 frames, which at 24 fps is 2 s.
-
Now find the floor. Each repeating unit costs 3 × 6 + 12 = 30 units for 4 frames, or 7.5 per frame, and lengthening the GOP does nothing but add more of these units. Subtract that rate from the group and 448 - 7.5 × 48 = 88 units are left over.
-
Those 88 are one number: 100 - 12, the I-frame's premium over the P-frame it stands in place of. The premium does not grow with the group, so it is 88 whatever the length is, and the average is S̄ = 7.5 + 88/N. Test it at double the length: N = 96 gives 7.5 + 88/96 = 8.4 units per frame.
Answer
9.3 units per frame, against a floor of 7.5 that no GOP length can go below. The two halves of the trade scale in opposite directions and neither is linear in the way it looks: what you still have to gain falls as 88/N while the seek latency rises as N/24. At 48 frames you are 1.8 units above the floor. Doubling to 96 recovers 0.9 of that — under 10% of the frame size — and costs another 2 s of worst-case seek. Doubling again recovers 0.46 and costs 4 s more. So the GOP length worth choosing is fixed by the latency you are willing to accept, not by the compression you are still chasing: past a few dozen frames, one I-frame amortised a little further is all that is left on the table.
-
References (1)
- Where I, P and B pictures and the GOP structure are specified: ITU-T Recommendation H.264, Advanced video coding for generic audiovisual services.