#!/usr/bin/env python3
"""needs.py: upload speed needed for the official 1080p60 settings, and the largest video bitrate a given upload speed carries.
Headroom 1.3 and 1.5 are OUR SUGGESTION (30% and 50% above the stream's bitrate); neither YouTube nor Twitch states a headroom."""
import math
def up(x, d=1): return math.ceil(x * 10**d - 1e-9) / 10**d
rows = [
 ('Twitch 1080p60, x264 or NVENC (CBR)', 6000, 96),
 ('YouTube 1080p60 H.264, minimum', 6000, 128),
 ('YouTube 1080p60 H.264, recommended', 17000, 128),
 ('YouTube 1080p60 AV1/H.265, minimum', 4000, 128),
 ('YouTube 1080p60 AV1/H.265, recommended', 12000, 128),
]
print('setting | video kbps | audio kbps | stream Mbps | x1.3 | x1.5')
for n, v, a in rows:
    s = (v + a) / 1000
    print(f'{n} | {v} | {a} | {s:.3f} | {up(s*1.3)} | {up(s*1.5)}')
print()
print('upload speed (Mbps, from a speed test) | max video kbps at x1.5 headroom | at x1.3 headroom (audio 128 kbps)')
for u in (5, 8, 10, 15, 20, 30, 50):
    lo = math.floor((u*1000/1.5 - 128)/100)*100; hi = math.floor((u*1000/1.3 - 128)/100)*100
    print(f'{u} | {lo} | {hi}')
print()
print('check: tool 70% row = x', round(1/0.7, 4), 'headroom of', round((1/0.7-1)*100, 1), '%')
