caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

48 lines
1.4 KiB
Python

"""The OTT bitrate ladder (MV3). One set of CMAF segments serves both HLS and DASH.
Every rung uses the same 2 s GOP (closed, no scene-cut keyframes), so segment
boundaries line up across rungs and a player can switch at any segment.
Rungs above the source height are dropped (no upscaling); the lowest rung is
always kept. Audio is one AAC stereo rendition; audio-only titles get just it.
"""
from __future__ import annotations
from dataclasses import dataclass
SEGMENT_SECONDS = 2
GOP_SECONDS = 2
@dataclass(frozen=True)
class Rung:
name: str
height: int
video_kbps: int
max_kbps: int
profile: str = "high"
LADDER: tuple[Rung, ...] = (
Rung("1080p", 1080, 4500, 6000),
Rung("720p", 720, 2800, 3800),
Rung("480p", 480, 1400, 1900, "main"),
Rung("360p", 360, 800, 1100, "main"),
)
AUDIO_KBPS = 128
def rungs_for(source_height: int) -> tuple[Rung, ...]:
"""Rungs at or below the source height (the lowest is always kept)."""
keep = tuple(r for r in LADDER if r.height <= max(int(source_height), 0))
return keep or (LADDER[-1],)
def scaled_width(source_w: int, source_h: int, height: int) -> int:
"""Even width for ``height`` keeping the source aspect (vertical or landscape)."""
width = round(int(source_w) * int(height) / max(int(source_h), 1))
return max(2, width - width % 2)
__all__ = ["AUDIO_KBPS", "GOP_SECONDS", "LADDER", "Rung", "SEGMENT_SECONDS", "rungs_for", "scaled_width"]