"""At any fixed delivery ceiling and ~52% mean utilisation, the mean is not the risk -- the peaks are. Measure per-frame peak-to-mean, then check whether the leaky-bucket rate controller actually holds the ceiling.""" import sys; sys.path.insert(0,'tools/encoder') import vq_hybrid as H, ratectl as RC, numpy as np S=sys.argv[1] BW=4_000_000/8/1024 print(f"ceiling {BW:.0f} KB/s (4 Mbps), audio {RC.AUDIO_KBPS} KB/s\n") print(f'{"scene":8}{"lam":>5}{"mean":>8}{"p90":>8}{"MAX":>8}{"pk/mean":>9}{"MAX % of pipe":>15}',flush=True) for s in ['00010','00020','00146','00181']: m=H.build(f'{S}/fr_{s}',k1=256,k4=256,iters=16) for lam in [60.,10.]: e=H.encode(m,lam=lam) kb=e['sizes']*12/1024 # per-frame instantaneous KB/s tot=kb+RC.AUDIO_KBPS print(f'{s:8}{lam:5.0f}{tot.mean():8.1f}{np.percentile(tot,90):8.1f}' f'{tot.max():8.1f}{tot.max()/tot.mean():9.2f}{tot.max()/BW*100:14.1f}%' + (' OVER' if tot.max()>BW else ''),flush=True)