let ffmpeg auto-calc height value when specifying (new) width while keeping aspect ratio?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

let ffmpeg auto-calc height value when specifying (new) width while keeping aspect ratio?

Ben Stover
Assume I want to re-encode a video.

The new video should have the same aspect ratio as the original.

I want to change the resolution of the new video to 1680 but don't want to calculate manually the corresponding height (dividable by 2).

Can I tell ffmpeg to automatically calculate the appropriate height by using the specified width and the given aspect ratio?

Thank you
Ben
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: let ffmpeg auto-calc height value when specifying (new) width while keeping aspect ratio?

Moritz Barsnick
On Thu, Nov 01, 2018 at 07:56:52 +0100, Ben wrote:
> The new video should have the same aspect ratio as the original.
> I want to change the resolution of the new video to 1680 but don't want to calculate manually the corresponding height (dividable by 2).
> Can I tell ffmpeg to automatically calculate the appropriate height by using the specified width and the given aspect ratio?

Sure. Using the "scale" filter, there's the magic negative dimension:

https://ffmpeg.org/ffmpeg-filters.html#scale-1

  "If one and only one of the values is -n with n >= 1, the scale
  filter will use a value that maintains the aspect ratio of the input
  image, calculated from the other specified dimension. After that it
  will, however, make sure that the calculated dimension is divisible
  by n and adjust the value if necessary."

In other words:

$ ffmpeg -i input -vf scale=1680:-2 output

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".