Vapoursynth DeblendS

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

DeblendS restores material that was frame-rate converted by blending, for example film or PAL converted to NTSC. It is a newer, faster reimplementation of Vapoursynth sRestore with the same detection; Hybrid marks it experimental.

Filtering → Vapoursynth → Frame → Deblend

DeblendS controls in Hybrid
DeblendS controls in Hybrid

What it does

DeblendS detects blended frames with the same signals and decisions as sRestore. In output mode 6 it resolves the cadence and decimates to the true frame rate; all other modes keep the frame rate and either replace each blend with a neighbor or rebuild it from its neighbors. Optionally the rebuild uses motion-compensated interpolation instead of a simple 50/50 merge.

Requirements

  • The SVP engine for OpticalFlow is only offered when SVP is installed.

Settings

Control Parameter Range / values Hybrid default Meaning
Omode omode 1 – 6, pp0 – pp3 6 6: decimate to FPS (the only mode that changes the rate). 1: previous frame, 2: next frame, 3: the neighbor that differs less, 4: by the blend/clear ratio of the neighbors, 5: full double-blend removal (may shift by two frames). pp0–pp3: rebuild the blend from its neighbors (pp0 no mask, pp1 difference mask, pp2 blend mask, pp3 both plus a chroma blur); slower.
FPS true_fps 0.0001 – 1000 23.976 Target rate (Omode 6 only). It must match what the source really contains and lie between a fifth of the source rate and the source rate; otherwise the clip passes through 1:1.
Mode mode −4 … −1, 1 … 4 2 1: basic frame selection; 2: with duplicate detection; 3: with merge detection, without duplicate detection; 4: both (try it if 2 misses blends). Negative: the same with chroma in the detection.
Thresh thresh 1 – 44 16 Detection threshold as in sRestore; lower is more sensitive (worth lowering for anime).
Det. size bsize 32, 48, 64 32 Edge length of the detection thumbnails; a calibration value, not a quality setting – leave it at 32 unless a source gives poor results.
Denoise denoise none, RemoveGrain, NLMeans (light), NLMeans (heavy) none Spatial denoising of the detection clip only; the output frames are untouched. Helps when noise, blocking or ringing disturb the detection.
OpticalFlow optical_flow on/off off Rebuild blends with motion-compensated interpolation; for live action or CG, not for anime.
Engine optical_flow_engine mvtools, svp mvtools Optical-flow engine (with OpticalFlow).
Pel of_pel pixel, half-pixel, quarter-pixel half-pixel Sub-pixel precision of the motion search (mvtools only).
Blk size of_blksize block sizes 16 Block size of the motion search (mvtools only); smaller follows finer motion but is slower and less stable on flat areas.
Tools: MV – mvgpu, mvutensils, mv – MVTools implementation for OpticalFlow.
Tools: Expr – akarin, cranexpr, std – Expression plugin.
Tools: NLMeans – knlm, vszip, nlm_ispc, knlmvk, vszipcl/vszipcu – NLMeans implementation for Denoise.
Tools: RG – zsmooth, neo_smo – RemoveGrain implementation for Denoise.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x356, 25 fps):

# adjusting color space from YUV420P10 to YUV444P16 for vsDeblendS
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16)
# adjusting frame count and rate with DeblendS
clip = deblendS.deblendS(clip, src_fps=25/1, true_fps=24000/1001, tools={'mv': 'mvutensils', 'expr': 'akarin', 'nlmeans': 'vszipcu', 'rg': 'zsmooth'})

How Hybrid calls it

  • DeblendS works on YUV clips of any bit depth; other formats are converted first. Interlaced input is allowed. The script handles the bit depth itself.
  • Hybrid passes the current frame rate of the clip as the source rate; FPS is only written with Omode 6.
  • Values are only written when they differ from the defaults (Hybrid's defaults are the script's).
  • Frame rate: with Omode 6 the output rate is FPS and the frame count shrinks accordingly (e.g. 29.97 → 23.976 fps keeps 4 of 5 frames). If FPS is above the source rate or below a fifth of it, the script passes the clip through unchanged and Hybrid keeps the source rate. All other modes keep rate and frame count.
  • In the side-by-side preview the unfiltered clip is rate-converted to the same rate.
  • DeblendS also offers the common options (Gimmick only).

Background

Processing order

DeblendS keeps its detection state and advances it strictly in frame order, caching the results: seeking backwards is cheap, but a far jump forward must process all frames in between. Like the AviSynth original it does not reset at scene cuts.

Sources