Templates are the most convenient way to create reusable and shareable styles in pycaps. A template is a self-contained directory that bundles together configuration, styles, and resources.
A pycaps template is simply a folder that contains:
- A
pycaps.template.jsonconfiguration file. - A
style.cssstylesheet. - An optional
resourcesfolder for assets like fonts or images.
A typical template looks like this:
my-awesome-template/
├── pycaps.template.json # Main configuration for the pipeline
├── style.css # All CSS styles for the subtitles
└── resources/ # Optional folder for assets
└── my-font.ttf
The paths inside pycaps.template.json (like for css and resources) should be relative to the file itself.
You can use a template from both the CLI and Python.
Use the --template option. pycaps will look for a template with that name first in your current working directory (a local template) and then in its built-in templates.
pycaps render --input my_video.mp4 --template my-awesome-templateUse the TemplateLoader to initialize a pipeline builder directly from a template.
from pycaps import TemplateLoader
# Load a builder from a template named 'my-awesome-template'
builder = TemplateLoader("my-awesome-template").with_input_video("my_video.mp4").load(False)
# You can further customize the builder here if needed
builder.with_video_quality("high")
# Build and run
pipeline = builder.build()
pipeline.run()The easiest way to create a new template is with the CLI.
Run the template create command. This will copy an existing template (by default, the default built-in one) to a new folder.
# Creates a new folder named 'my-new-style' in the current directory
pycaps template create --name my-new-styleThis gives you a solid starting point with a working pycaps.template.json and style.css.
Now, you can edit the files inside the my-new-style directory:
- Edit
style.css: Change the fonts, colors, sizes, and backgrounds to match your brand. - Add resources: Place any custom fonts or images into the
resources/folder and reference them in your CSS. - Edit
pycaps.template.json: Modify the animations, effects, layout, and other pipeline settings. For a full list of options, see the Configuration Reference.
Once customized, your template is ready to be used with the --template my-new-style flag.