A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloudinary.com/documentation/video_conditional_expressions below:

Transform Videos with Conditional Expressions

Cloudinary supports conditional transformations for videos, where a transformation is only applied if a specified condition is met, for example, if a video's width is greater than 300 pixels, apply a certain transformation.

See also: Conditional transformations for images.

Specifying conditions

To specify a condition to be met before applying a transformation, use the if parameter (also if in URLs). The if parameter accepts a string value detailing the condition to evaluate, and is specified in the URL in the following format:

if_<video characteristic>_<operator>_<video characteristic value>

Where:

See examples below.

Supported video characteristics Characteristic Description w (also width in SDKs) The asset's current width. iw The asset's initial width. h (also height in SDKs) The asset's current height. ih The asset's initial height. ar (also aspect_ratio in SDKs) The aspect ratio of the asset. The compared value can be either decimal (e.g., 1.5) or a ratio (e.g., 3:4). iar The asset's initial aspect ratio. ctx A contextual metadata value assigned to an asset. md A structured metadata value assigned to an asset. tags The set of tags assigned to the asset. du (also duration in SDKs) The current duration of the video. idu The video's initial duration. Supported operators URL SDK symbol Description eq = Equal to ne != Not equal to lt < Less than gt > Greater than lte <= Less than or equal to gte >= Greater than or equal to in|nin in|nin Included in | Not included in

Compares a set of strings against another set of strings. See Using the in and nin operators for examples.

When working with the Cloudinary SDKs, you can specify the condition using the SDK characteristic names and operator symbols, or you can specify it using the URL format. For example, both of the following are valid:

Using the in and nin operators

The in and nin operators compare two sets of strings. The : delimiter between strings denotes AND. String sets can include tags, contextual metadata or structured metadata values, for example:

Supported conditional video transformation parameters and flags Notes Specifying transformations for a condition

The transformation for a condition should be specified between the condition component and an if_end component in the format:

if_condition/transformation/if_end

For example:

if_ar_lt_1.0/b_darkorange,c_pad,h_300,w_500/if_end

In the following examples, both videos are scaled to a width of 500px. Afterwards, the identical conditional padded-resize transformation shown above is applied to both videos. However, since the condition applies only for portrait videos (those with an aspect ratio less than 1.0) the resizing and padding is applied only to the parrot video below:

Transformation URLs technically support defining both the condition and a single resulting transformation inside a single transformation component (without the need for a closing end_if). However, to avoid ambiguity, the best practice is to always use if and if_end components in your URL as shown above.

Conditions with chained transformations

You can apply multiple chained transformations to your condition by including the entire chained transformation in between the if and if_end components.

The example below checks whether the video asset's tags include a 'cloudinary' tag. Only in that case, a chained transformation including an image overlay (Cloudinary logo) and a text overlay ('By Cloudinary') are applied. If 'cloudinary' is not one of the tags, no image or text overlay is applied.

Note that this example also includes a scale-down transformation before the beginning of the conditional transformation and a duration trim after the end of the conditional transformation. Those transformations are applied regardless of the true or false result of the condition.

Multiple AND | OR conditions

You can specify multiple conditions to evaluate by joining the conditions with 'AND' or 'OR' conjunction operators.

'AND' operators are evaluated before 'OR' operators.

The example below checks whether the video's aspect ratio is larger than a standard mobile portrait orientation AND if it has a large width. Only in this case, it crops the video to a portrait orientation with a width of 500. If the video already has a portrait orientation (condition 1 is false) or if the original width is less than 500 (condition 2 is false), the conditional transformation is ignored and the video is delivered in its original shape and size.

It's also possible to define multiple separate conditions, each with its own transformation result by using multiple

if...end_if

chained components in the URL.

Else branch transformations

You can specify a transformation that is applied in the case that the initial condition is evaluated as false (and hence the transformations associated with the condition are not applied), by using the if_else parameter to specify this fallback transformation.

For example, the following conditional transformation checks whether a video's aspect ratio is close to the desired aspect ratio, if it is close, then when the video is resized, any necessary padding is black. But if the aspect ratio is much smaller (for example, if it is a square or portrait video), then a blurred video padding is added.

In cases where the if condition is not in the preceding transformation component, then the if_else parameter also acts as an if_end parameter: all chained transformation components until the one with if_else are only applied if the previous condition holds true. Multiple conditional transformations can also be applied by adding an if_end parameter to the last transformation component in the chain, and to avoid ambiguity, the component with the if_else parameter should not have additional transformation instructions.

For example, if the video is shorter than or equal to 10 seconds, fade in for one second and fade out for one second, else if the video is longer than 10 seconds, fade in for two seconds and fade out for two seconds:

Conditional transformation examples

When you use variable or conditional expressions that include the

tags

,

ctx

or

md

parameters, their values are exposed publicly in the URL. If you want to prevent such values from being exposed, you can disable the

Usage of tags/context/metadata in transformation URLs

option in the

Security

Settings (enabled by default). When this setting is disabled, any URL that exposes tags, contextual metadata or structured metadata values will return an error.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4