Skip to main content

Library for conversion of common timed text formats

Project description

ttconv (Timed Text Conversion)

  $$\     $$\                                             
  $$ |    $$ |                                            
$$$$$$\ $$$$$$\    $$$$$$$\  $$$$$$\  $$$$$$$\ $$\    $$\ 
\_$$  _|\_$$  _|  $$  _____|$$  __$$\ $$  __$$\\$$\  $$  |
  $$ |    $$ |    $$ /      $$ /  $$ |$$ |  $$ |\$$\$$  / 
  $$ |$$\ $$ |$$\ $$ |      $$ |  $$ |$$ |  $$ | \$$$  /  
  \$$$$  |\$$$$  |\$$$$$$$\ \$$$$$$  |$$ |  $$ |  \$  /   
   \____/  \____/  \_______| \______/ \__|  \__|   \_/    

Introduction

ttconv is a library and command line application written in pure Python for converting between timed text formats used in the presentations of captions, subtitles, karaoke, etc.

TTML / IMSC ---                                       ---- IMSC / TTML
                \                                   /
SCC / CTA 608 ------- 0 or more document filters --------- WebVTT
                /        [ Canonical Model ]        \
EBU STL -------                                       ---- SRT
              /                                        \
SRT ---------                                           -- SCC / CTA 608
            /
WebVTT ----

ttconv works by mapping the input document, whatever its format, into an internal canonical model, which is then optionally transformed by document filters, and finally mapped to the format of the output document is derived. The canonical model closely follows the TTML 2 data model, as constrained by the IMSC 1.3 Text Profile specification.

Online demo

https://ttconv.sandflow.com/

Format support

ttconv currently supports the following input and output formats. Additional input and output formats are planned, and suggestions/contributions are welcome.

Input Formats

Output Formats

Quick start

To install the latest version of ttconv, including pre-releases:

pip install --pre ttconv

tt convert -i <input .scc file> -o <output .ttml file>

Documentation

Command line

tt convert [-h] -i INPUT -o OUTPUT [--itype ITYPE] [--otype OTYPE] [--config CONFIG] [--config_file CONFIG_FILE]

  • --itype: TTML | SCC | STL | SRT (extrapolated from the filename, if omitted)
  • --otype: TTML | SCC | SRT | VTT (extrapolated from the filename, if omitted)
  • --filter: specifies by name a filter to be applied to the content
  • --config and --config_file: JSON dictionary where each property specifies (optional) configuration parameters for readers, writers and filters.

Example:

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"}}'

General configuration ("general")

progress_bar

"progress_bar": true | false

A progress bar is displayed if progress_bar is true and log_level is "INFO".

Default: true

log_level

"log_level": "DEBUG" | "INFO" | "WARN" | "ERROR"

Logging verbosity

Default: "INFO"

document_lang

"document_lang": <RFC 5646 language tag>

Overrides the top-level language of the input document.

Example: "document_lang": "es-419"

Default: None

IMSC Writer configuration ("imsc_writer")

time_format

"time_format": "frames" | "clock_time" | "clock_time_with_frames"

Specifies whether the TTML time expressions are in frames (f), HH:MM:SS.mmm or HH:MM:SS:FF

Default: "frames" if "fps" is specified, "clock_time" otherwise

fps

"fps": "<num>/<denom>"

Specifies the ttp:frameRate and ttp:frameRateMultiplier of the output document.

Required when time_format is frames or clock_time_with_frames. No effect otherwise.

Example:

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

profile_signaling

"profile_signaling": "none" | "content_profiles"

Specifies whether and how the output TTML document signals conformance to profile:

  • "none": no profile conformance is signalled
  • "content_profiles": if available, content profile conformance is signaled using the ttp:contentProfiles attribute

Default: "none"

Example:

--config '{ "imsc_writer" : { "profile_signaling" : "content_profiles" } }'

NOTE: Profile conformance signalling is neither required by IMSC not TTML, and is prohibited by some applications, e.g., EBU-TT-D, and some versions of IMSC. Moreover, profile conformance cannot always be determined. As a result, profile conformance should be signaled only when required by the application.

