Spaces:
Sleeping
Sleeping
| """ | |
| Subtitle Engine. v1 burns in SRT/ASS via ffmpeg's subtitles filter, styled | |
| per the active template. Animated word-highlight/karaoke is a v2 item that | |
| will require switching burn-in to per-frame drawtext or ASS \\k tags. | |
| """ | |
| import os | |
| # style presets keyed by name; templates reference these by `subtitle.style` | |
| STYLE_PRESETS = { | |
| "default": "FontName=Noto Sans,FontSize=20,PrimaryColour=&HFFFFFF&,OutlineColour=&H000000&,BorderStyle=1,Outline=2", | |
| "financial": "FontName=Montserrat,FontSize=22,PrimaryColour=&H00D7FF&,OutlineColour=&H000000&,BorderStyle=1,Outline=2,Bold=1", | |
| } | |
| def build_subtitle_filter(subtitle_path: str, style: str = "default") -> str: | |
| force_style = STYLE_PRESETS.get(style, STYLE_PRESETS["default"]) | |
| ext = os.path.splitext(subtitle_path)[1].lower() | |
| # ffmpeg's `subtitles` filter handles srt/ass/vtt uniformly; path must be | |
| # escaped for the filter graph (colons and backslashes are special). | |
| escaped_path = subtitle_path.replace("\\", "/").replace(":", "\\:") | |
| return f"subtitles='{escaped_path}':force_style='{force_style}'" | |