Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Konformigi()
  2. #  Resize the video for the largest resolution that still fits an defined box, retaining video's DAR (Display Aspect Ratio).
  3. #  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".
  4. #
  5.  
  6.  
  7. Function Konformigi(clip c, int "width", int "height", string "ResizeMethod",
  8. \ int "modW", int "modH", string "roundmode")
  9. {
  10.  
  11. # Set Defaults
  12.  
  13.     width = Default(width, c.width()) # box width
  14.     height = Default(height, c.height()) # box height
  15.     ResizeMethod = Default(ResizeMethod, "Spline36Resize") #chose your favorite resizer
  16.     modW = Default(modW, 4) #defaults for YV12
  17.     modH = Default(modH, 2) #defaults for YV12
  18.     roundmode = Default(roundmode, "nearest") #can be "up" or "down" too
  19.  
  20. # Hack for assert work. I don't know why i can't put this inside the assert function
  21.  
  22. widthtAssert = (width/modW)*modW
  23. heightAssert = (height/modH)*modH
  24.  
  25. # Quick sanity check, to guarantee the desired resolution, and the desired roundmode
  26.    
  27. Assert( width == widthtAssert , "Your box width needs to obey the modW you have set")
  28. Assert( height == heightassert , "Your box height needs to obey the modH you have set")
  29. Assert( roundmode == "down" || roundmode == "up" || roundmode == "nearest" , """Your roundmode needs to be "down" or "up" or "nearest". """)
  30.  
  31. # Calculate the scale factor
  32.  
  33. scaleWidth  = Float(Width)/Float(c.width())
  34. scaleHeight = Float(Height)/Float(c.Height())
  35. scaleFactor = Min(scaleWidth,scaleHeight)
  36.  
  37. # Apply the scale factor and convert to integer using the desired rounding
  38.  
  39. newWidth = roundmode == "nearest" ? (Round((c.Width() * scaleFactor)/modW))*modW :
  40.  \          roundmode == "up" ? Ceil((c.Width() * scaleFactor)/modW)*modW :
  41.  \          (Int(c.Width() * scaleFactor)/modW)*modW    # roundmode == "down"
  42. newHeight = roundmode == "nearest" ? (Round((c.Height() * scaleFactor)/modH))*modH :
  43.  \          roundmode == "up" ? Ceil((c.Height() * scaleFactor)/modH)*modH :
  44.  \          (Int(c.Height() * scaleFactor)/modH)*modH    # roundmode == "down"
  45.  
  46.  
  47. # 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.
  48.  
  49. newWidth = (newWidth > Width) ? width : newWidth
  50. newHeight = (newHeight > Height) ? Height : newHeight
  51.  
  52. # Apply the desired resizer
  53.  
  54. Eval(ResizeMethod + "(c, " + String(newWidth) + ", " + String(newHeight) + ")")
  55.  
  56. return last
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement