feat: replace GPAC with FFmpeg for MP4 demuxing #2170
feat: replace GPAC with FFmpeg for MP4 demuxing #2170DhanushVarma-2 wants to merge 17 commits intoCCExtractor:masterfrom
Conversation
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.
006130e to
4039844
Compare
|
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. |
af09ee5 to
87f2178
Compare
87f2178 to
9e95cd7
Compare
|
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. |
- 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 CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 90128d8...:
Your PR breaks these cases:
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:
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 CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit e4bcade...:
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:
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. |
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
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).