Overview
The subtitle system automatically generates styled captions from transcription segments and burns them directly into the video. Subtitles are synchronized with audio timing and positioned for optimal mobile viewing.How It Works
Theadd_subtitles_to_video function in Components/Subtitles.py:4 processes transcription segments and overlays them on the video:
Transcription Filtering
Filters transcription segments to match the video timeframe (important for cropped clips).
Text Clip Creation
Creates styled TextClip objects for each transcription segment with timing information.
Function Signature
Components/Subtitles.py
Path to the input video file (typically the cropped video).
Path where the final video with subtitles will be saved.
List of
[text, start, end] tuples from transcribeAudio function. Each tuple contains the text content and start/end timestamps in seconds.Start time offset in seconds. Used when the video has been cropped to adjust subtitle timing.
Transcription Filtering
Subtitles are filtered to match the video duration:Components/Subtitles.py:17-28
Time Adjustment: When a 2-minute clip is extracted from a longer video,
video_start_time ensures subtitle timing matches the cropped segment.Subtitle Styling
Font Configuration
Subtitles use the Franklin Gothic font family:Components/Subtitles.py:56
Dynamic Font Sizing
Font size scales proportionally to video height:Components/Subtitles.py:39-41
| Video Height | Font Size | Calculation |
|---|---|---|
| 1080p | 70px | 1080 × 0.065 |
| 720p | 47px | 720 × 0.065 |
| 480p | 31px | 480 × 0.065 |
Color and Stroke
The subtitle style uses bright blue text with black outline:Components/Subtitles.py:50-56
Text fill color in hex format.
#2699ff is a bright blue that stands out on most backgrounds.Outline color around the text. Black provides maximum contrast.
Outline thickness in pixels. 2px provides good readability without being too bold.
Text rendering method.
caption enables word wrapping for long text.Text Wrapping
Subtitles automatically wrap to fit the video width:Components/Subtitles.py:58
The 100-pixel reduction (50px margin on each side) prevents subtitle text from touching the screen edges on mobile devices.
Positioning
Subtitles are positioned at the bottom center of the video:Components/Subtitles.py:61-62
Horizontal alignment.
center ensures text is centered regardless of width.Vertical position in pixels. Positioned 100px from the bottom of the video.
Timing Synchronization
Each subtitle clip is precisely timed to match the transcription:Components/Subtitles.py:63-64
Start time in seconds when the subtitle should appear.
Duration in seconds how long the subtitle should remain visible.
Example Timing
Video Composition
All subtitle clips are composited onto the base video:Components/Subtitles.py:69-70
Layering Order: The base video is the first layer, with all text clips rendered on top in order.
Output Encoding
The final video is encoded with high-quality settings:Components/Subtitles.py:73-80
H.264 video codec for wide compatibility across platforms.
AAC audio codec (industry standard for mobile platforms).
Matches source video frame rate to prevent timing issues.
Encoding speed preset. Options:
ultrafast, fast, medium, slow, veryslow. Slower presets provide better compression.Target video bitrate. 3000k (3 Mbps) provides high quality for 1080p vertical video.
Error Handling
No Transcriptions
If no transcriptions match the video timeframe:Components/Subtitles.py:30-34
Empty Text Handling
Components/Subtitles.py:45-47
Customizing Subtitle Style
Change Font and Size
Change Font and Size
Edit
Components/Subtitles.py:52-56:Modify Colors
Modify Colors
Edit
Components/Subtitles.py:53-55:Change Position
Change Position
Edit
Components/Subtitles.py:62:Adjust Margins
Adjust Margins
Edit
Components/Subtitles.py:58,62:Performance
- Processing Speed: ~0.5-2× realtime (depends on video length and subtitle count)
- Memory Usage: ~500MB-2GB (depends on video resolution and duration)
- Rendering Time:
- 1-minute 1080p video: ~30-60 seconds
- 2-minute 720p video: ~20-40 seconds
