[MEncoder-users] zoom to fit resolution

James Hastings-Trew jimht at shaw.ca
Thu Aug 21 19:03:05 CEST 2008


Dominik 'Rathann' Mierzejewski wrote:
>> -vf scale did not allow me to maintain the aspect ratio,
>>     
>
> That statement is false. The scale filter does have an option to keep the
> aspect ratio. Please check man mplayer.
>
> Regards,
> R.
>   
It does, but in general it doesn't do what he wants. He wants a general 
"fix video into this size" option - which could be enlargement, or 
reduction. Mencoder doesn't offer that, because for the aspect ratio 
option to work in -vf scale you need to specify at least one of the 
dimensions, and then you don't have any control over what the other 
dimension will end up being.

I'm not a console scripter, but I did work out a little routine in DOS 
to do what he wants. I can't post it here because it relies on a bunch 
of third party command line tools and custom scripts, but I can post 
some pseudo-code that should give him a push in the right direction. 
(this assumes that $actualwidth and $actualheight have a square pixel 
aspect ratio - if not, you'll need to precalculate):

If your source is from DVD, you'll have to precalculate the actualwidth 
and height.

if ($vidmode=="PAL") {
    $widthscale=1.066
    $heightscale=1
    if($aspect=="WIDE") {
       $widthscale=1.422
       }
    }
else {
    // if its not PAL it has to be NTSC
    $widthscale=1
    $heightscale=1.125
    if($aspect=="WIDE") {
       $widthscale=1.186
       $heightscale=1
       }
    }
$actualwidth=$actualwidth*$widthscale
$actualheight=$actualheight*$heightscale

$optimalwidth=848
$optimalheight=480
// movie will be fit to this size - either increasing or decreasing to fit
// put in whatever values you want but make sure they are divisible by 16.

// calculate the scale factor for width and height and use whichever is 
smaller
$widthfactor=$optimalwidth/$actualwidth
$heightfactor=$optimalheight/$actualheight
$final_factor=$widthfactor
if $heightfactor<$widthfactor {
    $final_factor=$heightfactor
    }

// to find out which dimension "won" compare the results to the optimal 
values
if (($actualwidth*$finalfactor)=$optimalwidth) {
    $scale=$optimalwidth:-10
    }
else {
    $scale=-10:$optimalheight
    }

Then you can plug "-vf $scale" into your mencoder command line.

Hope this helps.







More information about the MEncoder-users mailing list