49

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?

Andrew Simpson
  • 6,145
  • 9
  • 59
  • 153

4 Answers4

86

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

Killer
  • 3,574
  • 6
  • 35
  • 51
Andri Kurnia
  • 1,058
  • 9
  • 11
  • Hi, beat you to it. It was what I just found. But, as you got the right answer and you gave me your time I give you a tick :) – Andrew Simpson Mar 02 '15 at 11:03
  • 13
    The scale filter can also automatically calculate a dimension while preserving the aspect ratio: `scale=320:-1`, or `scale=-1:240`. – llogan Mar 02 '15 at 18:13
  • This results in a corrupt image for me. Just a bunch of lines and colors. jpg to jpg – Tyguy7 Nov 09 '15 at 18:26
  • 2
    Interesting, png output works fine though. JPG is borked. – Tyguy7 Nov 09 '15 at 18:27
  • What if I want to keep the output file name unchanged? Can I have a shorter command? Thank you. – Alston Mar 01 '19 at 03:22
17

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
VxJasonxV
  • 934
  • 10
  • 29
Aniket Thakur
  • 58,991
  • 35
  • 252
  • 267
2

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.

Boris Yakubchik
  • 2,387
  • 1
  • 24
  • 30
1

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.

LF00
  • 22,077
  • 20
  • 117
  • 225