Skip to main content

VapourSynth expr plugin built on top of Cranelift.

Project description

cranexpr

cranexpr is like std.Expr but built on top of Cranelift. It's a VapourSynth plugin that allows one to evaluate an expression per pixel.

Examples

Median of 3 clips:

core.cranexpr.Expr([x, y, z], "x y min x y max z min max")

Flip a clip horizontally:

core.cranexpr.Expr([x], "width X - 1 - Y x[]")

3x3 box blur:

core.cranexpr.Expr([x], "x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + + 9 /")

Features

  • Arithmetic: +, -, *, /, %, pow, exp, log, sqrt.
  • Trigonometry: sin, cos, tan, atan2.
  • Comparison: >, <, =, >=, <=.
  • Logical: and, or, xor, not.
  • Bitwise: bitand, bitor, bitxor, bitnot.
  • Clamping: min, max, clip (alias: clamp).
  • Rounding: floor, round, trunc.
  • Ternary (if/else): ?.
  • sgn: Returns the sign of a value (-1 if negative, 1 if positive, 0 if zero).
  • Constants:
    • width: Width of the plane.
    • height: Height of the plane.
    • N: Current frame number.
    • pi: π.
  • Stack manipulation:
    • dropN, drop: drops the top N values from the stack. drop is equivalent to drop1.
    • dupN, dup: allows a value N steps up in the stack to be duplicated. The top value of the stack has index 0 meaning that dup is equivalent to dup0.
    • swapN, swap: allows a value N steps up in the stack to be swapped. The top value of the stack has index 0 meaning that swap is equivalent to swap1. This is because swapN always swaps with the topmost value at index 0.
  • Variables:
    • var!: Pops the top value from the stack and stores it in a variable named var.
    • var@: Pushes the value of the variable var onto the stack.
  • Frame property access: clip.PropertyName.
    • Accesses a numeric frame property from the given clip.
    • If the property is missing, its value will be NaN.
    • If the property is not a numeric frame property, its value will be the first byte.
  • Relative pixel access: clip[relX, relY]:[mode].
    • Accesses a pixel relative to the current coordinate (X, Y). relX and relY must be integer constants.
    • If no suffix is provided, the edge behavior is determined by the filter's boundary parameter.
      • :c: Forces clamped boundary.
      • :m: Forces mirrored boundary.
  • Absolute pixel access: absX absY clip[]:[mode].
    • Accesses a pixel at an absolute coordinate. It pops absY then absX from the stack. These coordinates can be computed by expressions.
    • If the coordinates are not integers, they will be rounded half to even.
    • Example: X 2 / Y x[] reads the pixel at half the current X coordinate from the first clip, using the default clamp mode.
    • Boundary Suffixes:
      • :c: Forces clamped boundary.
      • :m: Forces mirrored boundary.
  • Supports any number of input clips. srcN may be used to access the N-th input clip. Shorthand aliases x, y, z, a, b, c, etc. map to src0, src1, src2, src3, src4, src5, etc., up to w being src25. Beyond that, use srcN.

Install

pip install vapoursynth-cranexpr

API

cranexpr.Expr(
  clips: vs.VideoNode | Sequence[vs.VideoNode],
  expr: str | list[str],
  format: int | None = None,
  boundary: Literal[0, 1] = 0,
) -> vs.VideoNode
  • clips — Input video nodes.
  • expr — Reverse Polish Notation (RPN) expression(s) for each plane. The expression given for the previous plane is used if the list contains fewer expressions than the input clip has planes. This means that a single expression will be applied to all planes by default.
  • format — By default the output format is the same as the first input clip's format. This can be overridden by setting this parameter.
  • boundary — Boundary mode. 0 for clamping, 1 for mirroring.
cranexpr.PropExpr(
  clips: vs.VideoNode | Sequence[vs.VideoNode],
  **kwargs: str,
) -> vs.VideoNode
  • clips — Input video nodes. The first clip's format is used for the output.
  • **kwargs — Each keyword argument maps a frame property name to a RPN expression. The expression is evaluated once per frame and the result is written back as a frame property on the output.

PropExpr evaluates expressions that produce scalar values and stores them as frame properties on the output frame. All expressions are evaluated before any properties are written.

If the computed value is an exact integer, then it is stored as an integer frame property. Otherwise it is stored as a float.

