Skip to content

Add VideoFrame.solid() - #2482

Merged
WyattBlue merged 1 commit into
masterfrom
videoframe-solid
Oct 26, 2026
Merged

WyattBlue merged 1 commit into
masterfrom
videoframe-solid

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Adds VideoFrame.solid(width, height, color="black", format="yuv420p") to create a frame filled with one color. Today that takes a numpy array and from_ndarray, or writing bytes into planes by hand while accounting for line_size padding.

color is either a string av_parse_color understands ("red", "#ff8000", "white@0.5") or an (r, g, b) / (r, g, b, a) tuple of 0–255 ints.

Swscale converts a 16x16 RGBA block to the target format. av_read_image_line2 reads that block's components, and av_image_fill_color writes them across the whole frame. The result matches reformat(), including its colorspace and range tags, and only the small block goes through swscale. This works for packed, planar, semi-planar, subsampled, alpha, and high-bit-depth formats. Paletted and Bayer formats raise ValueError because a single component value can't describe them.

Tests cover several formats at an odd size (33x17), equality with reformat(), alpha, and invalid input.

The color goes through swscale on a 16x16 RGBA block, then av_image_fill_color copies the resulting components across the frame, so the result matches reformat() without converting every pixel. Paletted and Bayer formats are rejected because a single component value cannot describe them.
@WyattBlue
WyattBlue merged commit 6911aa7 into master Oct 26, 2026
10 checks passed
@WyattBlue
WyattBlue deleted the videoframe-solid branch October 26, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant