Vapoursynth ReplaceBlackFrames

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

ReplaceBlackFrames finds frames whose average brightness is below a threshold and replaces them with the last non-black frame or with frames interpolated between the surrounding non-black frames.

Filtering → Vapoursynth → Frame → Replace

ReplaceBlackFrames controls in Hybrid
ReplaceBlackFrames controls in Hybrid

What it does

The average of the first plane is measured for each frame; frames at or below Threshold count as black. With previous they are replaced by the last good frame; with the interpolating methods a run of black frames is rebuilt from the good frames before and after it. Black frames at the very start or end of the clip (with no good frame on one side) stay as they are.

Requirements

  • interpolateSVP, interpolateCPU: SVP must be installed (only then are they listed).
  • interpolateRIFE: a Vulkan-capable GPU.

Settings

Control Parameter Range / values Hybrid default Meaning
Method method previous, interpolateSVP, interpolateCPU, interpolateRIFE previous Repeat the last good frame, or interpolate with SVP on the GPU, SVP on the CPU, or RIFE.
Threshold thresh 0.002 – 0.999 0.1 Normalized average brightness (0 = black, 1 = white) at or below which a frame counts as black.
SC thresh rifeSC 0 – 1 0.15 Scene change threshold for interpolateRIFE: if the frames before and after the black run differ by more, RIFE does not interpolate across the cut. 0 = off.
Debug debug on/off off Shows the average brightness of each frame in the preview.
Tools: SCD – scd, misc, std, mv – Scene change detection (only for interpolateRIFE with SC thresh above 0).

Example

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

from ReplaceBlackFrames import ReplaceBlackFrames
rbf = ReplaceBlackFrames(clip=clip, tools={'scd': 'scd'})
clip = rbf.out

How Hybrid calls it

  • Color formats: previous works on any format, the SVP methods on 8-bit YUV 4:2:0, interpolateRIFE on 32-bit float RGB; the clip is converted as needed. ReplaceBlackFrames is not offered for interlaced material.
  • Values are normalized and do not depend on the bit depth. Options are only written when they differ from the defaults.
  • RIFE uses its default model (rife-v4.5 ensemble) without TTA or UHD.
  • Replaced frames keep the frame properties (such as the frame duration) of the original frame.
  • Frame count and frame rate do not change.

Background

Threshold and video levels

The default 0.1 is about 25 on the 8-bit scale. In limited-range video black sits at 16 (about 0.063), so very dark frames that are not fully black can also count as black; lower the threshold if dark scenes are replaced.

Sources