Avisynth TemporalDegrain

From wiki.selur.net
Jump to navigation Jump to search

TemporalDegrain is a slow, thorough temporal degrainer for heavy, "dancing" grain. It combines an FFT3D prefilter, two motion-compensated degrain passes and a limited contra-sharpening.

Filtering → Avisynth → DeGrain

TemporalDegrain controls in Hybrid
TemporalDegrain controls in Hybrid

What it does

  1. An FFT3D prefilter builds a calm copy of the clip; the motion vectors are searched on it.
  2. A first MDegrain pass denoises the clip, but may not change it more than the FFT3D copy does.
  3. A second MDegrain pass denoises further.
  4. A contra-sharpening gives back sharpness, but never more than the source had.

With the higher PreFiltering (HQ) levels HQDn3D also runs on the search clip, and after the second pass at the highest level.

Typical use: strong, moving grain that simpler denoisers cannot remove. The filter is slow. TemporalDegrain2 is an improved version of the same idea.

Requirements

The GPU option needs a DirectX capable graphics card (FFT3DGPU). Everything else runs on the CPU and ships with Hybrid.

Settings

Control Parameter Range / values Hybrid default Meaning
PreFiltering (HQ) HQ disabled, default, additional denoising default Disabled: no HQDn3D on the search clip. Default: HQDn3D on the search clip. Additional denoising: also a light HQDn3D after the second pass.
GPU GPU on/off off Use FFT3DGPU instead of FFT3DFilter for the prefilter.
Sigma sigma 0–64 16 Strength of the FFT3D prefilter.
Width / Height bw / bh 4, 8, 16, 32, 64, 128, 256, 512 16 / 16 Block size of the FFT3D prefilter.
Degrain degrain 1–3 2 Number of frames on each side (MDegrain1, 2 or 3).
Block size blksize 4, 8, 16, 32 8 Block size of the motion search.
Overlap ov 0–8 4 Block overlap. The maximum follows the block size (half of it).
Accuracy pel 1–2 2 Pixel accuracy of the motion search: 1 full pixel, 2 half pixel.
SAD threshold SAD1 / SAD2 0–10000 400 / 300 Thresholds of the first and second MDegrain pass. Lower them if you see ghosting.
Limit limit 1–255 255 Maximum change per pixel; 255 means no limit.

Example

Default settings on a 10-bit YUV 4:2:0 source. Hybrid converts the clip to 8 bit for the filter and back afterwards:

# Converting from 10 to 8bit for TemporalDegrain
ConvertBits(8)
TemporalDegrain(HQ=1)
# Converting from 8 to 10bit for encoder
ConvertBits(10)

How Hybrid calls it

  • Hybrid loads the TemporalDegrain script, hqdn3d.dll, FFT3DFilter.dll (FFT3dGPU.dll with GPU), masktools2.dll, mvtools2.dll and the neo-smo RemoveGrain helpers.
  • The script only works on 8-bit YV12 (4:2:0). Hybrid converts other formats before the filter and back afterwards.
  • PreFiltering (HQ) is always written as HQ=n. The FFT3D prefilter always runs, whatever the level, so GPU, Sigma, Width and Height are always active.
  • All other values are only written when they differ from the defaults. Overlap is compared with half the block size, so with block size 8 an overlap of 2 is written and 4 is not.
  • The script is not interlace-aware; Hybrid handles interlaced input itself.
  • TemporalDegrain also offers the common options and can be added to the filter queue several times.

Background

"Temporal Degrain" v1.23 (2009) was written by Sagekilla from an idea of Didée and uses the MVTools2 plugin. Its sigma values for the further FFT3D steps follow the Sigma setting at fixed ratios. The script uses MinBlur from Didée's MCBob. The script also has a pel value of 4, which Hybrid does not offer.

See also: Vapoursynth TemporalDegrain, TemporalDegrain2, MDegrain

Sources

  • Doom9 thread: TemporalDegrain2 (describes the improvements over this script)
  • Hybrid's tooltips
  • The AviSynth+ documentation does not cover TemporalDegrain.