fix(subtitles): stop charging quota for burning captions
Captions are table stakes for short-form — a clip without them barely works on any platform — but every burn cost 2 minutes, 10% of the free monthly quota, roughly what generating the clip cost in the first place. People skipped them: only 9% of delivered clips had captions in the 25-jul-2026 prod audit (35 subtitle jobs against 380 process jobs). The charge never matched the work. The normal path reads the transcript already stored in metadata.json and runs one short FFmpeg pass — measured at 4s on CPU for a 12s clip, 1-2s on the GPU. Charging 120s of quota for that is ~30x the compute, and it was invisible in the UI, so users were drained without being told. The endpoint is already gated by require_managed_entitlement, so the charge was never what bounded abuse. Dubbed clips keep the charge: subtitling them re-runs Whisper over the translated audio, which is real work. The rule lives in cloud.config next to the constant so it stays testable without importing app. Also short-circuit reserve_managed_action on a zero-minute action rather than writing a 0-minute ledger row on every call.
This commit is contained in:
parent
98fd35130c
commit
a793e02ddf
3 changed files with 69 additions and 7 deletions
29
app.py
29
app.py
|
|
@ -234,6 +234,11 @@ async def reserve_managed_action(request, minutes, job_id, job_type):
|
||||||
"""
|
"""
|
||||||
if not BILLING_ENABLED:
|
if not BILLING_ENABLED:
|
||||||
return None
|
return None
|
||||||
|
if minutes <= 0:
|
||||||
|
# Free action (e.g. burning captions). Skip the ledger entirely rather
|
||||||
|
# than writing a 0-minute row on every call — the endpoint's own
|
||||||
|
# entitlement gate is what bounds it.
|
||||||
|
return None
|
||||||
user = await _user_from_request(request)
|
user = await _user_from_request(request)
|
||||||
if not managed_keys.has_active_entitlement(user):
|
if not managed_keys.has_active_entitlement(user):
|
||||||
return None # BYOK header path (self-host) — not metered
|
return None # BYOK header path (self-host) — not metered
|
||||||
|
|
@ -1980,17 +1985,27 @@ async def add_subtitles(req: SubtitleRequest, request: Request):
|
||||||
output_filename = f"subtitled_{generation_id}_{filename}"
|
output_filename = f"subtitled_{generation_id}_{filename}"
|
||||||
output_path = os.path.join(output_dir, output_filename)
|
output_path = os.path.join(output_dir, output_filename)
|
||||||
|
|
||||||
# Meter the FFmpeg re-encode (and any dubbed-video re-transcription) so it
|
# Burning captions is FREE. They're table stakes for short-form — a clip
|
||||||
# can't be looped for free off-quota. No-op for BYOK / self-host.
|
# without them barely works on any platform — and the cost is nil: the SRT
|
||||||
subtitle_minutes = _cloud_config.SUBTITLE_MINUTES if BILLING_ENABLED else 0
|
# comes from the transcript already sitting in metadata.json, and the burn is
|
||||||
|
# a single short FFmpeg pass (4s on CPU for a 12s clip, 1-2s on the GPU).
|
||||||
|
# Charging 2 minutes for that meant 10% of the whole free monthly quota per
|
||||||
|
# captioned clip, roughly what generating the clip cost in the first place —
|
||||||
|
# so people skipped it: only 9% of delivered clips had captions (prod audit,
|
||||||
|
# 25-jul-2026). The endpoint is already gated by require_managed_entitlement
|
||||||
|
# above, so this is not an open door.
|
||||||
|
#
|
||||||
|
# The dubbed path is the exception and keeps the charge: it runs a fresh
|
||||||
|
# Whisper transcription over the translated audio, which is real work.
|
||||||
|
is_dubbed = filename.startswith("translated_")
|
||||||
|
subtitle_minutes = (_cloud_config.subtitle_minutes_for(filename)
|
||||||
|
if BILLING_ENABLED else 0)
|
||||||
reservation_id = await reserve_managed_action(
|
reservation_id = await reserve_managed_action(
|
||||||
request, subtitle_minutes, req.job_id, "subtitle")
|
request, subtitle_minutes, req.job_id, "subtitle")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 1. Generate SRT
|
# 1. Generate SRT — from the existing transcript, or a fresh
|
||||||
# Check if this is a dubbed video - if so, transcribe it fresh
|
# transcription when the audio was dubbed (see the metering note above).
|
||||||
is_dubbed = filename.startswith("translated_")
|
|
||||||
|
|
||||||
if is_dubbed:
|
if is_dubbed:
|
||||||
print(f"🎙️ Dubbed video detected, transcribing audio for subtitles...")
|
print(f"🎙️ Dubbed video detected, transcribing audio for subtitles...")
|
||||||
def run_transcribe_srt():
|
def run_transcribe_srt():
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,21 @@ MANAGED_ANALYSIS_MINUTES = 1
|
||||||
# Remotion render proxy do real server compute per call. Meter a small fixed
|
# Remotion render proxy do real server compute per call. Meter a small fixed
|
||||||
# cost so an entitled user can't loop them for free off-quota.
|
# cost so an entitled user can't loop them for free off-quota.
|
||||||
SUBTITLE_MINUTES = 2
|
SUBTITLE_MINUTES = 2
|
||||||
|
|
||||||
|
|
||||||
|
def subtitle_minutes_for(filename: str) -> int:
|
||||||
|
"""Minutes charged for burning captions onto ``filename``.
|
||||||
|
|
||||||
|
Zero for the normal path: the SRT comes from the transcript already stored
|
||||||
|
in metadata.json and the burn is one short FFmpeg pass, so there is nothing
|
||||||
|
to recover. Captions are also table stakes for short-form — charging 2 min
|
||||||
|
(10% of the free monthly quota) per clip priced them out of the product and
|
||||||
|
only 9% of delivered clips ever had them (prod audit, 25-jul-2026).
|
||||||
|
|
||||||
|
Dubbed clips are the exception: subtitling them re-runs Whisper over the
|
||||||
|
translated audio, which is real compute, so they keep the charge.
|
||||||
|
"""
|
||||||
|
return SUBTITLE_MINUTES if str(filename).startswith("translated_") else 0
|
||||||
HOOK_MINUTES = 1
|
HOOK_MINUTES = 1
|
||||||
RENDER_MINUTES = 3
|
RENDER_MINUTES = 3
|
||||||
|
|
||||||
|
|
|
||||||
32
tests/test_subtitle_metering.py
Normal file
32
tests/test_subtitle_metering.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
"""What burning captions costs the user.
|
||||||
|
|
||||||
|
Captions are mandatory for short-form to work at all, and the normal path costs
|
||||||
|
the server nothing beyond one short FFmpeg pass — the transcript is already in
|
||||||
|
metadata.json. Charging for it (2 min, 10% of the free monthly quota per clip)
|
||||||
|
priced captions out of the product: only 9% of delivered clips had them in the
|
||||||
|
25-jul-2026 prod audit. Only the dubbed path, which re-runs Whisper, still pays.
|
||||||
|
"""
|
||||||
|
from cloud.config import SUBTITLE_MINUTES, subtitle_minutes_for
|
||||||
|
|
||||||
|
|
||||||
|
class TestSubtitleMetering:
|
||||||
|
def test_normal_clip_is_free(self):
|
||||||
|
assert subtitle_minutes_for("Some_Video_Title_clip_1.mp4") == 0
|
||||||
|
|
||||||
|
def test_already_subtitled_clip_is_free(self):
|
||||||
|
# Restyling captions must not cost anything either.
|
||||||
|
assert subtitle_minutes_for("subtitled_1784974487_My_Video_clip_1.mp4") == 0
|
||||||
|
|
||||||
|
def test_hooked_or_edited_clip_is_free(self):
|
||||||
|
assert subtitle_minutes_for("edited_My_Video_clip_2.mp4") == 0
|
||||||
|
|
||||||
|
def test_dubbed_clip_still_pays_for_the_transcription(self):
|
||||||
|
# This path runs a fresh Whisper pass over the translated audio.
|
||||||
|
assert subtitle_minutes_for("translated_es_My_Video_clip_1.mp4") == SUBTITLE_MINUTES
|
||||||
|
|
||||||
|
def test_dubbed_prefix_must_be_at_the_start(self):
|
||||||
|
# A clip merely containing the word must not be charged.
|
||||||
|
assert subtitle_minutes_for("my_translated_notes_clip_1.mp4") == 0
|
||||||
|
|
||||||
|
def test_handles_non_string_input(self):
|
||||||
|
assert subtitle_minutes_for(None) == 0
|
||||||
Loading…
Reference in a new issue