DEV Community

Peiguan
Peiguan

Posted on

Is There Visible Banding in This Bama Bound Clip? A Sky Gradient / Posterization Detector (Python + ffmpeg, Tested)

I maintain bamabound.app, and I wanted a post-download check for banding — those false contours that show up as steps in a sky or a field when a smooth gradient has been posterized. I ran the check today, 24 November 2026, on the official imported preview from the homepage, plus three labeled synthetic controls. The official file is an "Imported field preview," an external reference of the sign clip, not a result generated by this studio, and I did not upload it anywhere.

The clip I measured is ref.mp4, SHA-256 9dcb91afc8f985baaa1bae746380d2e2514b6d84abd5108b3b0284eb1fc6492a. Re-probed today it is 720×1280, H.264 High, yuv420p, 24 fps, 193 frames, video 8.041667 s. I am asking a narrower question than "does the field look grainy." I want to know whether a smooth region is using consecutive 8-bit luma codes, or skipping them in long flat bands.

The detector

There is no hidden model. The script decodes frames with ffmpeg to PNG, converts to Rec.709 luma Y' = 0.2126 R + 0.7152 G + 0.0722 B, rounded to an integer 0–255, and then walks every column of a documented region of interest from top to bottom. For each column it records the length of each flat run of identical luma, and the size of the step when the luma finally changes.

From that walk I keep four numbers: the count of unique levels in the ROI, the luma min and max, how many integer codes in [min, max] are missing (missing_fraction), the longest and median flat run, and the median of the nonzero absolute steps.

The 8-bit threshold is: flag a frame as banded if missing_fraction >= 0.50 or median_nonzero_step >= 2. I chose those cuts because a genuine 8-bit smooth ramp uses consecutive codes and steps of 1. A forced step-16 ramp misses most of the codes in its range and steps by 16. A nearly flat sky that still uses every code in a narrow range, with steps of 1, is a shallow 8-bit gradient, not posterization, even if the flat runs are long.

The 16-bit control needs a different rule. A 1,280-row ramp across 0..65535 is supposed to skip codes; missing_fraction will be about 0.98, and the typical step will be about 51. For 16-bit gray I therefore say a frame is not banded if and only if unique_levels == height and max_flat_run == 1. That is the signature of a sampled high-bit ramp with no plateaus.

For the official imported preview, the ROI is a sky box above the maroon banner. I find the banner with the same HSV rule I have used in earlier guides (hue 310–355, saturation ≥ 0.40, value 0.10–0.75, a row counting as banner if at least 15% of its pixels pass, short gaps merged). The box starts at row 16 and stops 8 rows above the banner, columns 180–540. I do not use the field as the primary ROI: grass is textured, and a textured region will always show many unique levels.

The synthetic controls

All three fixtures are 720×1280, 24 fps, 24 frames, silent, and encoded as FFV1 so the encoder does not add its own contours. They are labeled synthetic. They are not studio output.

clean16 is a 16-bit vertical luma ramp from 0 to 65535. The detector reported unique=1280 (one level per row), luma 0..65535, missing_fraction 0.98046875, step_med 51.000000, max_flat 1, median_flat 1.000000, and 0/24 frames banded under the 16-bit rule.

