Skip to content

feat: replace GPAC with FFmpeg for MP4 demuxing #2170

Open
DhanushVarma-2 wants to merge 17 commits intoCCExtractor:masterfrom
DhanushVarma-2:feat/replace-gpac-with-ffmpeg
Open

feat: replace GPAC with FFmpeg for MP4 demuxing #2170
DhanushVarma-2 wants to merge 17 commits intoCCExtractor:masterfrom
DhanushVarma-2:feat/replace-gpac-with-ffmpeg

Conversation

@DhanushVarma-2
Copy link
Contributor

@DhanushVarma-2 DhanushVarma-2 commented Mar 4, 2026

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Adds an FFmpeg-based MP4 demuxing path as an alternative to GPAC, enabled when building with -DWITH_FFMPEG=ON.

When ENABLE_FFMPEG_MP4 is set, processmp4() calls processmp4_ffmpeg() which uses avformat/avcodec instead of libgpac for opening files, reading tracks, and extracting samples. Supports AVC, HEVC, tx3g, c608, c708, and VOBSUB tracks. The existing GPAC path is unchanged and still used when FFmpeg is not enabled.

Also added libswresample to the CMake FFmpeg deps since the Rust library needs it.

Tested locally on macOS (arm64) with various MP4 files. Linux, Mac, and Docker CI all pass. Windows CI is failing due to Chocolatey servers being down (unrelated).

@DhanushVarma-2 DhanushVarma-2 changed the title Feat/replace gpac with ffmpeg feat: replace GPAC with FFmpeg for MP4 demuxing Mar 5, 2026
Add FFmpeg-based MP4 demuxer as alternative to GPAC, enabled via
-DWITH_FFMPEG=ON (sets ENABLE_FFMPEG_MP4). Uses avformat_open_input,
av_read_frame, and extradata parsing instead of libgpac.

Supports AVC, HEVC, tx3g, c608, c708, and VOBSUB tracks.
Existing GPAC path unchanged when FFmpeg is not enabled.

Also adds libswresample to CMake FFmpeg dependencies.
@DhanushVarma-2 DhanushVarma-2 force-pushed the feat/replace-gpac-with-ffmpeg branch from 006130e to 4039844 Compare March 6, 2026 06:23
@DhanushVarma-2
Copy link
Contributor Author

The 9 Windows test failures (autoprogram, spupng, startcreditstext) are unrelated to MP4 demuxing — they involve subtitle encoding and credits detection, not the MP4 code path. These same tests pass on the Linux CI run. The Windows build itself was also delayed by a Chocolatey 503 outage when installing GPAC.

All 237 Linux tests pass, including the 3 MP4-specific tests. The Linux CI bot also notes this PR fixes 9 previously-broken tests that had never passed before.

@DhanushVarma-2 DhanushVarma-2 force-pushed the feat/replace-gpac-with-ffmpeg branch 12 times, most recently from af09ee5 to 87f2178 Compare March 6, 2026 19:45
@DhanushVarma-2 DhanushVarma-2 force-pushed the feat/replace-gpac-with-ffmpeg branch from 87f2178 to 9e95cd7 Compare March 7, 2026 06:59
@cfsmp3
Copy link
Contributor

cfsmp3 commented Mar 7, 2026

Before going deep into this.

It would be a lot more readable to separate both implementations. Have process_mp4_ffmpeg and process_mp4_gpac functions, possibly in separate files, so we only need a few #ifdef guards.

Minimize the changes in the existing code (which already is not super well organized)...

Even (much better), do the ffmpeg part in rust. We don't want to add more C to the code - we really want to switch to rust.

@DhanushVarma-2
Copy link
Contributor Author

Before going deep into this.

It would be a lot more readable to separate both implementations. Have process_mp4_ffmpeg and process_mp4_gpac functions, possibly in separate files, so we only need a few #ifdef guards.

Minimize the changes in the existing code (which already is not super well organized)...

Even (much better), do the ffmpeg part in rust. We don't want to add more C to the code - we really want to switch to rust.

yeah sure.

Dhanush Varma added 10 commits March 9, 2026 13:17
- Add enable_mp4_ffmpeg feature flag to Cargo.toml
- Create src/demuxer/mp4.rs with track enumeration using rsmpeg
- Add C-callable exports in mp4_ffmpeg_exports.rs
- Register modules in lib.rs and demuxer/mod.rs

This is the foundation for replacing the C FFmpeg implementation
with a Rust-based demuxer as suggested by @cfsmp3
- Full track classification (AVC, HEVC, tx3g, CEA-608/708, VobSub)
- NAL unit size parsing from AVCC/HVCC extradata in Rust
- AVC and HEVC track processing via C bridge functions
- Add mp4_rust_bridge.h/c to expose static C functions to Rust
- Add ccx_mp4_process_avc/hevc_sample bridge functions
- Update build.rs to pass ENABLE_FFMPEG_MP4 define to bindgen
- Update wrapper.h to include bridge header
- Add unit tests for track classification and NAL parsing
Per maintainer feedback, rewrote FFmpeg MP4 demuxing in Rust:

- src/demuxer/mp4.rs: Full Rust implementation using rsmpeg
  - Track classification (AVC, HEVC, tx3g, CEA-608/708, VobSub)
  - NAL unit size parsing from AVCC/HVCC extradata
  - AVC and HEVC sample processing via C bridge
  - Clean error handling, no crashes on corrupted files

- mp4_rust_bridge.c/h: Minimal C bridge exposing internal functions
- ccx_gpac_types.h: Clean GPAC type definitions (no more stubs in mp4.c)
- mp4.c: Minimal changes, GPAC code untouched (41 gf_isom calls intact)
  - Only 13 #ifdef guards (down from 30+)
  - Calls ccxr_processmp4() and ccxr_dumpchapters() (Rust)

Build verified on macOS arm64 with -DWITH_FFMPEG=ON
All valid MP4 files processed correctly, corrupted files rejected cleanly
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 90128d8...:
Report Name Tests Passed
Broken 10/13
CEA-708 2/14
DVB 4/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 79/86
Teletext 20/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

NOTE: The following tests have been failing on the master branch as well as the PR:

  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed:

    Test 8730

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --parsePAT --out=srt c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --endcreditsforatleast 3 --endcreditstext "CCextractor Ends crdit Testing" addf5e2fc9..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit e4bcade...:
Report Name Tests Passed
Broken 10/13
CEA-708 2/14
DVB 4/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 81/86
Teletext 20/21
WTV 13/13
XDS 34/34

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

This PR does not introduce any new test failures. However, some tests are failing on both master and this PR (see above).

Check the result page for more info.

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.

3 participants