[PR #1791] [MERGED] fix(scc): Always emit position codes at start of caption (fixes #1776) #2525

Open
opened 2026-01-29 17:22:36 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1791
Author: @cfsmp3
Created: 12/12/2025
Status: Merged
Merged: 12/13/2025
Merged by: @cfsmp3

Base: masterHead: fix/1776-scc-position-codes


📝 Commits (2)

  • 60aa30f fix(scc): Always emit position codes at start of caption (fixes #1776)
  • e412392 fix(rust): Remove unused assignments to fix clippy warnings

📊 Changes

2 files changed (+4 additions, -5 deletions)

View changed files

📝 src/lib_ccx/ccx_encoders_scc.c (+4 -2)
📝 src/rust/src/decoder/tv_screen.rs (+0 -3)

📄 Description

Summary

Fixes #1776 - SCC output was omitting line position instructions (PAC codes) that were correctly included in G608 output.

Problem

The SCC encoder in ccx_encoders_scc.c was initializing tracking variables as:

unsigned char current_row = 14;
unsigned char current_column = 0;

The encoder only writes position codes (PAC) when it detects a change in row/column/font/color:

if (current_row != row ||
    current_column != column ||
    switch_font ||
    switch_color)
{
    // Write position code
}

The bug: When caption content started at row 14 (the last row, "row 15" in 1-indexed terms), column 0, all four conditions evaluated to false:

  • current_row (14) != row (14) → false
  • current_column (0) != column (0) → false
  • No font change → false
  • No color change → false

This caused the position code (e.g., 9470/{1500}) to be completely omitted from the output.

Solution

Initialize current_row and current_column to UINT8_MAX (255), which is an impossible value that will never match any valid row (0-14) or column (0-31). This ensures the position code is always written for the first character of each caption.

// Initialize to impossible values to ensure the first character always
// triggers a position code write (fixes issue #1776)
unsigned char current_row = UINT8_MAX;
unsigned char current_column = UINT8_MAX;

Testing

Tested with a sample MPEG-TS file (ANDE.ts, ~200MB) containing CEA-608 captions.

Before fix (6 instances with missing position codes):

00:04:12:23	 9420 5468 e520 6775 79a7 7320 6120 f761 6ef4 e564 20e6 7567 e9f4 e976 e520 a180 942f 94ae
00:04:46:15	 9420 d3ef 2068 e5a7 7320 ef75 f420 ecef ef6b e96e 6720 e6ef f220 68e9 6dae 942f 94ae
00:08:29:08	 9420 d3f4 e570 68e5 6e20 e361 ecec e564 206d e5ae 942f 94ae
00:09:23:04	 9420 c16e 6420 ece5 f4a7 7320 73e5 f420 f468 e973 2075 70ae 942f 94ae
00:09:26:18	 9420 4f6b 6179 2c20 f468 61f4 a773 206e eff4 2067 efef 64ae 942f 94ae
00:09:54:12	 9420 c1f2 e520 79ef 7520 6775 7973 20f4 68e5 f2e5 20bf 942f 94ae

Note: 9420 is RCL (Resume Caption Loading), immediately followed by text data without any position code.

After fix (position code 9470 now present):

00:04:12:23	 9420 9470 5468 e520 6775 79a7 7320 6120 f761 6ef4 e564 20e6 7567 e9f4 e976 e520 a180 942f 94ae
00:04:46:15	 9420 9470 d3ef 2068 e5a7 7320 ef75 f420 ecef ef6b e96e 6720 e6ef f220 68e9 6dae 942f 94ae
00:08:29:08	 9420 9470 d3f4 e570 68e5 6e20 e361 ecec e564 206d e5ae 942f 94ae
00:09:23:04	 9420 9470 c16e 6420 ece5 f4a7 7320 73e5 f420 f468 e973 2075 70ae 942f 94ae
00:09:26:18	 9420 9470 4f6b 6179 2c20 f468 61f4 a773 206e eff4 2067 efef 64ae 942f 94ae
00:09:54:12	 9420 9470 c1f2 e520 79ef 7520 6775 7973 20f4 68e5 f2e5 20bf 942f 94ae

The 9470 code is the PAC (Preamble Address Code) for row 15, column 0 - exactly what was reported missing in #1776.

Test methodology

  1. Built ccextractor without the fix
  2. Ran: ccextractor ANDE.ts --out=scc -o before_fix.scc
  3. Applied the fix and rebuilt
  4. Ran: ccextractor ANDE.ts --out=scc -o after_fix.scc
  5. Compared outputs with diff before_fix.scc after_fix.scc

Files changed

  • src/lib_ccx/ccx_encoders_scc.c - Changed initialization of current_row and current_column from 14/0 to UINT8_MAX/UINT8_MAX

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1791 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/12/2025 **Status:** ✅ Merged **Merged:** 12/13/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/1776-scc-position-codes` --- ### 📝 Commits (2) - [`60aa30f`](https://github.com/CCExtractor/ccextractor/commit/60aa30fe48a64b11c567d78d5281961cf81205b7) fix(scc): Always emit position codes at start of caption (fixes #1776) - [`e412392`](https://github.com/CCExtractor/ccextractor/commit/e412392925ba5a0b18035cb2d34b7a8055dba5c0) fix(rust): Remove unused assignments to fix clippy warnings ### 📊 Changes **2 files changed** (+4 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/ccx_encoders_scc.c` (+4 -2) 📝 `src/rust/src/decoder/tv_screen.rs` (+0 -3) </details> ### 📄 Description ## Summary Fixes #1776 - SCC output was omitting line position instructions (PAC codes) that were correctly included in G608 output. ## Problem The SCC encoder in `ccx_encoders_scc.c` was initializing tracking variables as: ```c unsigned char current_row = 14; unsigned char current_column = 0; ``` The encoder only writes position codes (PAC) when it detects a change in row/column/font/color: ```c if (current_row != row || current_column != column || switch_font || switch_color) { // Write position code } ``` **The bug:** When caption content started at row 14 (the last row, "row 15" in 1-indexed terms), column 0, all four conditions evaluated to `false`: - `current_row (14) != row (14)` → false - `current_column (0) != column (0)` → false - No font change → false - No color change → false This caused the position code (e.g., `9470/{1500}`) to be completely omitted from the output. ## Solution Initialize `current_row` and `current_column` to `UINT8_MAX` (255), which is an impossible value that will never match any valid row (0-14) or column (0-31). This ensures the position code is always written for the first character of each caption. ```c // Initialize to impossible values to ensure the first character always // triggers a position code write (fixes issue #1776) unsigned char current_row = UINT8_MAX; unsigned char current_column = UINT8_MAX; ``` ## Testing Tested with a sample MPEG-TS file (`ANDE.ts`, ~200MB) containing CEA-608 captions. ### Before fix (6 instances with missing position codes): ``` 00:04:12:23 9420 5468 e520 6775 79a7 7320 6120 f761 6ef4 e564 20e6 7567 e9f4 e976 e520 a180 942f 94ae 00:04:46:15 9420 d3ef 2068 e5a7 7320 ef75 f420 ecef ef6b e96e 6720 e6ef f220 68e9 6dae 942f 94ae 00:08:29:08 9420 d3f4 e570 68e5 6e20 e361 ecec e564 206d e5ae 942f 94ae 00:09:23:04 9420 c16e 6420 ece5 f4a7 7320 73e5 f420 f468 e973 2075 70ae 942f 94ae 00:09:26:18 9420 4f6b 6179 2c20 f468 61f4 a773 206e eff4 2067 efef 64ae 942f 94ae 00:09:54:12 9420 c1f2 e520 79ef 7520 6775 7973 20f4 68e5 f2e5 20bf 942f 94ae ``` Note: `9420` is RCL (Resume Caption Loading), immediately followed by text data without any position code. ### After fix (position code `9470` now present): ``` 00:04:12:23 9420 9470 5468 e520 6775 79a7 7320 6120 f761 6ef4 e564 20e6 7567 e9f4 e976 e520 a180 942f 94ae 00:04:46:15 9420 9470 d3ef 2068 e5a7 7320 ef75 f420 ecef ef6b e96e 6720 e6ef f220 68e9 6dae 942f 94ae 00:08:29:08 9420 9470 d3f4 e570 68e5 6e20 e361 ecec e564 206d e5ae 942f 94ae 00:09:23:04 9420 9470 c16e 6420 ece5 f4a7 7320 73e5 f420 f468 e973 2075 70ae 942f 94ae 00:09:26:18 9420 9470 4f6b 6179 2c20 f468 61f4 a773 206e eff4 2067 efef 64ae 942f 94ae 00:09:54:12 9420 9470 c1f2 e520 79ef 7520 6775 7973 20f4 68e5 f2e5 20bf 942f 94ae ``` The `9470` code is the PAC (Preamble Address Code) for row 15, column 0 - exactly what was reported missing in #1776. ### Test methodology 1. Built ccextractor without the fix 2. Ran: `ccextractor ANDE.ts --out=scc -o before_fix.scc` 3. Applied the fix and rebuilt 4. Ran: `ccextractor ANDE.ts --out=scc -o after_fix.scc` 5. Compared outputs with `diff before_fix.scc after_fix.scc` ## Files changed - `src/lib_ccx/ccx_encoders_scc.c` - Changed initialization of `current_row` and `current_column` from `14`/`0` to `UINT8_MAX`/`UINT8_MAX` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:22:36 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2525