Scaling within limits whilst preserving aspect ratio

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

Scaling within limits whilst preserving aspect ratio

Thomas N McEwan
I don't know if what I'm trying to do is possible or not with ffmpeg,
but here goes:

I'm trying to write a script for automatically batch converting movies
into a form optimised for playback on my PDA (Tapwave Zodiac) using
TCPMP.  I've noticed that the best performance happens, obviously, when
the player does not need to do any scaling, which is needed by videos
that have a higher vertical or horizontal resolution than the device's
screen (480x320, landscape).  The problem is, my collection of input
videos is quite diverse and they have quite a variety of different
aspect ratios.

What I'd like to do, then, is to scale the videos, whilst preserving
their original aspect ratio, so that they can be displayed entirely on
the device's screen without scaling but of course at maximal size, so
every pixel encoded in the video translates exactly to one real pixel on
the display.

What this requires, then, is that videos which happen to have a wider
original ratio than the device's physical screen be scaled until their
left and right borders are exactly coincident with the screen edges
(which will leave a gap between top and bottom edges that the player
will simply blank out as horizontal letterbox bars with minimal
processor usage) and, conversely, videos with a thinner ratio than the
physical screen be shrunk until their top and bottom edges are
coincident with the screen edges, leaving vertical side bars which,
again, will be filled in by the device and need not be stored in the video.

Is there a mechanism in ffmpeg that can do this, or is it possible to
write a script to modify the input parameters accordingly?  The best I
can manage so far is simply to set the physical screen size of the
device using "-s 320x480", and put up with whatever distortion occurs
when the aspect ratios don't happen to be the same between the physical
screen and the original file (I could, of course, use scaling in the
player to preserve the ratio, but that gobbles up battery and cpu power,
and is also, I feel, an inelegant solution compared to converting all
the files to fit properly in the first place).

If such a capacity were present in ffmpeg, I imagine that the required
commands would be a combination of keeping the aspect ratio the same as
the input, and choosing whichever is possible out of height<=320 &
width=480, or height=320 & width<=480.

Is there currently a way to do this and, if not, might it be worth
requesting it to the developers?  Alternatively is there, perhaps, a
separate program that can read the necessary parameters of the input
video file into a script and calculate the necessary parameters to pass
to ffmpeg?

Thanks and, of course, sorry if this is a repeated topic.  I've checked
the list archives, but I could always have missed something.

Tom
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Scaling within limits whilst preserving aspect ratio

Eduardo M Kalinowski-2
Thomas N McEwan wrote:

> I'm trying to write a script for automatically batch converting movies
> into a form optimised for playback on my PDA (Tapwave Zodiac) using
> TCPMP.  I've noticed that the best performance happens, obviously, when
> the player does not need to do any scaling, which is needed by videos
> that have a higher vertical or horizontal resolution than the device's
> screen (480x320, landscape).  The problem is, my collection of input
> videos is quite diverse and they have quite a variety of different
> aspect ratios.
>
> What I'd like to do, then, is to scale the videos, whilst preserving
> their original aspect ratio, so that they can be displayed entirely on
> the device's screen without scaling but of course at maximal size, so
> every pixel encoded in the video translates exactly to one real pixel on
> the display.
>
> Is there a mechanism in ffmpeg that can do this, or is it possible to
> write a script to modify the input parameters accordingly?  The best I
> can manage so far is simply to set the physical screen size of the
> device using "-s 320x480", and put up with whatever distortion occurs
> when the aspect ratios don't happen to be the same between the physical
> screen and the original file (I could, of course, use scaling in the
> player to preserve the ratio, but that gobbles up battery and cpu power,
> and is also, I feel, an inelegant solution compared to converting all
> the files to fit properly in the first place).
>  

It is not possible to do that automatically with ffmpeg at this moment.

> Is there currently a way to do this and, if not, might it be worth
> requesting it to the developers?  Alternatively is there, perhaps, a
> separate program that can read the necessary parameters of the input
> video file into a script and calculate the necessary parameters to pass
> to ffmpeg?
>  

You can write a simpler wrapper script to do the job. Use ffmpeg -i on
the file, parse the output to see the video resolution, and do a little
math to calculate the size of the scaled video. Then call ffmpeg again,
passing the calculated size.


--
They call them "squares" because it's the most complicated shape they can
deal with.

Eduardo M KALINOWSKI
[hidden email]
http://move.to/hpkb

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user