[Libav-user] Preserve aspect ration while using sws_scale() API

Carl Eugen Hoyos ceffmpeg at gmail.com
Tue Aug 4 00:20:31 EEST 2020


Am Mo., 3. Aug. 2020 um 19:03 Uhr schrieb gga <ggarra13 at gmail.com>:
>
> On 3/8/20 03:47, rohit khali wrote:
> >
> > I am using sws_scale() API to scale my decoded YUV(any format) to
> > YUV420P with 'new' width and height.
> > Instead of hardcoding destination width and height, I want to preserve
> > the original aspect ratio. My idea was to provide destination height
> > and let API decide on width using aspect ratio.
> > Is there a way to achieve this?
> > Thanks in advance for the help!
>
> There's nothing in the ffmpeg api to do it, but you can do it yourself
> trivially.
>
> double aratio = (double) width / height;
> size_t newwidth = aratio * newheight;
>
> Or is there something else I am missing?

No reason to use a double, AVRational is a possible solution.

Carl Eugen


More information about the Libav-user mailing list