forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

h264rc.report.md3.4 KiBHistoryRawDownload

h264rc: does ec-h264 hit its bitrate?

Setup: 1080x1920, 30 fps, 10 s (300 frames), synthetic ffmpeg lavfi sources piped as raw yuv420p. Target 8 Mb/s. ec-h264 via crates/ec-h264/examples/h264_clip_encode.rs (4 threads, CABAC, gop 60, per-picture QP from H264_TRACE=1). Reference: ffmpeg -c:v libx264 -preset veryfast -b:v 8M -bf 0. Run on host b (server). Actual = bytes x 8 / 10 s.

source target ec-h264 actual ec-h264 avg QP ec pics at QP 10 ec QP range x264 actual
testsrc2 8 Mb/s 7.703 Mb/s 27.5 2 10-30 8.025 Mb/s
mandelbrot 8 Mb/s 7.972 Mb/s 35.7 0 15-38 8.376 Mb/s
cellauto 8 Mb/s 8.305 Mb/s 45.1 0 26-51 5.087 Mb/s
noise (geq=random(1)*255) 8 Mb/s 8.982 Mb/s 50.7 0 26-51 10.238 Mb/s
smptebars (control, flat) 8 Mb/s 0.037 Mb/s (46 KB) 10.1 296 10-26 0.021 Mb/s

Verdict

No rate-control undershoot bug on these sources. Three sources land within about 4 % of target (testsrc2 -3.7 %, mandelbrot -0.3 %, cellauto +3.8 %). The flat control undershoots badly, and x264 undershoots it just as badly (0.021 Mb/s), so that part is legitimate content limits.

  • smptebars: 296 of 300 pictures sit on the QP 10 floor and the whole clip is 46 KB. The floor stops the encoder from spending more bits. This is the expected undershoot on trivial content.
  • noise overshoots by 12 % (8.98 vs 8.0). Its average QP of 50.7 means it is pinned at the QP 51 ceiling and still cannot shed the bits, so this is an overshoot at the top clamp, not an undershoot.
  • The 0.32 Mb/s edith case is not reproduced by pure colour bars (0.037 Mb/s here). The edith clip must have more content than smptebars, so its low rate needs a separate check on the real clip. That was out of scope here: only synthetic sources were used.

Floors and clamps

  • crates/ec-h264/src/enc/rc.rs:87: qp.round().clamp(10.0, 51.0). This is the picture-level QP floor. The comment says it is a deliberate choice: below QP 10 the encoder spends bits the viewer cannot see. Consequence: flat content cannot reach the target.
  • crates/ec-h264/src/enc/mod.rs:783: the per-row correction (job.qp + delta).clamp(10, 51) uses the same floor, so row deltas cannot lower QP below 10 either.
  • crates/ec-h264/src/enc/rc.rs:81: leaky-bucket correction capped at +/-6 QP. rc.rs:76 caps the per-picture step at -4/+2 for P pictures.
  • crates/ec-h264/src/enc/mod.rs:257: constant-QP is clamped to 0..51 (only used when bitrate is 0).
  • Target-to-QP mapping: rc.rs:61, qp = 6 * log2(complexity / target), with complexity measured per picture type (rc.rs:97-106) and target from frame_target (rc.rs:134-142).

Suggested fix

No fix needed for the synthetic cases. If the edith clip is shown to be non-trivial content and still undershoots, the candidate is the QP 10 floor at rc.rs:87 and mod.rs:783. Lowering the floor would trade quality for bitrate on flat content, which the existing comment rejects on purpose. The noise overshoot could be addressed by letting the bucket correction reach beyond QP 51 for intra-heavy content, but the gain is small (+12 % on pathological noise).

Caveats

  • x264 ran with its default QP range and no rate-control tuning beyond -b:v 8M -bf 0.
  • Average QP was taken from per-picture QP (H264_TRACE), unweighted by picture size.
  • Single run per source, no repeats.