NV12 Row Stride: Find Y and Interleaved Chroma Bytes
2026-11-21

NV12 Row Stride: Find Y and Interleaved Chroma Bytes

NV12 row stride is the distance in bytes from the beginning of one stored row to the beginning of the next. A frame described as six pixels wide can have an eight-byte stride in its luma plane. When the planes are contiguous, the actual stored length of the luma rows determines where the chroma bytes begin. A small frame is enough to see how a stride error changes both addresses.

Identify the planes and the stored components

In the linear, contiguous eight-bit NV12 layout used here, the first plane has one Y byte per luma sample. The second plane stores alternating Cb and Cr bytes as pairs. For 4:2:0 sampling the chroma plane has half as many positions as luma horizontally and half as many rows vertically. Each chroma position occupies two bytes. This gives the same active bytes per row for the two planes in this even-width example, though the chroma plane has only half as many rows.

Use the memory layout supplied by the actual interface. A separately allocated planar format may supply independent buffer pointers and strides. A tiled format has storage rules different from simple row addition. The example is a linear six-by-four frame with an eight-byte pitch in both planes and the chroma plane directly after all four stored luma rows.

Count the padding before advancing to the next row

Each luma row contains six active bytes and two padding bytes. The four row starts are therefore offsets 0, 8, 16 and 24. The plane occupies thirty-two bytes, including padding. With zero-based coordinates, the luma sample at x equal to 4 and y equal to 3 sits at byte offset 3 times 8 plus 4, or 28. The width in pixels describes the valid columns, while the stride locates the next row in memory.

The four padded luma rows start at offsets zero, eight, sixteen and twenty-four. Byte 28 holds the sample at four, three.
The pitch determines the distance between row starts and includes the two padding bytes. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Multiplying the visible width by height gives only twenty-four active luma bytes. In this frame, offset 24 is still the start of the last luma row. Using that value as the chroma start would read either active luma samples or padding as if they were color differences. Advancing through each row by the width instead of the pitch would progressively misplace each subsequent row.

Locate the corresponding interleaved chroma pair

For the same example position, divide its coordinates by two and take the integer parts to get the stored chroma column 2 and row 1. The start of the chroma plane is offset 32. The second stored chroma row begins eight bytes later at offset 40. Each Cb/Cr pair occupies two consecutive bytes. Column 2 therefore starts four bytes into that row, giving Cb at offset 44 and Cr at offset 45.

The sample at luma position four, three uses the stored chroma cell whose Cb byte is 44 and Cr byte is 45.
Chroma indexing advances two bytes per stored pair. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

This identifies the 4:2:0 stored cell associated with the small group of luma positions. A particular image converter’s reconstruction still depends on its chroma siting and interpolation rules. When testing a conversion, store the reported format and siting along with the buffer address calculation. Reading the two bytes in reverse order would represent an NV21-style arrangement, rather than the Cb/Cr convention used here.

Account for the coded dimensions and crop

A displayed area can be smaller than the coded or allocated frame. A crop changes the local pixel coordinates seen by the viewer, while the source buffer still begins at its own origin and uses its own row pitch. Some APIs expose offsets explicitly. Others provide a plane pointer already adjusted to a requested image map. Confirm the contract before adding a crop offset in a second place.

Padding bytes are allocated storage and usually do not represent visible samples. When saving a tightly packed test fixture, copy only the active bytes from each row and describe its new stride. When inspecting an original buffer returned by a device, respect each row’s declared pitch. Two buffers with the same displayed image can have different byte counts because the storage padding differs.

Verify three known byte locations

On an invented patterned frame, mark a luma position in the last row and the Cb/Cr pair in the second chroma row. Check offsets 28, 44 and 45 against a separately constructed byte list. Include a visible difference between the Cb and Cr values so pair order is observable. Save frame width, height, plane base offsets and per-plane pitch with the test data. Those fields make the result reproducible regardless of how the pixels are later displayed.

The contiguous example uses 32 bytes for luma and 16 for chroma, for a total of 48 bytes. Of those, 24 luma bytes and 12 chroma bytes carry active samples. The other twelve bytes are row padding. A tightly packed export of the same samples would use 36 bytes and start the chroma plane at byte 24. Comparing these two byte counts checks the storage convention without relying on the rendered image.

Source notes. Microsoft’s 8-bit YUV formats guide describes the NV12 plane order. The Linux video API reference distinguishes linear contiguous and multi-planar forms and describes subsampling and pitch. The six-by-four layout is invented. Find related material in the image resources and technical article directory.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

咨询 在线留言 电话:18028484626
微信 微信扫码添加我