Use ffmpeg to resize image

Image ProcessingFfmpeg

Image Processing Problem Overview


Is it possible to resize an image using FFMPEG?

I have this so far:

ffmpeg. -i 1.jpg -vf scale=360:240 > 2.jpg

I get the error message that 'At least one output file must be specified'

Is it possible?

Image Processing Solutions


Solution 1 - Image Processing

You can try this:

ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png

I got this from source

Note: The scale filter can also automatically calculate a dimension while preserving the aspect ratio: scale=320:-1, or scale=-1:240

Solution 2 - Image Processing

If you want to retain aspect ratio you can do -

./ffmpeg -i 1.jpg -vf scale="360:-1" 2.jpg

or if you want to resize based on input width and height, let's say half of input width and height you can do -

./ffmpeg -i 1.jpg -vf scale="iw/1:ih/2" 2.jpg

where

iw: input width
ih: input height

Solution 3 - Image Processing

It is also possible to resize an image to fit inside some dimensions and letterbox the rest.

Example command:

ffmpeg -i IN.png -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" OUT.jpg

See this answer for more details.

Solution 4 - Image Processing

Thanks to @andri-kurnia 's answer.

This example also shows how to resize multiple images (in windows):

for %j in (*.jpg) do ffmpeg -i "%j" -vf scale=480:-1 "Small-%~nj.jpg"

This command will resize all .jpg images in the folder, sets the width 480 while keeping ratio, and add "Small-" at the start of the resized image name. And I think for some types, it may be necessary to use -2 instead of -1. For specifying the height, we can use something like -1:480.

Solution 5 - Image Processing

To reduce image scale to the bounding box of width:320px and height:240px.

ffmpeg -i src_image_path -vf 'scale=if(gte(a\,320/240)\,min(320\,iw)\,-2):if(gte(a\,320/240)\,-2\,min(240\,ih))' dst_image_path

a: aspect ratio
iw: in width
ih: in height

If the src image size is in the bounding box do no resize on it. If image has a big aspect ration than 320/240 and width is bigger then 320, resize width to 320 and keep the aspect ration. If image has a small aspect ration than 320/240 and height is bigger then 240, resize height to 240 and keep the aspect ration.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrew SimpsonView Question on Stackoverflow
Solution 1 - Image ProcessingAndri KurniaView Answer on Stackoverflow
Solution 2 - Image ProcessingAniket ThakurView Answer on Stackoverflow
Solution 3 - Image ProcessingBoris YakubchikView Answer on Stackoverflow
Solution 4 - Image ProcessingMisaghView Answer on Stackoverflow
Solution 5 - Image ProcessingLF00View Answer on Stackoverflow