STL Reader configuration ("stl_reader")

disable_fill_line_gap

"disable_fill_line_gap" : true | false

true means that the STL reader does not fill gaps between lines

Default: false

disable_line_padding

"disable_line_padding" : true | false

true means that the STL reader does not add padding at the begining/end of lines

Default: false

program_start_tc

"program_start_tc" : "TCP" | "HH:MM:SS:FF"

Specifies a starting offset, either the TCP field of the GSI block or a user-specified timecode

Default: "00:00:00:00"

font_stack

"font_stack" : [<font-families>](https://www.w3.org/TR/ttml2/#style-value-font-families)

Overrides the font stack

Default: "Verdana, Arial, Tiresias, sansSerif"

max_row_count

"max_row_count" : "MNR" | integer

Specifies a maximum number of rows for open subtitles, either the MNR field of the GSI block or a user-specified value

Default: 23

SRT Writer configuration ("srt_writer")

text_formatting

"text_formatting" : true | false

false means that the SRT writer does not output any text formatting tags

Default: true

SRT Reader configuration ("srt_reader")

extended_tags

"extended_tag" : true | false

If true, the following extended formatting tags are supported: {bold}, <bold>, {b}, {italic}, <italic>, {i}, {underline}, <underline> and {u}.

Default: false

alignment_tags

"alignment_tags" : true | false

If true, ASS/SSA-style alignment tags ({\anN}) are supported, where N is a number from 1-9 corresponding to positions on a numpad:

  • 1-3: bottom (left, center, right)
  • 4-6: middle (left, center, right)
  • 7-9: top (left, center, right)

Default: false

VTT Writer configuration ("vtt_writer")

line_position

"line_position" : true | false

true means that the VTT writer outputs line and line alignment cue settings

Default: false

text_align

"text_align" : true | false

true means that the VTT writer outputs text alignment cue settings

Default: false

cue_id

"cue_id" : true | false

true means that the VTT writer outputs cue identifiers

Default: true

SCC Reader configuration

text_align

"text_align" : "auto" | "left" | "center" | "right"

Specifies the text alignment. "auto" means the reader will use heuristics to determine text alignment.

Default: "auto"

SCC Writer configuration

allow_reflow

"allow_reflow" : true | false

If true, the writer reflows text to fit within the 32 columns.

Default: true

force_popon

"force_popon" : true | false

If true, the writer does not detect roll-up captions and always emits pop-on captions.

Default: false

rollup_lines

"rollup_lines" : 2 | 3 | 4

Specifies the number of lines the writer should use in the roll-up region.

Default: 4

frame_rate

"frame_rate" : "30NDF" | "29.97NDF" | "29.97DF"

If frame_rate is:

  • "30NDF", the output SCC file uses 30 fps non drop frame (NDF) timecode.
  • "29.97NDF", the output SCC file uses 29.97 fps non drop frame (NDF) timecode.
  • "29.97DF", the output SCC file uses 29.97 fps drop frame (DF) timecode.

Default: "2997DF"

start_tc

"start_tc" : null | "HH:MM:SS:FF" | "HH;MM;SS;FF"

If not null, specifies the starting timecode for the SCC file. The timecode must be consistent with the value of the frame_rate parameter.

Default: null

LCD filter configuration ("lcd")

Description

The LCD filter merges regions and removes all text formatting with the exception of color and text alignment.

safe_area

"safe_area" : <integer between 0 and 30>

Specifies the safe area (as a percentage of the height and width of the root container)

Default: 10

color

"color" : <TTML color> | null

If not null, overrides text color. The syntax of TTML color is specified at https://www.w3.org/TR/ttml2/#style-value-color.

Default: null

Examples: "#FFFFFF" (white), "white"

bg_color

"bg_color" : <TTML color>

If not null, overrides the background color. The syntax of TTML color is specified at https://www.w3.org/TR/ttml2/#style-value-color.

Default: null

Examples: "#FF0000" (red), "transparent", "black"

preserve_text_align

"preserve_text_align" : true | false

If true, text alignment is preserved, otherwise text is centered.

Default: false

IMSC 1.1 Text Profile filter configuration ("imsc11text")

Description

The IMSC 1.1 Text Profile filter checks the document against major deviations from the IMSC 1.1 Text Profile. Any deviation results in the filter raising an exception. The absence of deviation results in the IMSC 1.1 Text Profile designator being added to the ttp:contentProfiles parameter.

This filter has no configuration parameters.

NOTE: This filter is not currently intended as substitute for a full IMSC 1.1 validator.

Example

tt convert -i input.vtt -o output.ttml --filter imsc11text

Library

The overall architecture of the library is as follows:

  • Reader modules validate and convert input files into instances of the canonical model (see ttconv.imsc.reader.to_model() for example);
  • Filter modules transform instances of the canonical data model, e.g. all text styling and positioning might be removed from an instance of the canonical model to match the limited capabilities of downstream devices; and
  • Writer modules convert instances of the canonical data model into output files.

Processing shared across multiple reader and writer modules is factored out in common modules whenever possible. For example, several output formats require an instance of the canonical data model to be transformed into a sequence of discrete temporal snapshots – a process called ISD generation.

The library uses the Python logging module to report non-fatal events.

Unit tests illustrate the use of the library, e.g. ReaderWriterTest.test_imsc_1_test_suite at src/test/python/test_imsc_writer.py.

Detailed documentation including reference documents is under doc.

Dependencies

Runtime

Development

The project uses pipenv to manage dependencies.

Development

Setup

Local

  • run pipenv install --dev
  • set the PYTHONPATH environment variable to src/main/python, e.g. export PYTHONPATH=src/main/python
  • pipenv run can then be used

Docker

docker build --rm -f Dockerfile -t ttconv:latest .
docker run -it --rm ttconv:latest bash

Example

From the root directory of the project:

mkdir build
pipenv install --dev
export PYTHONPATH=src/main/python
python src/main/python/ttconv/tt.py convert -i src/test/resources/scc/mix-rows-roll-up.scc -o build/mix-rows-roll-up.ttml

Code coverage

Unit test code coverage is provided by the script at scripts/coverage.sh

Continuous integration

Overview

Automated testing is provided by the script at scripts/ci.sh

Local

Run PYTHONPATH=src/main/python ./scripts/ci.sh

GitHub actions

See .github/workflows/main.yml

Docker

Run docker run -it --rm ttconv:latest /bin/sh scripts/ci.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttconv-1.2.2b2.tar.gz (120.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttconv-1.2.2b2-py3-none-any.whl (181.7 kB view details)

Uploaded Python 3

File details

Details for the file ttconv-1.2.2b2.tar.gz.

File metadata

  • Download URL: ttconv-1.2.2b2.tar.gz
  • Upload date:
  • Size: 120.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ttconv-1.2.2b2.tar.gz
Algorithm Hash digest
SHA256 109228d4cf0c21e5caf435e650813f4bd1d2bafacc54d78cb052448a19deeabe
MD5 527f625a5124874d72cd40be862ad258
BLAKE2b-256 f76c13b2c51eef1c5e0ea2c9ed4891dbe83a36a3c910d8b79153b33758d93e7c

See more details on using hashes here.

File details

Details for the file ttconv-1.2.2b2-py3-none-any.whl.

File metadata

  • Download URL: ttconv-1.2.2b2-py3-none-any.whl
  • Upload date:
  • Size: 181.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ttconv-1.2.2b2-py3-none-any.whl
Algorithm Hash digest
SHA256 efd49db03d58079483737cb9fabf9776b1ba3563b8023e4fdad94d69120c1ad2
MD5 a73984261b63233fdf136ade40cca74b
BLAKE2b-256 3e152b2029eb64ce79e903fe203b4ac2b0bede91e86e48766ed64a1a6fd2ac73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page