diff --git a/app.py b/app.py index b525f18..b5f3e08 100644 --- a/app.py +++ b/app.py @@ -2100,6 +2100,14 @@ async def edit_clip( print(f"❌ Edit Error: {e}") raise HTTPException(status_code=500, detail=str(e)) +class CaptionWordIn(BaseModel): + """One user-edited caption word, clip-relative ms — the same shape the + /transcript endpoint hands the subtitle modal.""" + text: str + startMs: int + endMs: int + + class SubtitleRequest(BaseModel): job_id: str clip_index: int @@ -2117,6 +2125,10 @@ class SubtitleRequest(BaseModel): base_opacity: float = 1.0 # opacity of non-active words (dimmed modern look) uppercase: bool = False input_filename: Optional[str] = None + # User-edited caption words. When present, the burn uses them VERBATIM + # instead of regenerating from the stored transcript — without this, text + # edits in the modal were silently discarded on the server render path. + words: Optional[List[CaptionWordIn]] = None @app.get("/api/clip/{job_id}/{clip_index}/transcript") @@ -2680,6 +2692,32 @@ async def add_subtitles(req: SubtitleRequest, request: Request): sub_start = clip_data.get('start', 0) sub_end = clip_data.get('end', 0) + # User-edited captions win over both: build a synthetic clip-relative + # transcript from them so the SRT/ASS generators burn the edited words + # verbatim (issue #69 — edits used to be dropped on this path). + if req.words: + if len(req.words) > 2000: + raise HTTPException(status_code=400, detail="Too many caption words (max 2000).") + # Leading space = Whisper's word-boundary convention; without it the + # block collector treats each word as a continuation fragment and + # glues the whole line together. + edited = [ + {"word": " " + w.text.strip(), "start": max(0.0, w.startMs / 1000.0), + "end": max(0.0, w.endMs / 1000.0)} + for w in req.words if w.text.strip() and w.endMs > w.startMs >= 0 + ] + if edited: + edited.sort(key=lambda w: w["start"]) + sub_transcript = { + "language": (transcript or {}).get("language", "en"), + "segments": [{ + "start": edited[0]["start"], "end": edited[-1]["end"], + "text": " ".join(w["word"] for w in edited), + "words": edited, + }], + } + sub_start, sub_end = 0.0, max(w["end"] for w in edited) + # Video Path if req.input_filename: # Use chained file diff --git a/dashboard/src/components/ResultCard.jsx b/dashboard/src/components/ResultCard.jsx index c25bf00..d88aa9a 100644 --- a/dashboard/src/components/ResultCard.jsx +++ b/dashboard/src/components/ResultCard.jsx @@ -377,7 +377,10 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK effect: options.effect || 'none', base_opacity: options.baseOpacity ?? 1.0, uppercase: options.uppercase || false, - input_filename: serverVideoFile + input_filename: serverVideoFile, + // Edited caption text (clip-relative ms); null = server + // regenerates from the transcript as before. + words: options.captions || null }) }); diff --git a/dashboard/src/components/SubtitleModal.jsx b/dashboard/src/components/SubtitleModal.jsx index 36dc09f..0347e53 100644 --- a/dashboard/src/components/SubtitleModal.jsx +++ b/dashboard/src/components/SubtitleModal.jsx @@ -444,12 +444,18 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
{(() => { + // Text edits must survive the server render path too + // (issue #69): send the edited words whenever the text + // differs from what the transcript produced. + const textEdited = originalCaptions.length > 0 + && editableText.trim() !== originalCaptions.map((c) => c.text).join(' ').trim(); const styleOptions = { position, fontSize, fontName, fontColor, borderColor, borderWidth, bgColor, bgOpacity, // Karaoke burn (server-side ASS render) style, effect, baseOpacity, uppercase, highlightColor, // Remotion data remotion: useRemotionPreview ? subtitleConfig : null, + captions: textEdited ? captions : null, }; const bulkRunning = bulkProgress?.running; return ( @@ -469,7 +475,7 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
{onApplyAll && bulkCount > 1 && (