expr
expr(
input: Clip | [Clip, Clip, ...],
#{
expr: String | Array<String>,
}
)
Evaluates reverse-polish math expressions for every pixel. Use it for custom per-pixel arithmetic, comparisons, masks, and simple clip blending when no purpose-built filter matches the operation you need.
The filter accepts 1 to 26 fixed-format planar Gray, YUV, or planar RGB input
clips. The output always uses the first input clip’s format, resolution, timing,
and metadata. expr does not convert the output format. Use
convert_format or convert_bit_depth before or after expr when you need a
different output format.
Input sample values are not normalized. Integer clips use their stored code
values such as 0..255 for 8-bit and 0..1023 for 10-bit. Float clips use the
stored f32 values. Mixed input formats are allowed when plane geometry and
timing match, so expressions must account for each input clip’s sample range.
If expr contains fewer expressions than the output has planes, the last
expression is reused for the remaining planes. If it contains more expressions
than the output has planes, planning fails. An empty expression copies that
plane from the first input clip.
Examples
output = source("input.mkv").std.expr(#{ expr: "x 2 *" })
a = source("a.mkv")
b = source("b.mkv")
output = std.expr([a, b], #{ expr: ["x y + 2 /", "", ""] })
output = source("input.mkv").std.expr(#{
expr: ["x 128 > 255 0 ?", "", ""],
})
Input
One to 26 fixed-format planar Gray, YUV, or planar RGB clips with matching plane geometry and timing.
Output
A clip with the same format, resolution, timing, and metadata as the first input clip, with selected planes generated by expression evaluation.
Options
expr(String | Array<String>) – Reverse-polish expression or per-plane expressions. Empty per-plane expressions copy from the first input clip. Arrays may not be longer than the output plane count.
Variables
x,y,z– Inputs 0, 1, and 2.athroughw– Inputs 3 through 25.
Operators
- Unary:
exp,log,sqrt,sin,cos,abs,not,dup,dupN. - Binary:
+,-,*,/,max,min,pow,>,<,=,>=,<=,and,or,xor,swap,swapN. - Ternary:
?, usingcondition true_value false_value ?stack order.
Logical operators treat values greater than 0 as true and return 1.0 for
true or 0.0 for false. Integer outputs are rounded and clamped to the output
format’s valid code range. Float outputs are stored without clamping. If an
expression produces a non-finite result, rendering fails.