How to resize your video at the command line with ffmpeg

Card Puncher Data Processing

About

In this how-to, we show you how to resize video with the ffmpeg command line utility and the scale filter 1)

How to

How to scale down preserving the aspect ratio

ffmpeg permits to set the dimension of a video to -1 in order to preserve aspect ratio

Once, you have installed ffmpeg, you can resize:

  • a mp4 video
  • while preserving the aspect ratio (most wanted)
  • to a width of 960
ffmpeg -i output.mp4 -vf "scale=960:-1" output_960.mp4
  • to a height of 300
ffmpeg -i output.mp4 -vf "scale=-1:300" output_300.mp4
Image

Note that you can also resize an image

ffmpeg -i input.jpg -vf scale=320:-2 output_320.png
height not divisible by 2

You may encounter this error height not divisible by 2.

If you encounter the above error, you may want to use the following expression 2)

scale=640:trunc(ow/a/2)*2

where ow is the width of the output. </note>

How to scale down a video by 50% preserving the aspect ratio

On the width:

ffmpeg -i input.mp4 -vf "scale=trunc(iw/4)*2:-1" output_down_2.mp4

On the height

ffmpeg -i input.mp4 -vf "scale=iw:ih/2:0:0" output_down_2.mp4

Where iw and ih means the width and height of the input video.

How to scale down or up to fill into a rectangle ?

You can achieve this with the force_original_aspect_ratio option. It has two possible values:

  • decrease: The output video dimensions will automatically be decreased if needed.
  • increase: The output video dimensions will automatically be increased if needed.

Example 3)

ffmpeg -i input.jpg -vf scale=w=320:h=240:force_original_aspect_ratio=decrease output_320.png





Discover More
Card Puncher Data Processing
How to reduce the size of a video dramatically with ffmpeg ?

This article shows you how to reduce the size of video with ffmpeg. The following parameters have an important on the size: * the codec: the codec is the algorithm that encodes the picture into the...
Card Puncher Data Processing
How to resize images in a directory with ffmpeg ?

This article shows you how to scale image in a dirctory with ffmpeg and conserve the aspect ratio. Because ffmpeg is a video management tool, it can also modify a frame, in other word, an image. ...
Card Puncher Data Processing
How to use ffmpeg in a web page ?

Thanks to the wasm format , it's possible to integrate ffmpeg in a web page. * * With where you can compress & resize videos in...
Card Puncher Data Processing
What is ffmpeg ?

What is ffmpeg ? ffmpeg is a command line to record, convert and stream audio and video. This is the simple tool to manipulate and convert any video. * * * * * * FFmpeg...



Share this page:
Follow us:
Task Runner