﻿# Mapped video planes: preserve row padding when building an inference input

Mapped video planes: preserve row padding when building an inference input. A practical streaming-video guide with failure mechanisms, a controlled scenario, acceptance evidence and primary references.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/sv-mapped-video-planes-padding-stride/
Language: en

A frame mapper returns padded image rows, but an application assumes every row begins immediately after visible pixel bytes. Images become skewed when copied into the inference tensor.

## The media mechanism

Media plane offsets and row strides describe the mapped representation. Visible width and channel count do not determine every byte address, especially for planar formats or device-backed allocations.

## Establish the pipeline boundary

Read plane offsets and strides from the mapped video representation. Packed and planar formats use different addressing, and visible width does not include every padding byte that an allocator may place between rows.

Keep mapping lifetime separate from layout correctness. An array view that survives unmap or buffer release can reference invalid or reused storage even when its initial pixels looked correct. Asynchronous inference needs an ownership policy that keeps the required memory alive or makes an appropriate copy.

Compare a padded fixture with a tightly packed reference using visible pixels only. Fill padding with a distinctive pattern so accidental inclusion is detectable. Repeat for more than one plane and after allocation changes; a single familiar RGB image can conceal stride assumptions that fail immediately on a different decoder or device-backed surface.

## A constructed failure case

Give each visible row a different marker and fill padding with unrelated values. A correct adapter preserves visible rows without treating padding bytes as image content or silently shifting later rows.

## A practical validation procedure

Use a padded fixture with distinct row and plane markers. Read through documented frame mapping metadata and compare the produced model input with a trusted conversion. Check map/unmap lifetime independently of layout arithmetic.

Keep an unchanged control and a deliberate failure case. Change the relevant setting or interruption independently, then compare observed frame identities and state transitions. Measure through recovery as well as the first error; a restarted worker can retain obsolete results or references.

## Evidence for acceptance

Retain plane offsets, strides, visible geometry and a reviewed pixel comparison.

## Recovery and limits

A correct CPU mapping does not imply that arbitrary device memory is directly host-readable.

Define whether recovery drains, discards or isolates pending frames before resuming ordinary service. Preserve compact diagnostic identities and the fixture configuration. Avoid treating a new connection or a live process as proof that previous in-flight work has finished safely.

## References and interpretation

Primary references: [GStreamer video frame layout](https://gstreamer.freedesktop.org/documentation/video/video-frame.html); [GStreamer video information and colorimetry](https://gstreamer.freedesktop.org/documentation/video/video-info.html).

This is a proposed operational validation, not an executed Retrivium benchmark. Documentation defines interfaces and supported behavior; the actual pipeline needs its own evidence. Repeat the check after relevant plugin, decoder, source or preprocessing changes.

## Related reading

Continue with [OpenEXR Python color arrays: account for automatic RGB grouping before model input](/journal/fg2-openexr-python-rgb-channel-grouping-axis/); [Shared video buffers: separate writable metadata from shared branch state](/journal/sv-buffer-copy-on-write-branch-metadata/). Their adjacent context does not replace the specific frame-flow acceptance check described here.
