# How to do dynamic calculation with avisynth?

1. I want to find the max integer scale to convert old console video footage (atari, nes, snes, etc) using this information, however depending on the source height or target height this maximum integer value change, example from a 320x240 source:

Code:
```720  / 240 = 3
1080 / 240 = 4.5
1440 / 240 = 6```
So for a 1440 target I manually do:

Code:
`PointResize(width*6,height*6)`
Source: Target: The height of the source isn't always 240, sometimes it might be 224, 304 or other funky height. Is there a way to make avisynth automatically use the height information from the video source and calculate/find this max integer value for me?

Something like Replace '?' with the result of 1440 / height of source?

Code:
`PointResize(width*?,height*?)`
Thank you.  Quote
2. So you the maximum integer value that gives you a height of 1440 or less?

Code:
```iscale = int(1440 / height)
PointResize(width*iscale, height*iscale)```  Quote
3. another example, if you want to stay inside 1920x1080, you could use:
Code:
```iscale = Min(int(1920/ width), int(1080 / height))
PointResize(width*iscale, height*iscale)```  Quote
4. Thank you jagabo and Selur!  Quote
5. If you want something that's easy to customize for each video:

Code:
```MAXWIDTH =2560
MAXHEIGHT = 1440
iscale = Min(int(MAXWIDTH/width), int(MAXHEIGHT/height))
PointResize(width*iscale, height*iscale)```
Just change the MAXWIDTH and MAXHEIGHT to the limits you need.  Quote
6. Nice!

Thank you jagabo.  Quote
7. Jagabo asked me a question however I was working at the moment and I couldn't answer it before he edit the post. So, yes it would be nice to find the max integer scale I can find although still I want to always keep a 4:3 aspect ratio since some source aspect ratio it's 12:7, 8:7, 5:4 so on and so forth.

Thank you.  Quote
8. If the source isn't a 4:3 frame size you cannot multiply both the width and height by the same number and get a final 4:3 frame. One or the other will have to use a different number. For example, with a 352x240 source:

Code:
```iscale = int(1440 / height)
PointResize(height*iscale*4/3, height*iscale)```
iscale will be 6 and you will get the desired frame height of 1440 but to get a final 4:3 frame (1920x1440) the horizontal scaling factor will be 5.45454..., not 6.  Quote
9. What would be the best action?
Correct the frame before upscale?  Quote
10. If you want the point resize look it will usually be best to let the upscale use a non-integer scaling rather than scaling the source to a 4:3 frame size first.  Quote
11. Thank you jagabo.  Quote
12. You can do the smooth upscale like this:

Code:
```LWLibavVideoSource("00vnHM2.png")
ConvertToYV12()
nnedi3_rpow2(8, cshift="spline36Resize", fwidth=1920, fheight=1440) # upscale 8x, 320x240 to 2560x1920, then downscale to 1920x1440
aWarpSharp2(depth=20)
Sharpen(0.3)```  Quote
13. You can do the smooth upscale like this:

Code:
```LWLibavVideoSource("00vnHM2.png")
ConvertToYV12()
nnedi3_rpow2(8, cshift="spline36Resize", fwidth=1920, fheight=1440) # upscale 8x, 320x240 to 2560x1920, then downscale to 1920x1440
aWarpSharp2(depth=20)
Sharpen(0.3)```
Thank you jagabo!  Quote
14. It looks amazing, here a few samples.
Thank you jagabo.  Quote

Statistics