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

57 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Per-platform caption safe-zone sizing.
Each platform overlays its own UI chrome (right-rail actions, bottom caption/CTA)
over different regions, so caption height + vertical position must adapt: TikTok
captions sit at ~12-20% frame height in the lower third (Y≈63%), YouTube Shorts
smaller (~9%) to clear the title bar, Reels in between. Returns concrete pixel
values for a given frame height so the ASS builder places captions in the clear
zone on every surface.
"""
from __future__ import annotations
from dataclasses import dataclass
# fraction-of-frame-height sizing per surface.
_SURFACE = {
"tiktok": {"height_frac": 0.16, "y_frac": 0.63},
"reels": {"height_frac": 0.14, "y_frac": 0.62},
"shorts": {"height_frac": 0.09, "y_frac": 0.64},
"x": {"height_frac": 0.12, "y_frac": 0.60},
}
_DEFAULT = "tiktok"
@dataclass(frozen=True)
class SafeZone:
"""Resolved caption placement for a specific frame height."""
surface: str
fontsize: int # px, derived from height_frac × play_h
margin_v: int # px from the TOP edge (ASS alignment 8 = top-center)
y_frac: float
height_frac: float
def safezone_for(surface: str | None, play_h: int = 1920) -> SafeZone:
"""Resolve the caption safe-zone for ``surface`` at ``play_h`` pixels tall.
``margin_v`` is measured from the top (matching the ASS top-center alignment
the karaoke builder uses), computed from ``y_frac`` so captions land in the
platform's clear lower-third band.
"""
cfg = _SURFACE.get(str(surface or "").strip().lower(), _SURFACE[_DEFAULT])
fontsize = max(24, int(round(cfg["height_frac"] * play_h * 0.5)))
margin_v = int(round(cfg["y_frac"] * play_h)) - fontsize
return SafeZone(
surface=str(surface or _DEFAULT).lower(),
fontsize=fontsize,
margin_v=max(0, margin_v),
y_frac=cfg["y_frac"],
height_frac=cfg["height_frac"],
)
def supported_surfaces() -> tuple[str, ...]:
return tuple(_SURFACE)