Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

levels

levels(
  input: Clip,
  #{
    min_in: Int | Float,
    max_in: Int | Float,
    min_out: Int | Float,
    max_out: Int | Float,
    planes?: Array<Int>,
  }
)

Linearly remaps selected pixel values from the input range [min_in, max_in] to the output range [min_out, max_out].

The input must be one fixed-format planar Gray or YUV clip. Planar RGB clips are not supported. Integer formats use Int values in the clip format’s valid sample range. Float formats use finite Float values in 0.0..=1.0. max_in must be greater than min_in, and max_out must be greater than min_out.

Samples below min_in map to min_out, and samples above max_in map to max_out. Integer outputs round half up. For float clips, non-finite input samples are mapped to min_out so output samples remain in the requested range.

If planes is omitted or set to none(), every plane is processed. If planes is provided, only the listed zero-based plane indexes are processed; all other planes are preserved without modification. An empty array processes no planes.

Examples

output = source("input.mkv").std.levels(#{
  min_in: 16,
  max_in: 235,
  min_out: 0,
  max_out: 255,
})
output = source("input.mkv").std.levels(#{
  min_in: 16,
  max_in: 235,
  min_out: 0,
  max_out: 255,
  planes: [0],
})
output = source("input.mkv")
  .std.convert_format(#{ format: "grayf32" })
  .std.levels(#{ min_in: 0.1, max_in: 0.9, min_out: 0.0, max_out: 1.0 })

Input

One fixed-format planar Gray or YUV clip.

Output

A clip with the same format, resolution, timing, and metadata, with selected planes remapped to the requested output range.

Options

  • min_in (Int | Float) – Inclusive lower input bound. Use Int for integer sample formats and Float in 0.0..=1.0 for float sample formats.
  • max_in (Int | Float) – Inclusive upper input bound. Must be greater than min_in.
  • min_out (Int | Float) – Inclusive lower output bound. Use Int for integer sample formats and Float in 0.0..=1.0 for float sample formats.
  • max_out (Int | Float) – Inclusive upper output bound. Must be greater than min_out.
  • planes (Array<Int>, default: all planes) – Zero-based plane indexes to process. Unlisted planes are preserved without modification. none() uses all planes, and an empty array processes no planes.