Skip to content

Conversation

@sannies
Copy link

@sannies sannies commented Jan 8, 2026

This pull request introduces a new image-based subtitle writer for FFmpeg filtergraphs, improves the handling of image-based subtitle rendering, and refactors palette and color management for better clarity and extensibility. It also adds comprehensive tests for the new filtergraph writer. The most significant changes are grouped below.

New FFmpeg Filtergraph Writer:

  • Added a new FiltergraphWriter class in pycaption/filtergraph.py that generates PNG subtitle images and an FFmpeg filtergraph for overlaying subtitles as transparent video. This writer outputs a ZIP file containing the images and the filtergraph script, supporting custom output directories and video resolutions.
  • Updated pycaption/__init__.py to expose FiltergraphWriter in the public API. [1] [2]

Image-based Subtitle Rendering Refactor:

  • Refactored SubtitleImageBasedWriter in pycaption/subtitler_image_based.py to use RGBA images with transparent backgrounds by default, and moved palette/color management to subclasses. Now, each subclass is responsible for converting RGBA images to their required palette and format. [1] [2]
  • Simplified the drawing logic to use new fontColor and borderColor attributes for RGBA rendering, replacing the previous palette-based approach.

Palette and Format Handling for Subclasses:

  • Updated ScenaristDVDWriter and TTMLBackgroundWriter to define their own palettes and conversion logic, ensuring correct color quantization and transparency handling for their respective formats. [1] [2] [3]

Testing:

  • Added tests/test_filtergraph.py with extensive tests for the FiltergraphWriter, covering ZIP output, filtergraph structure, custom directories, overlay chaining, duration calculation, and resolution handling.

Other Minor Updates:

  • Added missing import for PIL.Image in pycaption/scenarist.py and minor test import tweaks. [1] [2]

@sannies sannies merged commit 64110a3 into main Jan 12, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants