SubTextHighlight
SubTextHighlight is a comprehensive Python package for generating, formatting, and styling subtitles. It focuses on user-friendliness while providing high-end visual features for video editing and automation.
Below is a clip from 1984, styled using SubTextHighlight as an example:
https://github.com/user-attachments/assets/0a6f01fd-72bb-4dc5-a9e1-9a0d14330490
Table of Contents
🛠 Requirements
- FFmpeg: Must be installed and added to your system PATH.
📦 Installation
# Via pip
pip install SubTextHighlight
# Via GitHub (latest)
pip install git+https://github.com/kalterBebapKacke/SubTextHighlight@main
🚀 How to Use
1. SubtitleConfig — The Single Entry Point
The API has been consolidated into a single configuration class: SubtitleConfig. Instead of instantiating and passing multiple separate argument classes, you now configure everything in one place and call .render() followed by .save().
from SubTextHighlight import SubtitleConfig, StyleConfig, preset_youtube, Formatters
input = './tests/input/plain_video.mp4' # set the input to a video, which will generate the subtitles for me
output = './media/output_video.mp4' # set the output to a .mp4, so that the subtitles will be burned in
conf = SubtitleConfig(
input, output,
subtitle_type=Formatters.sentence,
fill_sub_times=False,
alignment = 2,
highlight_style=StyleConfig(primarycolor='00AAFF'),
highlight_word_max=0,
highlight_as_borders=True,
fade=(50, 50),
)
conf.render()
conf.save()
# Or use the youtube preset, that gives a similar result
preset_youtube(input, output)
render() processes the input and generates the subtitle data. save() writes the output and returns the output path (or None if no file was written).
Full Parameter Reference
Input / Output
| Parameter | Type | Default | Description |
|---|---|---|---|
input |
str | dict | list[dict] | WhisperResult |
required | Path to a video/audio/srt file, a raw transcript dict, or a stable-whisper result. |
output |
str | None |
required | Output path (.ass, .mp4). Pass None to return the pysubs2.SSAFile object directly from save(). |
input_video |
str | None |
None |
Separate video file path, if the subtitle input differs from the video to burn into. |
Subtitle Layout
| Parameter | Type | Default | Description |
|---|---|---|---|
subtitle_type |
type[BaseFormatter] |
Formatters.joined |
Formatters.one_word, Formatters.joined (group by word_max), or Formatters.sentence (split at sentence ends). |
word_max |
int |
11 |
Maximum words per subtitle line when using 'join' mode. |
add_time |
float |
0.0 |
Time offset (seconds) added to all subtitle timestamps. |
fill_sub_times |
bool |
True |
Automatically fill gaps between subtitle lines. |
The layout and timing of the generated subtitles is controlled by the selected formatter, which determines the subtitle_type parameter. It is imported via from SubTextHighlight import Formatters. The available options are:
2. StyleConfig — Text Appearance
Visual styling is now handled by StyleConfig objects. Pass one to subtitle_style for the main text and optionally another to highlight_style for highlighted words.
from SubTextHighlight import StyleConfig
main_style = StyleConfig(
fontname='Arial Rounded MT Bold',
fontsize=28,
primarycolor='FFFFFF',
borderstyle=3,
)
Font & Text
| Attribute | Type | Default | Description |
|---|---|---|---|
fontname |
str |
'Arial' |
Font family (must be installed on the system). |
fontsize |
float |
24 |
Font size in points. |
bold |
bool |
True |
Bold text. |
italic |
bool |
False |
Italic text. |
underline |
bool |
False |
Underlined text. |
Colors
Accepts pysubs2.Color objects or HEX strings (e.g. 'FF0000').
| Attribute | Default | Description |
|---|---|---|
primarycolor |
White | Main text fill color. |
secondarycolor |
Black | Used for karaoke/transitional effects. |
backcolor |
Black | Background color for boxed styles. |
outlinecolor |
Black | Text outline color. |
Layout & Visuals
| Attribute | Default | Description |
|---|---|---|
outline |
1 |
Outline thickness in pixels. |
shadow |
0 |
Drop shadow offset in pixels. |
alignment |
5 |
Numpad positioning (2 = bottom center, 5 = center). |
borderstyle |
1 |
1: Outline only, 3: Opaque box. |
spacing |
0.75 |
Line spacing multiplier. |
3. Highlight Options
| Parameter | Type | Default | Description |
|---|---|---|---|
highlight_style |
StyleConfig | None |
None |
Style for highlighted words. Attributes left at None inherit from subtitle_style. |
highlight_word_max |
int | None |
None |
Number of words highlighted at once. 0 = single word. None disables highlighting. |
highlight_as_borders |
bool |
False |
Use the rounded border effect as the highlight indicator instead of a text color change. Cannot be combined with appear=True. |
4. Effects & Borders
Fade & Appear
| Parameter | Type | Default | Description |
|---|---|---|---|
fade |
tuple[float, float] |
(0.0, 0.0) |
(fade_in, fade_out) duration in milliseconds. |
appear |
bool |
False |
Words appear cumulatively rather than replacing each other. |
Rounded Borders
Set rounded_border=True to enable custom background box rendering. The border parameters below control its appearance.
| Parameter | Type | Default | Description |
|---|---|---|---|
rounded_border |
bool |
False |
Enable rounded background border rendering. |
offset |
int |
6 |
Padding between text and border edge. |
radius |
int |
6 |
Corner radius. |
transformy |
int |
1 |
Vertical shift/correction for the border. |
height_scaling |
float |
1.2 |
Border height multiplier relative to text height. |
color |
pysubs2.Color | None |
None |
Border fill color. Defaults to white if None. |
Docker / Rendering Backend
These parameters control the containerised rendering pipeline used for advanced border effects.
| Parameter | Type | Default | Description |
|---|---|---|---|
fonts_path |
list | str | None |
None |
Path(s) to custom font directories to mount. |
packages |
list[str] | None |
None |
Extra system packages to install inside the container. |
container_run_func |
callable | None |
None |
Custom function for containerised rendering. |
force_install |
bool |
False |
Force reinstallation of container dependencies. |
docker_verbose |
bool |
False |
Print verbose Docker output. |
docker_traceback |
bool |
False |
Show full tracebacks from inside the container. |
5. Whisper / Transcription
When input is a video or audio file, SubTextHighlight will transcribe it automatically using stable-whisper.
| Parameter | Type | Default | Description |
|---|---|---|---|
whisper_model |
str |
'medium.en' |
Whisper model name (e.g. 'base', 'large-v3'). |
whisper_device |
str |
'cpu' |
Device for inference ('cpu' or 'cuda'). |
whisper_refine |
bool |
False |
Refine word-level timestamps (English only). |
6. Shortcuts & Presets
The presets module contains pre-configured styles and settings for common use cases. For example, preset_youtube() applies a popular YouTube-style subtitle format with a single function call.
The presets here include:
preset_youtube— A modern, clean style inspired by YouTube's default captions.preset_tiktok— A clean style with a rounded border, inspired by TikTok's captions.fast— Create a subtitle file/render it with minimal processing and default styling, for quick results.fast_subtitle_file— Generate a subtitle file with minimal processing and default styling, without rendering a video, just returning thepysubs2.SSA_Fileobject.fast_highlight— Create a simple subtitle file or video with simple word-level highlighting, without advanced effects or styling.
Feedback & Contributions
Feedback is always welcome! Please feel free to open issues on GitHub. I am not finished with this project and there are many features I want to add, so if you have any suggestions or want to contribute, please do not hesitate to reach out.
Metadata
Release files for SubTextHighlight 3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subtexthighlight-3.0.tar.gz | 42.1 kB | Without provenance | Details for subtexthighlight-3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subtexthighlight-3.0-py3-none-any.whl | Python 3 | none | any | Details for subtexthighlight-3.0-py3-none-any.whl |
Total release size: 89.1 kB
Release files / subtexthighlight-3.0.tar.gz
| Download URL | subtexthighlight-3.0.tar.gz |
|---|---|
| Size | 42.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ac63f5fdf238daf490aa292810cd6265c8f3edac39aaf28417581c8de31ecc2
|
|
BLAKE2b-256 checksum How to use checksums |
1bbfb60f7c83c510be2d7677a2a7c0bb373cae92288a0f743daa55e4ac67c0c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / subtexthighlight-3.0-py3-none-any.whl
| Download URL | subtexthighlight-3.0-py3-none-any.whl |
|---|---|
| Size | 47.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11579e842b08a9f3f2339e6f3ac558ce34b55777b7062afc93209bd45dab52a3
|
|
BLAKE2b-256 checksum How to use checksums |
a36c64a6d86113193b74327b07fefc9c00607fa2147f1032322c418626f7077d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for SubTextHighlight 3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.