vsutil
vsutil copied to clipboard
get_w
"""
https://github.com/HomeOfVapourSynthEvolution/havsfunc/blob/master/havsfunc.py#L5907
"""
import math
def cround(x):
return math.floor(x + 0.5) if x > 0 else math.ceil(x - 0.5)
def m4(x):
return 16 if x < 16 else cround(x / 4) * 4
desc_w = m4(849 * 1920 / 1080)
print(f'havsfunc: {desc_w}')
"""
https://github.com/Infiziert90/getnative/blob/master/getnative/app.py#L194
"""
def getw(h, only_even=True):
w = h * 16 / 9
w = int(round(w))
if only_even:
w = w // 2 * 2
return w
desc_w = getw(849)
print(f'getnative: {desc_w}')
"""
https://github.com/Irrational-Encoding-Wizardry/kagefunc/blob/master/kagefunc.py#L336
"""
def getw(height, aspect_ratio=16 / 9, only_even=True):
"""
Returns width for image.
"""
width = height * aspect_ratio
width = int(round(width))
return width // 2 * 2 if only_even else width
desc_w = getw(849)
print(f'kagefunc: {desc_w}')
"""
https://github.com/Irrational-Encoding-Wizardry/vsutil/blob/master/vsutil/info.py#L74
"""
def get_w(height: int, aspect_ratio: float = 16 / 9, *, only_even: bool = True) -> int:
"""
Calculates the width for a clip with the given height and aspect ratio.
only_even is True by default because it imitates the math behind most standard resolutions (e.g. 854x480).
"""
width = height * aspect_ratio
if only_even:
return round(width / 2) * 2
return round(width)
desc_w = get_w(849)
print(f'vsutil: {desc_w}')
↓
havsfunc: 1508
getnative: 1508
kagefunc: 1508
vsutil: 1510
Well, 849*16/9 == 849*1920/1080 == 1509.3333333333333 ~= Fraction(4528, 3) so vsutil is actually the only one doing this correctly if we're to assume we round to nearest even :laughing: . Raise the issue in the other three repo's unless for some reason this is meant to be rounded down.
EDIT: reason would seem to be looking for a mod4 resolution (maybe subsampling concerns), which I guess we could implement as another param in get_w but I don't see the point since 849 is not mod4/mod2 either.