Skip to main content
edited body
Source Link
immerzl
  • 321
  • 2
  • 4

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):-1"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

NextLast step is to construct the filter command. There is no need to specify the output-height, you can specify -1 and ffmpeg will keep the aspect ratio by applying the same scaling factor as for the width.

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):-1"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

Next step is to construct the filter command. There is no need to specify the output-height, you can specify -1 and ffmpeg will keep the aspect ratio by applying the same scaling factor as for the width.

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):-1"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

Last step is to construct the filter command. There is no need to specify the output-height, you can specify -1 and ffmpeg will keep the aspect ratio by applying the same scaling factor as for the width.

added 121 characters in body
Source Link
immerzl
  • 321
  • 2
  • 4

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):ih*min(1\,min(640/iw\,360/ih))"-1"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

Next step is to construct the filter command. There is no need to specify the output-height, you can specify -1 and ffmpeg will keep the aspect ratio by applying the same scaling factor as for the width.

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):ih*min(1\,min(640/iw\,360/ih))"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):-1"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))

Next step is to construct the filter command. There is no need to specify the output-height, you can specify -1 and ffmpeg will keep the aspect ratio by applying the same scaling factor as for the width.

Source Link
immerzl
  • 321
  • 2
  • 4

A more readable version can look like follows:

-filter_complex "scale=iw*min(1\,min(640/iw\,360/ih)):ih*min(1\,min(640/iw\,360/ih))"

640/iw is the horizontal scaling factor and 360/ih is the vertical scaling factor

You want to fit the scaled image inside the output box and keep the (storage) aspect ratio. You do this by selecting the smallest scaling factor with the minimum function: min(640/iw, 360/ih)

You want to prevent any upscaling (i.e. a scaling factor > 1.0) so you add another minimum function: min(1, min(640/iw, 360/ih))

Next step is to calculate the output resolution by multiplying the scaling-factor with input-width and input-height:
output-width = iw * min(1, min(640/iw, 360/ih))
output-height = ih * min(1, min(640/iw, 360/ih))