Use ffmpeg to resize image

后端 未结 4 1999
挽巷
挽巷 2021-01-30 21:17

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 messa

相关标签:
4条回答
  • 2021-01-30 21:19

    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.

    0 讨论(0)
  • 2021-01-30 21:23

    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

    0 讨论(0)
  • 2021-01-30 21:23

    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.

    0 讨论(0)
  • 2021-01-30 21:27

    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
    
    0 讨论(0)
提交回复
热议问题