Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Konformigi()
- # Resize the video for the largest resolution that still fits an defined box, retaining video's DAR (Display Aspect Ratio).
- # Useful for re-encodes to cellphones, upscales for your screen, etc. Basically, makes what every decent video player do when you ask it to go "full screen".
- #
- Function Konformigi(clip c, int "width", int "height", string "ResizeMethod",
- \ int "modW", int "modH", string "roundmode")
- {
- # Set Defaults
- width = Default(width, c.width()) # box width
- height = Default(height, c.height()) # box height
- ResizeMethod = Default(ResizeMethod, "Spline36Resize") #chose your favorite resizer
- modW = Default(modW, 4) #defaults for YV12
- modH = Default(modH, 2) #defaults for YV12
- roundmode = Default(roundmode, "nearest") #can be "up" or "down" too
- # Hack for assert work. I don't know why i can't put this inside the assert function
- widthtAssert = (width/modW)*modW
- heightAssert = (height/modH)*modH
- # Quick sanity check, to guarantee the desired resolution, and the desired roundmode
- Assert( width == widthtAssert , "Your box width needs to obey the modW you have set")
- Assert( height == heightassert , "Your box height needs to obey the modH you have set")
- Assert( roundmode == "down" || roundmode == "up" || roundmode == "nearest" , """Your roundmode needs to be "down" or "up" or "nearest". """)
- # Calculate the scale factor
- scaleWidth = Float(Width)/Float(c.width())
- scaleHeight = Float(Height)/Float(c.Height())
- scaleFactor = Min(scaleWidth,scaleHeight)
- # Apply the scale factor and convert to integer using the desired rounding
- newWidth = roundmode == "nearest" ? (Round((c.Width() * scaleFactor)/modW))*modW :
- \ roundmode == "up" ? Ceil((c.Width() * scaleFactor)/modW)*modW :
- \ (Int(c.Width() * scaleFactor)/modW)*modW # roundmode == "down"
- newHeight = roundmode == "nearest" ? (Round((c.Height() * scaleFactor)/modH))*modH :
- \ roundmode == "up" ? Ceil((c.Height() * scaleFactor)/modH)*modH :
- \ (Int(c.Height() * scaleFactor)/modH)*modH # roundmode == "down"
- # I think the following is needed to guarantee that the box limits are keeped when rounding up. I'm not 100% sure, but it won't hurt.
- newWidth = (newWidth > Width) ? width : newWidth
- newHeight = (newHeight > Height) ? Height : newHeight
- # Apply the desired resizer
- Eval(ResizeMethod + "(c, " + String(newWidth) + ", " + String(newHeight) + ")")
- return last
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement