How to change the aspect ratio of a video?

I have some videos recorded in 16:9 aspect ratio, but I want to convert them to 1:1 for social media. Is there a way to change the aspect ratio of the video with ImageKit?

ImageKit provides URL-based resizing parameters for videos, whether they are uploaded to the ImageKit Media Library or stored on an External Storage connected to ImageKit.

These transformation parameters allow you to easily adjust your videos to any desired aspect ratio, ensuring smooth delivery across various platforms and screen sizes.

Methods to Change Video Aspect Ratio in ImageKit

ImageKit provides multiple transformation parameters and cropping options to achieve aspect ratio adjustments directly via the video URL:

Using both Width and Height parameter

You can specify the exact width (w) and height (h) to resize the video. To convert a 16:9 video to 1:1, simply set equal values for both.

Example:

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

Read more on how to use this transformation on your Videos here.

Using Aspect Ratio along with either Height or Width parameter

You can explicitly define an aspect ratio (ar ) along with either width (w ) or height (h ) to automatically calculate the other dimension.

Example:

https://ik.imagekit.io/demo/sample-video.mp4?tr=w-720,ar-1-1

This URL sets the width to 720px and applies a 1:1 aspect ratio, resulting in a height of 720px automatically.

Read more on how to use this transformation on your Videos here.

Note: If you use either method—setting exact width and height, or combining width or height with aspect ratio—your video might get cropped to fit those new dimensions.

Using crop Mode to make sure the videos are not cropped while resizing

Pad resize crop strategy

The pad_resize strategy resize your video in the asked aspect ratio without cropping by adding padding to match the requested dimensions if needed.

Example:

https://ik.imagekit.io/demo/sample-video.mp4?tr=w-720,h-720,cm-pad_resize

This ensures the output is exactly 720x720, with padding filling any extra space needed to preserve the aspect ratio.

You can control the position of the padding using the focus fo parameter. Additionally, you can customize the padding area by applying a background color or using a blurred background effect with the background bg transformation.

Forced crop strategy

The c-force strategy resizes your video by forcibly stretching or squashing it to fit exactly within the specified output dimensions.

Example:

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