API Reference v2

Math expressions

Math expressions bring very dynamic functionality to your jobs.

Usage

Math expressions, unlike variables, must be surrounded by {% expression %}

Like "if" key for conditional outputs, all variables can be used inside math expressions.

"outputs": {
  "mp4": [
    {
      "key": "mp4-half",
      "format": {
        "resolution": "{% input.width / 2 %}x",
        "video_bitrate": "{% int(input.video_bitrate / 2) %}k"
      },
      "path": "/half.mp4"
    }
  ]
}

Math Operators

+ - / * are supported.

Functions

FunctionDescriptionExample
min(int, int, int, ...)Return the lowest number{% min(input.video_bitrate, 1200) %}
max(int, int, int, ...)Return the biggest number{% max(input.fps, 30) %}
int(val)Return the value as integer{% int(input.video_bitrate / 2) %}
float(val)Return the value as float{% float(input.duration / 6) %}
array(val1, val2, val3)Return an array with the given values{% array(0, input.duration / 3, input.duration-1) %}
if(condition, val1, val2)Evaluate the given condition and return the value weither it's true or false{% if(input.video_bitrate > 2000, 2000, input.video_bitrate) %}

More examples

Limit the video bitrate to not be higher than original.

"mp4": {
  "path": "/video.mp4",
  "format": {
    "video_bitrate": "{% max(input.video_bitrate, 2500) %}k"
  }   
}

Crop the video to make a zoom effect.

"mp4:1080p": {
  "path": "/crop.mp4",
  "crop": "{% input.width / 2 %}:{% input.height / 2 %}"
}

Give offsets in second dynamically.

"jpg:320x"": {
  "path": "thumbnails%.2d.jpg",
  "offsets": "{% array(1, input.duration / 3, input.duration / 2, input.duration-1) %}"
}