mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-08 18:06:30 +00:00
[PR #1852] [MERGED] fix(hevc): Add HEVC/H.265 caption extraction support with B-frame reordering #2614
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/CCExtractor/ccextractor/pull/1852
Author: @cfsmp3
Created: 12/19/2025
Status: ✅ Merged
Merged: 12/20/2025
Merged by: @cfsmp3
Base:
master← Head:fix/issue-1690-hevc-caption-extraction📝 Commits (5)
0fbbc06fix(hevc): Add HEVC/H.265 caption extraction support440cd55fix(hevc): Fix garbled captions by implementing B-frame reordering87bc1d9style: Fix clang-format issue in ts_functions.c9e970fdstyle: Run cargo fmt on avc/core.rs1bdd9abfix(clippy): Suppress dead_code warnings for unused HEVC NAL constants📊 Changes
10 files changed (+371 additions, -117 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(+24 -7)📝
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 #1690 - Captions fail to extract on HEVC video stream
Fixes #1639 - CCextractor not finding 608 captions in ATSC3.0 TS (garbled output)
HEVC (H.265) video streams with embedded EIA-608/708 captions weren't being extracted correctly. VLC/MPV could display them, but CCExtractor either failed to find them or produced garbled output.
Root Causes Fixed
Issue #1639 Deep Dive - B-Frame Reordering
The ATSC 3.0 sample from issue #1639 exposed a critical problem: HEVC uses B-frames extensively, and CC data embedded in SEI NAL units was being processed in decode order instead of presentation order.
Evidence from the sample file:
" BOTH OF MIOEDCRE WNDOHE TRESTH.TCL WWEILATE SEWHNSAP HPE IGAN ME...""COME BOTH OF MEDIOCRE DOWN THE STRETCH. WE WILL SEE WHAT HAPPENS IN GAME NUMBER ONE TONIGHT"The same characters were present but scrambled due to B-frame reordering.
Before fix:
After fix:
Changes
C Code:
ts_info.c: Include HEVC (0x24) in video stream detectionts_functions.c: AddCCX_HEVCbuffer type handling, HEVC NAL type detection for streams without PAT/PMT (VPS=32, SPS=33, PPS=34, PREFIX_SEI=39, SUFFIX_SEI=40, IDR=19,20, CRA=21)ccx_common_constants.h: AddCCX_HEVC = 11buffer typegeneral_loop.c: HandleCCX_HEVCand setis_hevcflagavc_functions.h: Addis_hevcfield toavc_ctxRust Code (
src/rust/src/avc/core.rs):(byte[0] >> 1) & 0x3Fpts_ordering_mode):cc_countto 0 per SEI but preservecc_datavector lengthTest Results
Issue #1690 sample file - now extracts 329 lines of clean, readable captions:
Issue #1639 sample file - garbled output now displays correctly:
Acknowledgments
Thanks to @trufio465-bot for the initial research direction in PR #1735. While that PR was incomplete, it helped identify the key areas that needed modification.
Test plan
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.