feat(grain): grain_sigma/grain_flat metadata — the tune=auto detection enabler (ADR-0142)#43
Merged
Merged
Conversation
…ection enabler (ADR-0142) The session's measurement campaign established the law: NVENC is genuinely worse than x265, but the pre-encode gain that closes it is REDUCTIVE and CONTENT-DEPENDENT (additive pre-sharpen washes; denoise scales with removable grain; clean content gains ~0), and mostly a matter of TUNING. So there is no single best filter -- there is a tuned reductive boost per content class and a router (tune=auto) that detects the class from analyze.* metadata and applies it. The router needs content detection that did not exist: grain_estimate computes per-band RMS residual but emitted zero frame metadata (trapped in the PEL_SEC_FILMGRAIN side-data). This ships the first and highest-leverage enabler: grain_estimate now emits lavfi.pelorus.grain_sigma (peak per-band RMS over the edge-gated flat bands -- structure excluded by construction, so what survives is grain stddev) and lavfi.pelorus.grain_flat (the flat fraction = confidence), via the ADR-0136 av_dict_set pattern. No interop ABI change, no shader change, the value was already computed; the side-data path is untouched. Verified discriminating (heavy-grain 0.019 vs clean-ish Bluray 0.012) and unblocks the proven -34% grainy denoise route. ADR-0142 records the full tune=auto design (8-class routing table + validation priority + the encoder-integration patch parallel track). Follow-ups: the remaining detection enablers (noise_sigma, dark_frac), the per-leg validations, the router itself, and the encoder-patch track. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The foundational first step of
tune=auto(the content-adaptive pre-encode router):vf_pelorus_grain_estimate_vulkannow emitslavfi.pelorus.grain_sigmaandlavfi.pelorus.grain_flatas per-frame metadata, so the router can detect grainy content. ADR-0142 records the full design.Why (the law this session established)
With the real tooling (vmaf v1.0.16 + v0.6.1-NEG, x265-enabled ffmpeg, on-hardware NVENC): NVENC is genuinely worse than x265, but the pre-encode gain that closes it is REDUCTIVE and CONTENT-DEPENDENT.
→ There is no single best filter, there's a tuned reductive boost per content class + a router. That router needs detection metadata that didn't exist (only
analyzeemitted any).The enabler
grain_estimatealready computes per-band RMS residual over edge-gated locally-flat pixels (structure excluded by construction → what survives is grain stddev) but trapped it in thePEL_SEC_FILMGRAINside-data. This emits the peak asgrain_sigma+ the flat fraction asgrain_flat(confidence), via the ADR-0136av_dict_setpattern — no interop ABI change, no shader change, the value was already computed; the side-data path is untouched. Verified discriminating: heavy-grain clip 0.019 vs clean-ish Bluray 0.012.ADR-0142 (Proposed) records the full design
The 8-class routing table (grainy→denoise, anime→dehalo+aa+deband, textured→spatial-denoise, re-encode→demosquito, dark→dark-masked-denoise, screen→deblock, sports→denoise+mc-warp, clean→no-op), the validation priority (grainy scaling first — the proven lever; every leg iso-bitrate-proven + held-out-confirmed before it enters the router), the constraints (analyze.texture is derived; motion needs upstream mc), and the encoder-integration patch parallel track (NVENC/QSV/AMF features FFmpeg underuses).
Deliverables
Filter (metadata only) + ADR-0142 + README index +
grain_estimate.mdmetadata section + changelog + regenerated patch 0006. No ABI/shader/surface-behavior change beyond the additive metadata.🤖 Generated with Claude Code