Skip to content

Commit 96cf63c

Browse files
authored
Add support for document filters
#417
1 parent 3bc783e commit 96cf63c

29 files changed

+1104
-173
lines changed

README.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,15 @@ tt convert -i <input .scc file> -o <output .ttml file>
6969

7070
* `--itype`: `TTML` | `SCC` | `STL` | `SRT` (extrapolated from the filename, if omitted)
7171
* `--otype`: `TTML` | `SRT` | `VTT` (extrapolated from the filename, if omitted)
72-
* `--config` and `--config_file`: JSON dictionaries with the following members:
73-
* `"general": JSON object`: General configuration options (see below)
74-
* `"imsc_writer": JSON object`: IMSC Writer configuration options (see below)
75-
* `"stl_reader": JSON object`: STL Reader configuration options (see below)
76-
* `"vtt_writer": JSON object`: WebVTT Writer configuration options (see below)
77-
* `"srt_writer": JSON object`: SRT Writer configuration options (see below)
78-
* `"scc_reader": JSON object`: SCC Reader configuration options (see below)
72+
* `--filter`: specifies by name a filter to be applied to the content
73+
* `--config` and `--config_file`: JSON dictionary where each property specifies
74+
(optional) configuration parameters for readers, writers and filters.
7975

8076
Example:
8177

82-
`tt convert -i <.scc file> -o <.ttml file> --itype SCC --otype TTML --config '{"general": {"progress_bar":false, "log_level":"WARN"}}'`
78+
`tt convert -i <.scc file> -o <.ttml file> --itype SCC --otype TTML --filter lcd --config '{"general": {"progress_bar":false, "log_level":"WARN"}, "lcd": {"bg_color": "transparent", "color": "#FF0000"}}'`
8379

84-
### General configuration
80+
### General configuration (`"general"`)
8581

8682
#### progress_bar
8783

@@ -109,7 +105,7 @@ Example: `"document_lang": "es-419"`
109105

110106
Default: `None`
111107

112-
### IMSC Writer configuration
108+
### IMSC Writer configuration (`"imsc_writer"`)
113109

114110
### time_format
115111

@@ -131,7 +127,7 @@ Example:
131127

132128
`--config '{"general": {"progress_bar":false, "log_level":"WARN"}, "imsc_writer": {"time_format":"clock_time_with_frames", "fps": "25/1"}}'`
133129

134-
### STL Reader configuration
130+
### STL Reader configuration (`"stl_reader"`)
135131

136132
#### disable_fill_line_gap
137133

@@ -173,7 +169,7 @@ Specifies a maximum number of rows for open subtitles, either the MNR field of t
173169

174170
Default: `23`
175171

176-
### SRT Writer configuration
172+
### SRT Writer configuration (`"srt_writer"`)
177173

178174
#### text_formatting
179175

@@ -183,7 +179,7 @@ Default: `23`
183179

184180
Default: `true`
185181

186-
### VTT Writer configuration
182+
### VTT Writer configuration (`"vtt_writer"`)
187183

188184
#### line_position
189185

@@ -220,7 +216,52 @@ text alignment.
220216

221217
Default: `"auto"`
222218

223-
### Library
219+
### LCD filter configuration (`"lcd"`)
220+
221+
#### Description
222+
223+
The LCD filter merges regions and removes all text formatting with the exception
224+
of color and text alignment.
225+
226+
#### safe_area
227+
228+
`"safe_area" : <integer between 0 and 30>`
229+
230+
Specifies the safe area (as a percentage of the height and width of the root container)
231+
232+
Default: `10`
233+
234+
#### color
235+
236+
`"color" : <TTML color> | null`
237+
238+
If not `null`, overrides text color. The syntax of `TTML color` is
239+
specified at <https://www.w3.org/TR/ttml2/#style-value-color>.
240+
241+
Default: `null`
242+
243+
Examples: `"#FFFFFF"` (white), `"white"`
244+
245+
#### bg_color
246+
247+
`"bg_color" : <TTML color>`
248+
249+
If not `null`, overrides the background color. The syntax of `TTML color` is
250+
specified at <https://www.w3.org/TR/ttml2/#style-value-color>.
251+
252+
Default: `null`
253+
254+
Examples: `"#FF0000"` (red), `"transparent"`, `"black"`
255+
256+
#### preserve_text_align
257+
258+
`"preserve_text_align" : true | false`
259+
260+
If `true`, text alignment is preserved, otherwise text is centered.
261+
262+
Default: `false`
263+
264+
## Library
224265

225266
The overall architecture of the library is as follows:
226267

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='ttconv',
13-
version='1.0.8',
13+
version='1.1.0-beta.1',
1414
description='Library for conversion of common timed text formats',
1515
long_description=long_description,
1616
long_description_content_type='text/markdown',
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +0,0 @@
1-
#!/usr/bin/env python
2-
# -*- coding: UTF-8 -*-
3-
4-
# Copyright (c) 2020, Sandflow Consulting LLC
5-
#
6-
# Redistribution and use in source and binary forms, with or without
7-
# modification, are permitted provided that the following conditions are met:
8-
#
9-
# 1. Redistributions of source code must retain the above copyright notice, this
10-
# list of conditions and the following disclaimer.
11-
# 2. Redistributions in binary form must reproduce the above copyright notice,
12-
# this list of conditions and the following disclaimer in the documentation
13-
# and/or other materials provided with the distribution.
14-
#
15-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16-
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17-
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19-
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20-
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22-
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25-
26-
"""Data model filter"""
27-
28-
from ttconv.isd import ISD
29-
30-
31-
class Filter:
32-
"""Abstract base class for filters"""
33-
34-
def process(self, isd: ISD):
35-
"""Process the specified ISD and returns it."""
36-
raise NotImplementedError
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
# Copyright (c) 2023, Sandflow Consulting LLC
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this
10+
# list of conditions and the following disclaimer.
11+
# 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
26+
"""Collects document instance filters"""
27+
28+
import importlib
29+
import pkgutil
30+
import os.path
31+
import sys
32+
33+
# registers all document instance filters
34+
35+
for importer, package_name, _ in pkgutil.iter_modules([os.path.dirname(__file__)]):
36+
full_name = f"{__name__}.{package_name}"
37+
importlib.import_module(full_name)

0 commit comments

Comments
 (0)