It’s no secret that video content has become increasingly popular and pervasive and an essential tool for organisations. Naturally, cropping and resizing are two important editing skills needed to transform and optimise videos to fit aspect ratios required by different social media channels.
FFmpeg, a powerful and versatile multimedia framework, provides a wide range of functionalities, including video cropping and resizing. In this article, we will explore how to utilise FFmpeg to crop and resize videos and compare it with Shotstack, a cloud-based video editing API, to achieve your desired output.
Before we dive into the process, ensure that you have FFmpeg installed on your computer. FFmpeg is a command-line tool available for Windows, macOS, and Linux operating systems. You can download the latest version from the official FFmpeg website and follow the installation instructions provided.
To follow along this tutorial, download the video example we’re using and save it on your computer. The video is a vertical video with dimensions 1920px height x 1080px width:
Cropping a video allows you to remove unwanted portions from the frame, drawing viewers’ eyes to a specific subject or adjusting the aspect ratio. A good example of when cropping videos is important is when you’re repurposing and adjusting content based on social media channels’ video specs. A YouTube video of a car showcase is too wide to share on Instagram Reels or TikTok so you would want to crop to focus on certain parts of the car instead.
To do this, FFmpeg provides a straightforward method to crop videos using the following syntax:
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4
input.mp4
with the filename or path to your input video.output.mp4
with the desired filename or path for the output video.w
, h
, x
, and y
according to your requirements.w
: Width of the cropped region in pixels.h
: Height of the cropped region in pixels.x
: Horizontal position of the top-left corner of the cropped region relative to the original video's top-left corner. Use a positive value to move right and a negative value to move left.y
: Vertical position of the top-left corner of the cropped region relative to the original video's top-left corner. Use a positive value to move down and a negative value to move up.For example, our original video example has a height of 1920px and a width of 1080px and we want to crop it to a 1080px x 1080px video for Instagram.
We also want to crop it from the centre and we do this by calculating the x axis with this formula: original height - target height / 2. In our example, it’s 1920 - 1080 / 2 = 420
To crop our video example, you would use the following command:
ffmpeg -i car-overead-vertical.mp4 -filter:v "crop=1080:1080:420:0" cropped.mp4
The output video looks like this:
Resizing videos allows you to adjust their dimensions, whether to fit within specific display resolutions, reduce file size, or change aspect ratios. Unlike cropping, which focuses on removing portions of the frame, resizing adjusts the overall size of the video while preserving the entirety of the content within the frame.
FFmpeg simplifies this process by offering different resizing options.
To resize a video by specifying the desired width and height, use the following command:
ffmpeg -i input.mp4 -vf "scale=w:h" output.mp4
w
and h
with the desired width and height, respectively.output.mp4
with the desired filename or path for the output video.For instance, to resize our cropped video example to 720x720 pixels, you would use the following command:
ffmpeg -i cropped.mp4 -vf "scale=720:720" resized.mp4
And here is the output video:
In some cases, you may want to resize a video while maintaining its original aspect ratio, adjusting only one dimension, either width or height. To achieve this, you can use the following commands:
To resize by width, preserving the aspect ratio:
ffmpeg -i input.mp4 -vf "scale=w:-1" output.mp4
To resize by height, preserving the aspect ratio:
ffmpeg -i input.mp4 -vf "scale=-1:h" output.mp4
Replace w
or h
with the desired width or height, respectively.
If you prefer to resize a video by a certain percentage, you can use the following command:
ffmpeg -i input.mp4 -vf "scale=iw*percentage/100:ih*percentage/100" output.mp4
Replace percentage
with the desired percentage value. For example, to resize a video to 50% of its original dimensions, use:
ffmpeg -i input.mp4 -vf "scale=iw*0.5:ih*0.5" output.mp4
There are cases when you would need to crop a video and select an area the shows your main subject and reduce the video’s width and length. This way, you can transform the video to fit a social media channel’s aspect ratio while keeping the most important parts and quality of your video.
Sure, you can do the two commands above but it takes longer and each time you encode, the video loses quality. A better approach is combining both the crop and scale filers in a single command.
To crop and resize at the same time:
ffmpeg -i input.mp4 -vf “crop=""crop=w:h:x:y,scale=w:h" output.mp4
In our video example, you would use the following command:
ffmpeg -i car-overead-vertical.mp4 -vf "crop=1080:1080:420:0,scale=720:720" resized-and-cropped.mp4
Here is the final cropped and resized video:
While FFMpeg is an effective tool, it takes a certain level of command-line knowledge and skills to use. Shotstack is an easier, more intuitive and user-friendly tool to edit your videos.
Shotstack’s key advantages include:
There are two ways to crop and resize videos on Shotstack. We recommend using the Video Editing API if you want to perform other tasks, such as adding texts or transitions, stitching multiple videos and more. But if you simply want to resize or crop your video, we suggest using the Ingest API.
Follow our comprehensive guide to resizing and cropping videos using both APIs to find out how easy it is to use Shotstack. You can also check our easy-to-understand Edit API and Ingest API documentation to discover other flexible and robust functionalities that help you create stunning and unique videos at scale.
Keen to get started? Sign up for your free account with Shotstack today– no credit card required!
Every month we share articles like this one to keep you up to speed with automated video editing.
Learn to crop or resize videos using the Shotstack's Edit and Ingest API's
How to use the Shotstack API to merge video clips together to edit a simple video.
Learn how to trim the start, end or middle of a video using the Shotstack API.