mild8 is the same ramp quantized to 8-bit with no dither (value // 257). unique=256, luma 0..255, missing_fraction 0.000000, step_med 1.000000, max_flat 6, median_flat 5.000000, 0/24 banded. The median run of 5 is what you should expect from 1,280 rows and 256 codes.

poster16 forces that 8-bit ramp onto multiples of 16, a designed step of 16, with 16 unique codes from 0 to 240. unique=16, missing_fraction 0.933610, step_med 16.000000, max_flat 81, median_flat 80.000000, 24/24 banded. That is the control the 8-bit threshold is for.

The official imported preview

The banner is present on all 193 frames. The top of the band moves between rows 118 and 218; the bottom moves between 418 and 519. On frame 0 the band is rows 118–467, height 350, and the maximum row coverage is 0.9583333333333334.

Across the 193 sky boxes: unique levels ranged from 13 to 41, luma from 26 to 155, the median missing_fraction was 0.058824, the median nonzero step was 1.000000, the longest flat run on any frame was 38, and the median of the per-frame median runs was 7.000000.

Frame 0, a clean shallow sky: unique 15, luma 132–146, missing codes 0, step 1, not banded, ROI [16, 110, 180, 540].

Frame 96, the middle of the clip: unique 24, luma 120–144, missing_fraction 0.04, step 1, banner 196–507, ROI [16, 188, 180, 540], not banded.

Four frames — 67, 118, 119, and 120 — tripped the missing_fraction rule only. All four still have median_nonzero_step 1.000000. The worst is frame 118, missing_fraction 0.7378640776699029, unique 27, luma 43–145. Frame 119 has luma_min 26, which is not a sky value. On those frames the fixed box above the moving banner is no longer a pure gradient; darker picture has entered the ROI, the range has widened, and some codes in that wider range are unused. That is not the same thing as a step-16 posterized ramp.

Under the step test, I do not treat the official imported preview as posterized. 189 of 193 frames stay under the threshold, the typical step is 1, and the four misses are mixed ROIs, not skipped-code contours in a smooth sky.

I did not lean on the field for the official verdict. A left-side or centre field box is full of texture (I saw unique counts in the 200s when I scouted it) and would not tell me anything useful about false contours.

Why a long flat run is not, by itself, a verdict

This is the part I had to get right before I trusted the official numbers. A sky that only spans 15 eight-bit codes across 94 rows, like frame 0 (luma 132–146, unique 15, missing 0), will have median runs of several pixels. Frame 0's median flat run is 3.0 and its longest run is 30. That is what a shallow, in-range gradient looks like at 8-bit. If I had flagged "any max_flat_run above 16," I would have called a clean sky banded, and I would have been measuring the slope, not the contours.

The missing-code fraction and the median step are doing the work. Frame 0 uses every code in 132–146 and steps by 1. The posterized control, by design, uses 16 codes in 0–240, misses 0.933610 of that range, and steps by 16, with a median run of 80.000000 and a longest run of 81. Those two pictures are not close, and the threshold keeps them apart.

The 16-bit clean ramp is the other reminder. Its missing_fraction is 0.98046875, which would have failed the 8-bit rule on every frame, and its median step is 51.000000, which is exactly the spacing you get when you sample 65,536 levels with 1,280 rows (65,535 / 1,279 ≈ 51.24). The 16-bit rule exists so I do not call a high-bit source "banded" for being high-bit. unique=1280 and max_flat=1 is the pass.

Why I did not use a blur residual or ffmpeg signalstats for the official verdict

A common alternative is to blur the frame slightly and look at the residual for spatially coherent ridges. That can be a good visual, but it introduces a blur radius I would then have to justify, and it is harder to quote as a single threshold. signalstats and a luma histogram will tell you the range and the average, not whether the unused codes are arranged as false contours. I wanted a method I could write down in a few lines and re-run on a fixture with a known step size.

I also did not run the official file through an 8-bit re-encode and then compare it to itself. That would have mixed encoder decisions into a question about the decoded picture I already have. The official source is already 8-bit yuv420p. The PNG extract is a lossless copy of that decoded 8-bit picture, and that is what I walked.

If this were a billed download

The official file is not a billed generation. If I were checking a clip I had just paid for, I would still use the same sky box and the same step test, and I would still want the forced step-16 control in the same run so I know the detector still trips when it should. I would not treat a handful of frames whose ROI has picked up a dark edge — luma_min 26, as on frame 119 — as proof that the studio posterized the sky. I would look at the median step first. Today's official median step is 1.000000.

One 480p Field banner run, if you are paying for a generation rather than inspecting this imported preview, is $7.98 / 798 credits on the pricing page I re-checked today, with the higher tiers and packs listed above. Looking different from the photo is not, by itself, a failed order. Banding, if it were actually there under this test, would be a picture fact I could attach to a support mail, not a feeling about the sky.

Limitations I am willing to live with

The HSV banner finder can move the top of the box from row 110 on frame 0 to row 188 on frame 96 as the banner shifts. That is why the mid-clip sky box is taller, and why a few later frames include darker picture. A hand-drawn static sky rectangle might have avoided frames 118–120, but it would also have been a silent crop of whatever I happened to like. I kept the rule automatic and reported the four frames it flagged.

The walk is vertical, because the fixtures are vertical ramps and a sky usually gradients top to bottom. A horizontal posterization in a different picture could be missed. I did not see a reason, on this official clip, to swap the axis for the sky.

The threshold numbers, 0.50 and 2, are choices. They are not physical constants. I chose them so the mild 8-bit ramp passes and the step-16 ramp fails, and then I applied the same cuts to the official file. If I moved the missing_fraction cut to 0.20, more official frames with mixed ROIs would trip, and the median step would still be 1. That would not have changed the official verdict I am willing to stand on: this imported preview's sky is not a posterized staircase.

How to run it

python3 devto_make_banding_fixtures.py --out files/banding
python3 devto_banding.py \
  --official src/ref.mp4 \
  --clean16 files/banding/clean16.mkv \
  --mild8 files/banding/mild8.mkv \
  --poster16 files/banding/poster16.mkv \
  --out files/banding/banding_report.json
Enter fullscreen mode Exit fullscreen mode

Both scripts exited 0 on this box today. The JSON is the record; the figures above are copied from it.

A visitor who just wants a clip, rather than a luma walk, can start from bamabound.app or the pricing page. I re-checked those prices this afternoon: 480p is $7.98 / 798 credits, 720p $9.98 / 998, 1080p $16.98 / 1923, 4k $24.98 / 3921; packs $22.99 / 3, $59.99 / 10, $99.99 / 20, tax added at checkout. The official file I measured is not a billed generation.

This studio is not affiliated with the University of Alabama. The clip is a joke, not an admission letter. The studio checks final text only. The banding question, for this imported preview and this threshold, has a measured answer: the forced step-16 control is banded, the clean high-bit and mild 8-bit ramps are not, and the official sky is not posterized under the step test.

Top comments (0)