diff --git a/app.py b/app.py index 7a9e564..59a6dee 100644 --- a/app.py +++ b/app.py @@ -234,6 +234,11 @@ async def reserve_managed_action(request, minutes, job_id, job_type): """ if not BILLING_ENABLED: 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) if not managed_keys.has_active_entitlement(user): 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_path = os.path.join(output_dir, output_filename) - # Meter the FFmpeg re-encode (and any dubbed-video re-transcription) so it - # can't be looped for free off-quota. No-op for BYOK / self-host. - subtitle_minutes = _cloud_config.SUBTITLE_MINUTES if BILLING_ENABLED else 0 + # Burning captions is FREE. They're table stakes for short-form — a clip + # without them barely works on any platform — and the cost is nil: the SRT + # 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( request, subtitle_minutes, req.job_id, "subtitle") try: - # 1. Generate SRT - # Check if this is a dubbed video - if so, transcribe it fresh - is_dubbed = filename.startswith("translated_") - + # 1. Generate SRT — from the existing transcript, or a fresh + # transcription when the audio was dubbed (see the metering note above). if is_dubbed: print(f"🎙️ Dubbed video detected, transcribing audio for subtitles...") def run_transcribe_srt(): diff --git a/cloud/config.py b/cloud/config.py index d900d2d..5d65c54 100644 --- a/cloud/config.py +++ b/cloud/config.py @@ -82,6 +82,21 @@ MANAGED_ANALYSIS_MINUTES = 1 # 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. 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 RENDER_MINUTES = 3 diff --git a/tests/test_subtitle_metering.py b/tests/test_subtitle_metering.py new file mode 100644 index 0000000..d77f428 --- /dev/null +++ b/tests/test_subtitle_metering.py @@ -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