Skip to content

Fix SCC captions out of order when short text followed by longer text#363

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-scc-captions-order
Draft

Fix SCC captions out of order when short text followed by longer text#363
Copilot wants to merge 3 commits intomainfrom
copilot/fix-scc-captions-order

Conversation

Copy link

Copilot AI commented Mar 4, 2026

SCCWriter PASS 2 buffer time calculations push each caption's start time back proportional to its code length. When a short caption is followed by a longer one with close start times, the longer caption's adjusted start can precede the shorter caption's — producing out-of-order SCC timestamps.

00:00:02:05  "you know,"
00:00:01:15  "the way he kind of looked at me."  ← before previous caption

Changes

  • Adjust first caption's start time: The if index == 0: continue skipped both the previous-caption comparison (correct) and the codes[index] update (bug). Restructured to always apply the buffer offset.
  • Clamp to maintain ordering: After computing buffer-adjusted code_start, clamp it to max(code_start, previous_start) so timestamps never go backwards.
# Before
if index == 0:
    continue
codes[index] = (code, code_start, end)

# After
if index > 0:
    if code_start < previous_start:
        code_start = previous_start
codes[index] = (code, code_start, end)

Test

Added test_scc_captions_are_in_order_when_short_text_followed_by_long reproducing the exact scenario from the issue.

Original prompt

This section details on the original issue you should resolve

<issue_title>SCC captions out of order</issue_title>
<issue_description>Issue

In certain scenarios due to buffering calculations, SCC caption output is no longer in order. This manifests when short caption text is followed by longer caption text.
Example

VTT Source

WEBVTT

0
00:00:02.200 --> 00:00:02.359
you know,

1
00:00:02.400 --> 00:00:03.760
the way he kind of looked at me.

2
00:00:04.700 --> 00:00:05.169
And I said,

3
00:00:05.210 --> 00:00:05.520
oh

SCC Output

Scenarist_SCC V1.0

00:00:02:05 94ae 94ae 9420 9420 9470 9470 79ef 7520 6b6e eff7 2c80 942c 942c 942f 942f

00:00:01:15 94ae 94ae 9420 9420 9470 9470 f468 e520 f761 7920 68e5 206b e96e 6420 efe6 20ec efef 6be5 6420 61f4 206d e5ae 942c 942c 942f 942f

00:00:03:22 942c 942c

00:00:04:04 94ae 94ae 9420 9420 9470 9470 c16e 6420 4920 7361 e964 2c80 942c 942c 942f 942f

00:00:04:25 94ae 94ae 9420 9420 9470 9470 ef68 942c 942c 942f 942f

00:00:05:15 942c 942c
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 4, 2026 09:38
In PASS 2 of SCCWriter.write(), buffer time calculations could push
a longer caption's adjusted start time before the previous shorter
caption's start time. Two fixes applied:

1. Also adjust the first caption's start time for buffering (was
   skipped due to early `continue`)
2. Clamp each caption's adjusted start time to be at least as late
   as the previous caption's adjusted start time

Co-authored-by: lorandvarga <7048551+lorandvarga@users.noreply.github.com>
…omment

Co-authored-by: lorandvarga <7048551+lorandvarga@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SCC captions output order issue Fix SCC captions out of order when short text followed by longer text Mar 4, 2026
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.

SCC captions out of order

2 participants