Skip to content

Draw the hook title on the cover - #173

Merged
A21-devs merged 2 commits into
mainfrom
feat/cover-hook-title
Dec 4, 2026
Merged

A21-devs merged 2 commits into
mainfrom
feat/cover-hook-title

Conversation

@A21-devs

@A21-devs A21-devs commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Closes #108.

What

  • captions.build_title_ass(hook, style, width, height): an ASS document with only the hook title. It uses the same [Script Info] and Hook style as the clip's captions and the same wrapping (at most 3 lines), so the title lands exactly where the hook does in the clip. It runs from 0 to 9:59:59 with no \fad, because the cover frame keeps its clip time (for the follow/speaker crop) and a frame from the fade-in would get a half-transparent title. None for a blank title.
  • build_ass now gets its header and hook text from the same two helpers (_ass_header, _hook_lines). Its output is unchanged and the existing caption tests pass as before.
  • render.cover_command(..., title_file=) adds ass=<file> on [vout], at the clip's frame size, before the scale to 720. render_cover(..., title_ass=) writes it under a safe temp name next to the cover and runs ffmpeg there, the same trick render() uses to avoid libass path escaping. The source and output paths are resolved first, so a relative source still works. The temp file is removed in a finally.
  • thumbnail.make_cover(..., title=) builds the ASS with the run's caption style scaled to its aspect. _render_one passes its hook, which is the AI title with --hook --copy, the first sentence with --hook alone, and None without --hook. So the cover stays clean without a hook, and re-renders from the review page or MCP get the same treatment since they go through _render_one too.

Testing

  • uv run ruff check src tests, uv run mypy, uv run pytest -q: 732 passed.
  • New tests:
    • the title ASS has the clip's exact header, one Hook event from 0 with no fade, the same wrapped text as the clip's hook, and None when blank
    • the cover graph burns the title before the scale
    • make_cover builds it at 1:1 with the clean font, and sends nothing without a title or with a blank one
    • ffmpeg test: a clip rendered with a hook, and a titled cover made from a relative source path into another folder. The title rows are only in the top part, the titled cover matches the clip's frame at 1.5 s (mean diff < 4), and no temp .ass is left.
  • Real run: 90 s of Roblox gameplay with a Windows TTS voice mixed in at 30 s, clipwright speech.mp4 -n 1 --hook --no-cache. Whisper on CUDA, 46 words, picked 30-50 s, hook "Watch this jump.". The cover (720x1280) has the title box in the same place and size as frame 1.5 s of the clip. Re-rendering the clip with rerender_clip(..., 31, 50): the title box on the new cover is identical (mean 58.9 both times), and no _clipwright_* files were left in the folder.

Covers are rendered from the source without the clip's captions since
#107, so with --hook the title was gone too. make_cover now burns a
title-only ASS (build_title_ass: the clip's Hook style and frame, on
screen the whole time, no fade) onto the frame before it's scaled.
build_ass shares the header and hook wrapping with it.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the parts that could make covers worse: the title is burned at the clip's frame size before the scale, so it's the same size relative to the picture as in the clip. The cover frame keeps its clip timestamp, and the event runs from 0 with no fade, so a cover picked at 0.05 s still gets the full title. Without a hook nothing changes, because title_ass is None and the old command runs as-is. Timed it on the 90 s speech test: 0.34 s per cover with or without the title (3 runs each), so libass adds nothing measurable.

One real problem with the temp file:

Comment thread src/clipwright/render.py Outdated
# same trick as render(): a safe bare name in ffmpeg's working folder, so the filter graph
# needs no path escaping. Next to the cover, which is a folder we can write to.
folder = out.resolve().parent
title = folder / f"_clipwright_cover_{out.stem.encode().hex()[:16]}.ass"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out.stem.encode().hex()[:16] is the first 8 bytes of the stem, so it's the same for every clip of a video: speech_clip01.tmp and speech_clip02.tmp both give 7370656563685f63 (speech_c). Within one run the covers are made one after another, so that's fine. But two processes making covers in one folder at the same time (a run into a shared -o folder from the MCP server while the page re-renders a clip of another run there; the new edit lock only covers edits of the same run) would write, read and delete each other's .ass. Then a cover gets the other clip's title, or ffmpeg fails because the file is gone. The name should come from the whole cover path (a short hash of out.resolve()), plus the pid if it has to hold up across processes. render()'s temp_sub has the same [:16], so that's the same problem in older code. Worth an issue.

@A21-devs

A21-devs commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Fixed in the latest commit. The temp title file is now _clipwright_cover_<sha1 of "<resolved cover path>|<pid>">[:16].ass, so two clips of one video, or two processes making the same cover, can't share it.

New test: render_cover with title_ass for speech_clip01.tmp.jpg and speech_clip02.tmp.jpg, with subprocess.run faked to check the named file exists in cwd when ffmpeg would run. It gets two different names and leaves no .ass behind. On the previous commit it fails with the same name twice.

Reran the real CLI on the speech test with -n 2 --hook. Clip 1 (hook "Watch this jump.") has the title on its cover. Clip 2 has no speech early on, so no hook, and its cover is clean. No temp files left. Full suite 733 passed. render()'s temp_sub has the same [:16] naming; I'll open an issue for it since it's older code.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass on 2dde150. The finding is fixed: the key hashes the resolved cover path together with the pid. Different clips get different names, and two processes rendering the same cover (which the edit lock should already prevent) don't share one either. The .ass is written before ffmpeg starts and removed in the finally, as before. The new test checks the file exists in ffmpeg's working folder at run time, not just that two strings differ, and it fails on the previous commit. render()'s temp_sub still has the old naming, which is outside this diff and will be its own issue. Clean.

The name came from the first 8 bytes of the cover's stem, the same for
every clip of a video. It's now a hash of the full cover path and the
pid.
@A21-devs
A21-devs merged commit 41c64f9 into main Dec 4, 2026
4 checks passed
@A21-devs
A21-devs deleted the feat/cover-hook-title branch December 4, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Draw the hook title on the cover

1 participant