Skip to content

Code Lab

AutoClip: What an SRT Cue Can Tell You About Word Timing

By Miles Park·
AutoClip project import screen from GitHub

CODE LAB · PROJECT SPOTLIGHT

AutoClip Python · MIT

Follow the editing workflow from an SRT cue to word timing.

Project preview · zhouxiaoka/autoclip

AutoClip can use an existing SRT file when you import a video. That gives it the cue intervals a producer has already checked. The word-level editor still needs to decide where each word falls inside a cue. The Python implementation can use matching word timings from a separate alignment file or estimate how to divide the original interval.

AutoClip Studio shows the clip preview and export controls including a subtitle checkbox
AutoClip’s published Studio screenshot shows the editing and export controls. The subtitle checkbox includes original subtitles in the rendered output in the pictured version. Creator’s screenshot · SRT import guide.

Where the cue becomes a list of words

An SRT cue generally specifies a start time, end time and text. AutoClip splits the text at whitespace and selected punctuation. It divides the cue duration by the number of resulting tokens and assigns each an equal interval. The segment retains the cue boundaries and labels this fallback as estimated. Elsewhere in the same file, aligned timings can replace that estimate when the sidecar matches the cue text and rounded time bounds.

zhouxiaoka/autoclipPython · source excerpt
PY subtitle_processor.py
        total_duration = end_time - start_time        words_count = len(word_parts)                # 简单的时间分配策略:平均分配        word_duration = total_duration / words_count                words = []        for i, word_text in enumerate(word_parts):            word_start = start_time + (i * word_duration)            word_end = word_start + word_duration                        words.append({                'id': str(uuid.uuid4()),                'text': word_text,                'startTime': word_start,                'endTime': word_end            })
Lines 116–132 · commit 559f019View original on GitHub ↗

Reproduce the estimate on a three-second cue

We isolated the constructor and word-timing method from the pinned module and supplied the interval 12.0–15.0 seconds and the text Mark the cut.. In an AutoClip development environment, import SubtitleProcessor from backend.utils.subtitle_processor and run the example below.

processor = SubtitleProcessor()
words = processor._split_text_to_words("Mark the cut.", 12.0, 15.0)
for word in words:
    print(f"{word['text']}: {word['startTime']:.1f}–{word['endTime']:.1f} s")

Observed output

Mark: 12.0–13.0 s
the: 13.0–14.0 s
cut.: 14.0–15.0 s

All three spans are one second long. The period stays attached to the last token because the split pattern in this revision omits the ASCII full stop. If the speaker pauses after the first word, the cue boundaries alone cannot locate that pause. This test exercised the upstream estimate on text. An end-to-end render or speech recognition run would measure different behavior.

Check the cue and the highlight separately

First compare the clip against the original SRT to check where each complete caption appears and disappears. Then replay the words around a pause. If the sentence is correctly placed but individual highlights lead or lag the speech, inspect the timing source before changing the SRT. Adjusting the cue boundaries may move a correctly placed caption without improving its internal timing.

Code excerpt © 2024 AutoClip Team. MIT license · Pinned source · Mindung’s project roundup · Related Code Lab article on frame boundaries.

Join the discussion

Your email address will not be published. Required fields are marked *