[PR #1858] [MERGED] fix(ts): Skip broken PES packets instead of terminating file processing #2625

Closed
opened 2026-01-29 17:23:08 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

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

Base: masterHead: fix/issue-1455-uk-freeview-dvb


📝 Commits (6)

  • 0fbbc06 fix(hevc): Add HEVC/H.265 caption extraction support
  • 440cd55 fix(hevc): Fix garbled captions by implementing B-frame reordering
  • 87bc1d9 style: Fix clang-format issue in ts_functions.c
  • 9e970fd style: Run cargo fmt on avc/core.rs
  • 1bdd9ab fix(clippy): Suppress dead_code warnings for unused HEVC NAL constants
  • 3e9ed30 fix(ts): Skip broken PES packets instead of terminating file processing

📊 Changes

10 files changed (+376 additions, -119 deletions)

View changed files

📝 src/lib_ccx/avc_functions.c (+80 -33)
📝 src/lib_ccx/avc_functions.h (+1 -0)
📝 src/lib_ccx/ccx_common_constants.h (+2 -1)
📝 src/lib_ccx/general_loop.c (+7 -0)
📝 src/lib_ccx/ts_functions.c (+29 -9)
📝 src/lib_ccx/ts_info.c (+3 -1)
📝 src/rust/src/avc/common_types.rs (+2 -0)
📝 src/rust/src/avc/core.rs (+250 -75)
📝 src/rust/src/common.rs (+1 -0)
📝 src/rust/src/ctorust.rs (+1 -0)

📄 Description

Summary

  • Fixes #1455 - UK Freeview DVB subtitles fail with "Processing ended prematurely"
  • Skip malformed PES packets instead of terminating entire file processing
  • Enables extraction of DVB subtitles from UK Freeview recordings

Problem

UK Freeview DVB recordings from September 2022 onwards would fail at 0% with:

ATTENTION!!!!!!
In switch_to_next_file(): Processing of file.ts ended prematurely 185024 < 20000000

VLC and other players could display the subtitles correctly, but ccextractor would terminate immediately.

Root Cause

When read_video_pes_header() encounters a malformed or truncated PES packet, it returns -1. The calling function copy_capbuf_demux_data() then returned CCX_EOF (-101), which terminated the entire file. This was overly aggressive - a single broken PES packet should be skipped, not terminate the file.

Fix

Changed error handling to skip broken packets and continue:

// Before:
return CCX_EOF;  // terminates file

// After:
return CCX_OK;   // skips packet, continues

Test Results

Metric Before After
Progress 0% (185KB of 20MB) 100%
Error "ended prematurely" None
Subtitles 0 10 extracted correctly

Sample subtitle extracted: "of eight 400 ounce gold bars that were stolen in 1998."

All 299 Rust tests pass.

Test plan

  • Test with UK Freeview sample (ccissue.ts from issue #1455)
  • Verify DVB subtitles are extracted correctly
  • Run Rust test suite (299 tests pass)
  • CI verification

🤖 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/1858 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/20/2025 **Status:** ✅ Merged **Merged:** 12/20/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/issue-1455-uk-freeview-dvb` --- ### 📝 Commits (6) - [`0fbbc06`](https://github.com/CCExtractor/ccextractor/commit/0fbbc06bcfc3ec1242791ccb0bfafc76c9408ce1) fix(hevc): Add HEVC/H.265 caption extraction support - [`440cd55`](https://github.com/CCExtractor/ccextractor/commit/440cd5527f3bf68248368d511227d609b81a3011) fix(hevc): Fix garbled captions by implementing B-frame reordering - [`87bc1d9`](https://github.com/CCExtractor/ccextractor/commit/87bc1d96132d36fb7c6321e2e6627db307437088) style: Fix clang-format issue in ts_functions.c - [`9e970fd`](https://github.com/CCExtractor/ccextractor/commit/9e970fd788842263f68806b0b6848286b31c5196) style: Run cargo fmt on avc/core.rs - [`1bdd9ab`](https://github.com/CCExtractor/ccextractor/commit/1bdd9abd356f9ae9dcf9c18a52722630580af743) fix(clippy): Suppress dead_code warnings for unused HEVC NAL constants - [`3e9ed30`](https://github.com/CCExtractor/ccextractor/commit/3e9ed3043b7e529196c5eaa0a5940e5119286055) fix(ts): Skip broken PES packets instead of terminating file processing ### 📊 Changes **10 files changed** (+376 additions, -119 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/avc_functions.c` (+80 -33) 📝 `src/lib_ccx/avc_functions.h` (+1 -0) 📝 `src/lib_ccx/ccx_common_constants.h` (+2 -1) 📝 `src/lib_ccx/general_loop.c` (+7 -0) 📝 `src/lib_ccx/ts_functions.c` (+29 -9) 📝 `src/lib_ccx/ts_info.c` (+3 -1) 📝 `src/rust/src/avc/common_types.rs` (+2 -0) 📝 `src/rust/src/avc/core.rs` (+250 -75) 📝 `src/rust/src/common.rs` (+1 -0) 📝 `src/rust/src/ctorust.rs` (+1 -0) </details> ### 📄 Description ## Summary - Fixes #1455 - UK Freeview DVB subtitles fail with "Processing ended prematurely" - Skip malformed PES packets instead of terminating entire file processing - Enables extraction of DVB subtitles from UK Freeview recordings ## Problem UK Freeview DVB recordings from September 2022 onwards would fail at 0% with: ``` ATTENTION!!!!!! In switch_to_next_file(): Processing of file.ts ended prematurely 185024 < 20000000 ``` VLC and other players could display the subtitles correctly, but ccextractor would terminate immediately. ## Root Cause When `read_video_pes_header()` encounters a malformed or truncated PES packet, it returns -1. The calling function `copy_capbuf_demux_data()` then returned `CCX_EOF` (-101), which terminated the entire file. This was overly aggressive - a single broken PES packet should be skipped, not terminate the file. ## Fix Changed error handling to skip broken packets and continue: ```c // Before: return CCX_EOF; // terminates file // After: return CCX_OK; // skips packet, continues ``` ## Test Results | Metric | Before | After | |--------|--------|-------| | Progress | 0% (185KB of 20MB) | 100% | | Error | "ended prematurely" | None | | Subtitles | 0 | 10 extracted correctly | Sample subtitle extracted: *"of eight 400 ounce gold bars that were stolen in 1998."* All 299 Rust tests pass. ## Test plan - [x] Test with UK Freeview sample (ccissue.ts from issue #1455) - [x] Verify DVB subtitles are extracted correctly - [x] Run Rust test suite (299 tests pass) - [ ] CI verification 🤖 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:23:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2625