Skip to content

Instantly share code, notes, and snippets.

@wiwaz
Last active April 6, 2024 15:37
Show Gist options
  • Save wiwaz/91751d5a564f194f2805530f761b3e71 to your computer and use it in GitHub Desktop.
Save wiwaz/91751d5a564f194f2805530f761b3e71 to your computer and use it in GitHub Desktop.
def descale_args(
clip: vs.VideoNode,
width: int | float = None,
height: int | float = None,
src_left: float = None,
src_top: float = None,
width_parity: int = None,
height_parity: int = None,
):
out_args = dict()
if not float(width).is_integer():
src_width = width
width_parity = clip.width - width_parity
width = width_parity - 2 * floor((width_parity - src_width) / 2)
shift_left = (width - src_width) / 2
src_left = shift_left + src_left if src_left else shift_left
out_args.update(src_width=src_width)
if not float(height).is_integer():
src_height = height
height_parity = clip.height - height_parity
height = height_parity - 2 * floor((height_parity - src_height) / 2)
shift_top = (height - src_height) / 2
src_top = shift_top + src_top if src_top else shift_top
out_args.update(src_height=src_height)
out_args.update(width=width, height=height)
if src_left:
out_args.update(src_left=src_left)
if src_top:
out_args.update(src_top=src_top)
return out_args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment