Getting started

Integration & migration

Image & video API

DAM user guide

API overview

Account

Resize and Crop Videos

Learn how to resize and crop videos using the ImageKit.io URL-based transformation parameters.


Width - (w)

Used to specify the width of the output video. Accepts integer value greater than 1.

You can also provide an arithmetic expression such as iw_div_2, cw_mul_0.8, or ih as a value for this parameter. Doing so will first calculate the value of the expression and then apply transformations using that value. Learn more about arithmetic expressions here.

When you specify just width, the height is adjusted accordingly to maintain the aspect ratio.

Height - (h)

Used to specify the height of the output video. Accepts integer value greater than 1.

You can also provide an arithmetic expression such as ih_div_2, ch_mul_0.5, or ih as a value for this parameter. Doing so will first calculate the value of the expression and then apply transformations using that value. Learn more about arithmetic expressions here.

When you specify only height, the width is adjusted accordingly to maintain the aspect ratio.

Aspect ratio - (ar)

Used to specify the aspect ratio of the output video. It is the ratio of width to height of the output video. This parameter must be used along with either the height(h) or width(w) parameter but not both.

You can also provide an arithmetic expression such as iar_div_2, or car_mul_0.75 as a value for this parameter. Doing so will first calculate the value of the expression and then apply transformations using that value. Learn more about arithmetic expressions here.

Usage = ar-<width>_<height>

If you specify both height(h) and width(w) in the URL along with aspect ratio(ar), then the aspect ratio is ignored.

Crop, Crop Modes, and Focus

If only, one of the height(h) or width(w) is specified, then ImageKit.io adjusts the other dimension accordingly to preserve aspect ratio and no cropping takes place.

But when you specify both height(h) and width(w) dimensions, you need to choose the right cropping strategy based on your website layout and desired output video.

Tip for choosing the right cropping strategy

When choosing among different strategies for cropping, think in terms of your website layout and desired output video dimension.

  • If you want to preserve the whole video content without any cropping and need the exact same dimensions (height and width) in the output as requested, choose either the pad resize crop or forced crop strategy.
  • If you want to preserve the whole video content without any cropping, but it is okay if one or both the dimensions (height or width) in the output are adjusted to preserve the aspect ratio. Then choose either the max-size cropping or min-size cropping strategy.
  • If you need the exact same dimensions (height and width) in the output video as requested but it's okay to crop the video to preserve the aspect ratio. Then choose either the maintain ratio crop or the extract crop strategy. You can combine the extract crop strategy with different focus values to get the desired result.

Pad resize crop strategy - (cm-pad_resize)

In the pad resize crop strategy, the output dimension (height and width) is the same as requested, no cropping takes place, and the aspect ratio is preserved. This is accomplished by adding padding around the video to get it to match the exact dimension as requested.

Example - All padding on one side

In the examples above, we saw that when the video is padded using the pad resize crop strategy, the padding is equal on both sides of the video. However, there might be cases where we want all the padding to be added on only one side of the video. This can be done using the focus (fo) parameter.

https://ik.imagekit.io/demo/sample-video.mp4?tr=w-400,h-200

The video is 400x200 but it is cropped from all sides to preserve the aspect ratio.

Default crop 400x200

Forced crop strategy - (c-force)

In a forced crop strategy, the output video's dimension (height and width) is exactly the same as requested, no cropping takes place, but the aspect ratio is not preserved. It forcefully squeezes the original video to get it to fit completely within the output dimensions.

URL - https://ik.imagekit.io/demo/sample-video.mp4?tr=w-200,h-200,c-force

Notice that the aspect ratio is changed and the video looks squeezed.

Forced crop 200x200

Max-size cropping strategy - (c-at_max)

In the max-size crop strategy, the whole video content is preserved without any cropping, and the aspect ratio is preserved, but one of the dimensions (height or width) is adjusted.

The output video is less than or equal to the dimensions specified in the URL,i.e., at least one dimension will exactly match the output dimension requested, and the other dimension will be equal to or smaller than the corresponding output dimension requested.

URL - https://ik.imagekit.io/demo/sample-video.mp4?tr=w-200,h-200,c-at_max

Notice that the aspect ratio is maintained, and there is no cropping. However, the height is reduced so that the video fits within a 200x200 container.

Max-size crop 200x200

Min-size cropping strategy - (c-at_least)

This strategy is similar to the max-size cropping strategy, with the only difference being that, unlike the max-size strategy, the output video dimension is equal to or larger than the requested dimensions. One of the dimensions will be exactly the same as what is requested, while the other dimension will be equal to or larger than what is requested.

URL - https://ik.imagekit.io/demo/sample-video.mp4?tr=w-200,h-200,c-at_least

Notice that the height is 200px as requested, but the width is more than 200px. The aspect ratio is maintained and there is no cropping.

Min-size crop 200x200

Maintain ratio crop strategy - (c-maintain_ratio)

This is the default crop strategy. If no crop (c) or crop_mode (cm) is specified in the URL, c-maintain_ratio gets applied automatically.

In this strategy, the output video's dimensions (height and width) are the same as requested, and the aspect ratio is preserved. This is accomplished by resizing the video to the requested dimension and then cropping extra parts to get the desired height & width.

By default, ImageKit.io crops the video from the center, but you can change this using the focus parameter.

Extract crop strategy - (cm-extract)

In this strategy, the output video's dimension (height and width) is exactly the same as requested, and the aspect ratio is preserved. In this strategy, instead of trying to resize the video as we did in maintain ratio strategy, we extract out a region of the requested dimension from the original video.

By default, ImageKit.io extracts the video from the center but you can change this using the focus parameter.

Examples - Center and relative focus

URL - https://ik.imagekit.io/demo/sample-video.mp4?tr=h-300,w-300,cm-extract

A 300x300 part is extracted from the center of the original video.

Default center extract 300x300

Focus - (fo)

This parameter can be used along with pad resize, maintain ratio or extract crop to change the behavior of padding or cropping. Learn more from the different examples shown in respective sections.

This parameter can have the following values depending upon where it is being used:

  1. left, right, top, bottom can be to control the position of padding when used with pad resize. Learn from examples.
  2. center, top, left, bottom, right, top_left, top_right, bottom_left and bottom_right can be used to define relative cropping during extract crop. Learn from examples.

Beyond static positioning, the fo parameter also supports AI-powered smart cropping that can automatically detect and track subjects throughout your video. This includes automatic smart crop (fo-auto) for general content, face detection and tracking (fo-face), and object-aware cropping (fo-<object>) that can focus on specific objects like people, cars, or animals from our supported object list.

Automatic smart crop - (fo-auto)

Automatically detects and tracks the most important objects in your video, ensuring they remain centered as the video progresses. This feature is ideal for creating engaging social media content from longer videos. When using fo-auto, you must specify both dimensions—either provide both height and width, or specify one dimension along with the ar (aspect ratio) parameter. The unspecified dimension will be calculated automatically to maintain the aspect ratio.

Face crop - (fo-face)

Detects and follows faces in your video, automatically keeping them centered and in focus. When multiple faces are present, it focuses on the most prominent one.

Object-aware cropping - (fo-object name)

Focus on specific objects in your video by specifying any object from the supported list. The AI will track and keep the specified object in focus throughout the video.

Auto-sizing with smart crop: When using face crop (fo-face) or object-aware cropping (fo-<object>), you can omit width and height parameters to let the AI automatically determine the optimal crop size. Use the ar parameter to specify your preferred aspect ratio, and the AI will adjust the crop area to match while keeping the subject in focus.

Limitations and considerations for video smart crop

Crop mode compatibility: Video smart crop only works with c-maintain_ratio (default) and cm-extract crop modes. All other crop modes (defined with c or cm) are invalid.

  1. Video smart crop is available when base asset is video and inside video overlays (l-video). However, video smart crop is not available when input video codec is MPEG-1 Video or MPEG-2 Video.
  2. Video smart crop is not available when input of video layer (l-video) is a GIF file.
  3. Video smart crop is not available for image overlays (l-image) in video transformations.
  4. Smart crop can only be performed on a video once, and it must be the first step of the chained transformations.
    tr=b-10_red:fo-person - ❌
    tr=fo-person:b-10_red - ✅
    If you use smart crop inside a video layer (l-video), it must also be the first step within that layer’s chained transformations.
  5. You cannot use rotate (rt) in the same step as smart crop.
    tr=fo-person,rt-90 - ❌
    If you want to rotate a video after applying smart crop, use chained transformation (separate the parameters with a :).
    tr=fo-person:rt-90 - ✅ will first crop around the person in the video, and then rotate the result by 90 degrees.
  6. Arithmetic expressions are completely unsupported anywhere in the transformation when video smart crop is used.

Video smart crop pricing

Video smart crop incurs additional charges beyond the standard video encoding costs. The smart crop fee is calculated based on two factors:

  1. Duration of the final video output (in seconds).
  2. Number of smart crop operations used in the transformation.

The formula for calculating the smart crop cost is:

Copy
Smart crop cost = Final video duration (in seconds) × Number of `fo` parameters used × VPU rate for SD video