PropExpr supports all operators supported by Expr except those that access pixel values (x/y/srcN as pixel values, relative pixel access like x[-1,0], absolute pixel access like x[], and the per-pixel coordinate variables X and Y).

cranexpr.Select(
  clip_src: vs.VideoNode | Sequence[vs.VideoNode],
  prop_src: vs.VideoNode | Sequence[vs.VideoNode],
  expr: str | list[str],
) -> vs.VideoNode
  • clip_src — Candidate clips. All must have the same format and dimensions.
  • prop_src — Clips whose frame properties the expression may read.
  • expr — Reverse Polish Notation (RPN) expression(s) for each plane. The expression given for the previous plane is used if the list contains fewer expressions than the input clip has planes. This means that a single expression will be applied to all planes by default.

Select evaluates a RPN expression once per frame (per plane) and uses the result as an index to pick a clip from clip_src to satisfy the current frame request. It is designed to replace many uses of std.FrameEval where you want to compute a metric from frame properties and then choose one of several clips to use.

For each output frame and each plane, the filter evaluates the plane's expression, rounds the result to the nearest integer, clamps it to the range [0, len(clip_src) - 1], then takes that plane from clip_src[index]'s frame n.

Select supports all operators supported by Expr except those that access pixel values (x/y/srcN as pixel values, relative pixel access like x[-1,0], absolute pixel access like x[], and the per-pixel coordinate variables X and Y).

Unlike Expr, where a non-existent frame property evaluates to NaN, Select uses 0.0 instead.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vapoursynth_cranexpr-0.11.0.tar.gz (99.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vapoursynth_cranexpr-0.11.0-py3-none-win_amd64.whl (4.9 MB view details)

Uploaded Python 3Windows x86-64

vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_x86_64.whl (3.3 MB view details)

Uploaded Python 3macOS 13.0+ x86-64

vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_arm64.whl (1.1 MB view details)

Uploaded Python 3macOS 13.0+ ARM64

File details

Details for the file vapoursynth_cranexpr-0.11.0.tar.gz.

File metadata

  • Download URL: vapoursynth_cranexpr-0.11.0.tar.gz
  • Upload date:
  • Size: 99.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for vapoursynth_cranexpr-0.11.0.tar.gz
Algorithm Hash digest
SHA256 0465ab0d94c88cb21783cb75db2f15cb0f1938492532afee7c57b5ebff2ad6fc
MD5 7983b13dd55bb5854eec369f84eb011e
BLAKE2b-256 687e37a5858c99a49fa534599c5fd25f177ebb0267d17a30f56b12532c1bb4d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0.tar.gz:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_cranexpr-0.11.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_cranexpr-0.11.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 b3ad164c297a090a786862ebb7b0891c8d0e40d3119b481a218003cc222fafda
MD5 c954db8824fc03042cc1f7f320b75b0c
BLAKE2b-256 bfae0a45329a1184607d921e5dffe7aae1cb1bd602ec43f9de2b7da39ea25c3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0-py3-none-win_amd64.whl:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8003f3e4c1e0487095e5dea7c7e4d65a857c1069f4d33085aa9a75ad21ca5210
MD5 b5513b0d32ffd5e7c5eb11aa50446cdc
BLAKE2b-256 0f6aeffb08321dae8aa1ab270ef52d0aa32fc236f3507cbf41fe86e55079540b

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d44dc01668be844be228de47130bc5714164229b80f7e14477a24f8de2e06298
MD5 4309370c13028779d6349e473e918542
BLAKE2b-256 292420ee6796c2e3f24051b7f513716a574648acf7f849c188428db65a06c2d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 89b1ceb91c7a8d556d31c8f9f7025f479605b375a6941ba7dee03a3774728d49
MD5 0d931c0081536257711d75515bc16242
BLAKE2b-256 cf14ef67043b11e3f9bdd8c6f8f3c5e148d9fd7b9e29344c43b1494881311184

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_x86_64.whl:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 daa937d2ea0d72430d22fba5e8137868af9ed18157b2eecd87b21bcd79ce936f
MD5 0370fcf495493f126b07e8450d6c6d7e
BLAKE2b-256 a5bf62d63dd3f53141ce6f401858b6596d9cf96fdda43b9540bd9a66307c66b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_cranexpr-0.11.0-py3-none-macosx_13_0_arm64.whl:

Publisher: publish.yml on sgt0/cranexpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page