Created
January 20, 2020 19:36
-
-
Save po5/6286a91543964b9e0b538043635cbf17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vapoursynth as vs | |
import math | |
core = vs.get_core() | |
def nice_round(x, base=2): | |
return base * round(x / base) | |
def resizeroo(clip, max_width, max_height, func): | |
ratio = min(max_width / clip.width, max_height / clip.height) | |
clip = func(clip, nice_round(clip.width * ratio), nice_round(clip.height * ratio)) | |
border_left = (max_width - clip.width) / 2 | |
border_top = (max_height - clip.height) / 2 | |
if border_left % 2 == 1: | |
border_left += 1 | |
if border_top % 2 == 1: | |
border_top += 1 | |
border_right = border_left | |
border_bottom = border_top | |
if clip.width + border_left + border_right > max_width: | |
border_left -= 2 | |
if clip.height + border_top + border_bottom > max_height: | |
border_bottom -= 2 | |
clip = core.std.AddBorders(clip, border_left, border_right, border_top, border_bottom) | |
return clip | |
# thing = resizeroo(thing, 1920, 1080, core.resize.Spline36) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment