PIL-based word-highlighted text frame renderer (plain-background fallback).
Source: screencastgen/highlight_renderer.py
Renders individual video frames showing text with the currently-spoken word highlighted on a plain dark background. Uses PIL/Pillow for drawing with system fonts and handles word wrapping, scrolling, and per-word color highlighting.
This is the fallback renderer used when the input is not a PDF or PyMuPDF is not installed. For PDF inputs, Page Renderer is preferred — it highlights words on the actual PDF page images.
HighlightRendererHighlightRenderer(width=1280, height=720, font_size=32)
| Method | Description |
|---|---|
layout_words(words) -> List[dict] |
Computes pixel positions for each word. Accepts List[str] or List[WordTiming]. |
render_frame(layout, active_index, scroll_offset) -> Image |
Renders a single frame with the active word highlighted |
compute_scroll_offset(layout, active_index) -> int |
Calculates vertical scroll position to keep active word visible |
get_active_word_index(words, time) -> Optional[int] |
Finds which word is active at a given timestamp |
Highlight Renderer
├── Pillow (PIL) (deferred import)
├── Types (WordTiming for timing data)
└──▶ consumed by Highlight Pipeline
└──▶ consumed by Video Composer
List[WordTiming]
│
▼ layout_words()
List[dict] positions (x, y per word)
│
▼ render_frame() (called per video frame)
PIL Image
│
▼ passed to Video Composer
layout_words() also accepts List[str], but the current video pipeline passes AlignedChunk.words directly so both renderers share the same interface.
WordTiming dataclassDEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT, DEFAULT_VIDEO_FPS