Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can i resize a video to 480 pixels high in AviSynth, while maintaining aspect ratio? Assume, for simplicity sake, the Bilinear resize.

i've tried:

source = DirectShowSource("TheClip.avi")
resized = BilinearResize(source, target_height=480)
return resized

But that gives the error

Script error: Invalid arguments to function "BilinearResize"


Note: The reason i don't supply a width is that i don't know a width. The script is being used by a media server, that now forces the use of AviSynth in order to perform resizing. i don't know the size of any video that anyone might choose to play - but i do know i need it resized to x480.

i presume AviSynth can do something like:

resized=BilinearResize(source, source.width*480/source.height, 480)

but that also fails:

Resize: YUY2 destination width must be even

i could keep going, trying to find a way to AddBorders or Crop, to make the width mod4, mod8, or mod16. Or i could ask here and maybe there already is a way to perform aspect-preserving scaling.

share|improve this question
    
Is there a way to cast ( source.width*480/source.height) to an int or something? –  soandos Aug 28 '11 at 18:08
    
i'm pretty sure the problem is that the width it's calculating is something like 691x480. This conflicts with YUY2 which stores one color value for each pair of pixels; and this video is one pair short (should be 690x480 or 691x480) –  Ian Boyd Aug 28 '11 at 19:23
    
So is there a round function? –  soandos Aug 28 '11 at 22:55

1 Answer 1

I'm a bit rusty with avisynth scripting, but I think this should work to get the width, based in a target height of 480, and a given modulo value... I couldn't test it as I don't have avisynth installed ...

 srceH = source.height
 srceW = source.width
    AR = (float(srceW) / float(srceH))
 targH = 480
 targW = int(float(targH) * AR)
 coMod = 4   # The codec modulo requirement 
 targW = ((targW / coMod) * coMod)
share|improve this answer
    
you missed setting the aspect variable. but after that it works great, thanks –  yoshco Feb 12 '12 at 2:39
    
Thanks yoshco... Yes, I had AR in one place and aspect in another... Changed to AR. –  Peter.O Feb 13 '12 at 11:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.