-
Notifications
You must be signed in to change notification settings - Fork 0
Deblocking
KDeblock(clip, int "quality", float "str", float "thr", float "bratio", clip "qpclip", int "qp", bool "soft", int "show")
Source QP–adaptive deblocking filter.
The deblocking approach follows that introduced in JPEG Post-Processing and is the same algorithm used by FFmpeg’s spp and AviSynth’s SmoothD.
Unlike SmoothD, which applies a uniform quant level globally (ignoring the source content), KDeblock varies the strength per block using the MPEG‑2 source’s QP table. The original paper notes that using the same quant value as the source yields the best results; FFmpeg’s spp follows this, whereas SmoothD and its derivatives do not use source QP values and thus can over‑blur low‑noise areas — an “incomplete filter.” KDeblock, by adapting to the source QP, is a “complete filter.”
FFmpeg’s spp is also a “complete filter” using source QP, but it has fewer parameters. KDeblock exposes parameters such as the contribution ratio of B‑frame QP, minimum QP threshold to apply, overall strength, etc.
In addition to the CUDA version, there is an AVX implementation for fast CPU processing (still slower than CUDA).
Note: To obtain source QP values, the source filter must support outputting QP. Currently only Amatsukaze’s AMTSource does; without it, QP‑based processing is unavailable (i.e., without Amatsukaze you get an “incomplete filter”).
- CUDA support: Yes
- clip – Source clip. If qpclip is not specified, the QP table is taken from this clip.
-
int quality = 3 – Number of DCT/IDCT applications. Applied
(2 << quality)times. Valid values: 1–6. - float str = 0 – Strength modifier. 0 re‑quantizes using the source QP value. Smaller = weaker; larger = stronger. At −4.0, the quant level becomes 0, so −4.0 is the minimum.
- float thr = 0 – Minimum QP threshold to apply. Only blocks with QP ≥ thr are processed. QP is non‑negative; valid values are ≥0. Although the original algorithm already weakens filtering in low‑QP areas, setting this threshold lets you skip filtering entirely below it. Larger values mean only heavily compressed (blocky) areas are filtered.
-
float bratio = 0.5 – Consideration ratio for B‑frame QP. Unlike JPEG (single reference), MPEG‑2 P/B frames store differences, so reference frame quality must be considered. B‑frames are commonly encoded with higher QP, so relying only on the B‑frame’s QP makes the filter unstable. KDeblock computes the effective QP as:
(effective QP) = (B-frame QP) * bratio + (previous non-B-frame QP) * (1 - bratio) - clip qpclip – Separate clip providing QP values (useful when an intermediate filter between the source and KDeblock drops frame properties).
- int qp = -1 – Apply a uniform QP globally instead of reading from the source. If the source has no QP and qp is not set, the filter is disabled.
- bool soft = false – Use “soft” re‑quantization (as in FFmpeg’s spp). Usually not recommended due to overall blurring.
-
int show = 0 – Debug visualization:
- 1: Show whether source QP, fixed qp, or disabled is used (top‑left)
- 2: Paint blocks with QP ≥ threshold in blue
Returns a clip containing only QP values extracted from the source. Since QP data is small, this can reduce memory usage depending on workflow.
- CUDA support: Yes
Converts source QP values into frame data so you can visualize the QP table. Since QP exists per 16×16 block, the clip size becomes (ceil(width/16), ceil(height/16)) when the source is (width, height).
- CUDA support: Yes
- clip – Source clip
- bool nonb = false – If true, converts the previous non‑B frame’s QP; if false, includes B‑frames and uses the current frame’s QP.
Returns the frame type (I, P, B). This is a runtime filter for use with ScriptClip, etc. Frame types follow FFmpeg’s AVPictureType (I=1, P=2, B=3).
※ These filters depend on frame properties returned by Amatsukaze’s AMTSource, and do not work with clips from other sources.