fix(subtitles): honor user-edited caption text on the server render path
Fixes #69. The subtitle modal lets the user edit the caption text, but the edits only traveled through the in-browser Remotion path; the FFmpeg path (taken by every karaoke style and by any clip with server burns, i.e. all clips with default captions) sent style params only, so the server regenerated from the stored transcript and silently discarded the edits. /api/subtitle now accepts an optional 'words' list (clip-relative ms, the same shape the /transcript endpoint serves) and builds a synthetic transcript from it, so both the SRT and karaoke ASS generators burn the edited words verbatim. Words get Whisper's leading-space convention so the block collector keeps their boundaries. The modal sends them only when the text actually differs, and never on bulk apply-to-all (edits are per-clip). Verified live: an edited 5-word line burned exactly as typed, correctly grouped into blocks.
This commit is contained in:
parent
9c220efddb
commit
3790c65851
3 changed files with 49 additions and 2 deletions
38
app.py
38
app.py
|
|
@ -2100,6 +2100,14 @@ async def edit_clip(
|
||||||
print(f"❌ Edit Error: {e}")
|
print(f"❌ Edit Error: {e}")
|
||||||
raise HTTPException(status_code=500, detail=str(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):
|
class SubtitleRequest(BaseModel):
|
||||||
job_id: str
|
job_id: str
|
||||||
clip_index: int
|
clip_index: int
|
||||||
|
|
@ -2117,6 +2125,10 @@ class SubtitleRequest(BaseModel):
|
||||||
base_opacity: float = 1.0 # opacity of non-active words (dimmed modern look)
|
base_opacity: float = 1.0 # opacity of non-active words (dimmed modern look)
|
||||||
uppercase: bool = False
|
uppercase: bool = False
|
||||||
input_filename: Optional[str] = None
|
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")
|
@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_start = clip_data.get('start', 0)
|
||||||
sub_end = clip_data.get('end', 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
|
# Video Path
|
||||||
if req.input_filename:
|
if req.input_filename:
|
||||||
# Use chained file
|
# Use chained file
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,10 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
|
||||||
effect: options.effect || 'none',
|
effect: options.effect || 'none',
|
||||||
base_opacity: options.baseOpacity ?? 1.0,
|
base_opacity: options.baseOpacity ?? 1.0,
|
||||||
uppercase: options.uppercase || false,
|
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
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -444,12 +444,18 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
|
||||||
|
|
||||||
<div className="mt-5 shrink-0 space-y-2">
|
<div className="mt-5 shrink-0 space-y-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
|
// 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 = {
|
const styleOptions = {
|
||||||
position, fontSize, fontName, fontColor, borderColor, borderWidth, bgColor, bgOpacity,
|
position, fontSize, fontName, fontColor, borderColor, borderWidth, bgColor, bgOpacity,
|
||||||
// Karaoke burn (server-side ASS render)
|
// Karaoke burn (server-side ASS render)
|
||||||
style, effect, baseOpacity, uppercase, highlightColor,
|
style, effect, baseOpacity, uppercase, highlightColor,
|
||||||
// Remotion data
|
// Remotion data
|
||||||
remotion: useRemotionPreview ? subtitleConfig : null,
|
remotion: useRemotionPreview ? subtitleConfig : null,
|
||||||
|
captions: textEdited ? captions : null,
|
||||||
};
|
};
|
||||||
const bulkRunning = bulkProgress?.running;
|
const bulkRunning = bulkProgress?.running;
|
||||||
return (
|
return (
|
||||||
|
|
@ -469,7 +475,7 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
|
||||||
</div>
|
</div>
|
||||||
{onApplyAll && bulkCount > 1 && (
|
{onApplyAll && bulkCount > 1 && (
|
||||||
<button
|
<button
|
||||||
onClick={() => onApplyAll(styleOptions)}
|
onClick={() => onApplyAll({ ...styleOptions, captions: null })}
|
||||||
disabled={isProcessing}
|
disabled={isProcessing}
|
||||||
className="btn-ghost w-full flex items-center justify-center gap-2"
|
className="btn-ghost w-full flex items-center justify-center gap-2"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue