Vapoursynth TDecimate

From wiki.selur.net
Revision as of 09:53, 16 November 2026 by Selur (talk | contribs) (Update to current Hybrid behaviour; code as <pre> (via update-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

TDecimate removes duplicate frames and is the second half of an inverse telecine, after field matching. It drops the most similar frames, either a fixed number per cycle (29.97 → 23.976 fps) or so that any target rate is reached, and can handle sources that mix film and video.

Filtering → Vapoursynth → Frame → Reduction

TDecimate controls in Hybrid
TDecimate controls in Hybrid

What it does

TDecimate compares each frame with its neighbor and measures how different they are. In modes 0 and 1 it works in cycles: per Cycle frames it drops CycleR frames, either the most similar ones (mode 0) or those from the longest runs of duplicates (mode 1, useful for anime). Modes 2 and 7 decimate to an arbitrary target Rate; mode 7 does it with thresholds. The Hybrid option handles material where film (24p) and video (30p) sections alternate.

Settings

Control Parameter Range / values Hybrid default Meaning
Mode mode 0, 1, 2, 7 0 0: drop the CycleR most similar frames per cycle; 1: drop from the longest duplicate runs; 2: arbitrary rate; 7: arbitrary rate by thresholds.
Cycle cycle 2 – 100 5 Frames per cycle (modes 0/1).
CycleR cycleR 1 – Cycle − 1 1 Frames dropped per cycle (modes 0/1).
Hybrid hybrid no handling, blend 30p→24p keep 24p, blend 24p→30p keep 30p no handling Handling of mixed film/video material (modes 0/1 with CycleR 1). 30p→24p blends the video parts down; 24p→30p blends the film parts up and keeps the input rate.
no blend noblend on/off on Drop a duplicate instead of blending it with its neighbor (modes 0/1).
VidDetect vidDetect A, B, A or B, A and B, A and (B or C) A and B Which tests (A: field matches, B: metrics above VidThresh, C: no local minimum) mark a cycle as video (with Hybrid handling).
ConCycle conCycle 1 – 2 1 Consecutive cycles that must be detected as video (with Hybrid handling).
SDLim sdlim −10 – 10 0 Minimum distance between two dropped frames (modes 0/1 with CycleR > 1).
Rate rate fraction 24000/1001 Target frame rate (modes 2/7).
Max ndl maxndl 0 – 1024 0 Largest number of non-duplicate frames in a row (mode 2; 0 = not set, the plugin decides).
m2PA m2PA on/off off Lifts the read-ahead limit of 100 frames in mode 2, so one pass gives the same result as with stored metrics; long cycles can stall processing for minutes when a new cycle starts.
DupThresh dupThresh 0 – 100 1.1 (mode 1), 0.4 (mode 7) Difference (percent) below which a frame counts as a duplicate; used in modes 1 and 7 and always written there. Changing the mode sets the plugin's default for that mode.
VidThresh vidThresh 0 – 100 1.1 (modes 0/1), 3.5 (mode 7) Difference above which a frame counts as video (mode 7, and modes 0/1 with Hybrid handling). Changing the mode sets the default for that mode.
SceneThresh sceneThresh 0 – 100 15 Difference that counts as a scene change (mode 7, and modes 0/1 with Hybrid handling).
DenoiseThresh nt 0 – 10 0 Differences below this value are ignored when comparing frames, so grain does not make every frame look different.
Block (X/Y) blockx / blocky 4 – 2048 (powers of 2) 32 / 32 Size of the blocks used for the difference metrics.
Chroma chroma on/off on Include chroma in the metrics.
Denoise denoise on/off off Denoise the frames before the metrics are computed; helps noisy sources and dot crawl, a little slower.
SSD ssd on/off off Sum of squared instead of absolute differences; the default thresholds are meant for absolute differences.
Display display on/off off Print the metrics and decisions onto the frame.

Controls that the chosen Mode, CycleR and Hybrid setting do not use are disabled.

Example

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

# Decimate using TDecimate
clip = core.tivtc.TDecimate(clip) # new fps: 20

How Hybrid calls it

  • TDecimate works on 8–16-bit YUV 4:2:0, 4:2:2 and 4:4:4; other formats are converted first. Thresholds are percentages and do not depend on the bit depth.
  • Most options are only written when they differ from Hybrid's defaults; the options for Hybrid handling are written with Hybrid handling on. DupThresh is always written in modes 1 and 7, VidThresh and SceneThresh in mode 7 and with Hybrid handling.
  • Frame rate, modes 0/1: the input rate × (Cycle − CycleR) / Cycle, e.g. 29.97 fps with 5/1 → 23.976 fps. With "blend 24p→30p, keep 30p" the input rate is kept.
  • Frame rate, modes 2/7: the Rate fraction; Hybrid also sets this exact rate on the output.

Background

TIVTC

TDecimate comes from tritical's TIVTC package for AviSynth; the VapourSynth plugin is dubhater's port. It is normally used after field matching (TFM or a similar filter), whose hints it can read. In the plugin, DupThresh is only used by modes 1 and 7; its default there is 1.1 with chroma (1.4 without), and in mode 7 the plugin falls back to 0.4 if no value is given. VidThresh and SceneThresh also drive the video detection and the blending at scene changes when Hybrid handling is on.

For fixed-pattern decimation without analysis see Vapoursynth SelectEvery; for blended (not duplicated) frames see Vapoursynth sRestore and Vapoursynth ExBlend.

Sources