Green frames and macroblock glitches: decoding without a keyframe
A flash of green, a smear of coloured blocks, a picture that looks tiled for a few seconds and then snaps back. The decoder was asked to draw a frame that depended on one it never received.
What the viewer sees
Solid green frames, green or grey blocks, tearing, or a mosaic where parts of the image update and parts do not. The distinctive feature is that it self-corrects: after a few seconds the picture is clean again with no intervention. That timing is the diagnosis - it is the interval until the next keyframe.
Why it is green
Compressed video is a sequence of groups of pictures. Each group starts with an IDR frame, a complete picture that depends on nothing else, followed by P and B frames that only describe the difference from frames around them. If the decoder receives P or B frames without the IDR frame they reference, it applies the differences to whatever its reference buffers contain. Freshly allocated buffers are zeroed, and zero in the YUV colour space the decoder works in is a shade of green - which is why the failure has a colour.
How the decoder ends up without its keyframe
There are only a handful of ways in, and they are all about starting or resuming decoding somewhere other than a keyframe.
- A live stream joined mid-group, because the segment boundary was not on an IDR frame.
- A seek that lands on a non-keyframe position and a player that starts decoding from there instead of the preceding keyframe.
- Packet loss in a live contribution or UDP-based distribution path that drops the keyframe itself.
- A rendition switch where the two renditions have different keyframe positions, so the join is not on a keyframe.
- Open-GOP encoding, where frames after a keyframe still reference frames before it, cut at a segment boundary.
Prevention is in the encoder
Every segment must begin with an IDR frame, and every rendition in the ladder must place its keyframes at the same instants - a fixed, closed GOP with a length that divides the segment duration. That single constraint removes the mid-group start, the misaligned switch and the open-GOP cut at once. For live streaming a shorter GOP, around two seconds, limits how long any glitch can last and how long a viewer joining the stream waits for the first clean picture.
On the player side, seeks should always resolve to the keyframe at or before the target and decode forward from there, discarding frames until the requested position. Most player libraries do this correctly; native platform players on some televisions do not, which is one more reason to keep keyframes frequent and aligned so that the damage, when it happens, is brief.