From 060691d22858f25f7f9d7b0fd7782c88151faa97 Mon Sep 17 00:00:00 2001 From: shubhrai23 Date: Thu, 13 Aug 2026 02:49:47 +0530 Subject: [PATCH 1/3] fix: make GPAC dependency optional in CMake (fixes #2254) --- src/CMakeLists.txt | 14 ++++++++++---- src/lib_ccx/CMakeLists.txt | 14 ++++++++++---- src/lib_ccx/mp4.c | 32 ++++++++++++++++++++++++++++---- src/lib_ccx/params.c | 4 ++++ windows/ccextractor.vcxproj | 8 ++++---- 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f8785ecb..a62a826e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,7 @@ option (WITH_OCR "Build with OCR (Optical Character Recognition) feature" OFF) option (WITH_HARDSUBX "Build with support for burned-in subtitles" OFF) option (VBI_DEBUG "Enable VBI decoder debug output" OFF) option (NETWORKING_DEBUG "Enable networking debug output" OFF) +option (WITH_GPAC "Compile with GPAC support" ON) # HARDSUBX requires OCR (tesseract/leptonica) and FFmpeg if (WITH_HARDSUBX) @@ -55,10 +56,13 @@ configure_file ( "${PROJECT_SOURCE_DIR}/lib_ccx/compile_info_real.h" ) -add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP) +add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DNO_GZIP) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - add_definitions(-DGPAC_64_BITS) +if (WITH_GPAC) + add_definitions(-DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + add_definitions(-DGPAC_64_BITS) + endif() endif() include_directories(${PROJECT_SOURCE_DIR}) @@ -177,7 +181,9 @@ add_subdirectory (lib_ccx) aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE) set (EXTRA_LIBS ${EXTRA_LIBS} ccx) -set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) +if (WITH_GPAC) + set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) +endif() # set (EXTRA_LIBS ${EXTRA_LIBS} m) if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/src/lib_ccx/CMakeLists.txt b/src/lib_ccx/CMakeLists.txt index 1c6a8c744..6356c49f2 100644 --- a/src/lib_ccx/CMakeLists.txt +++ b/src/lib_ccx/CMakeLists.txt @@ -11,10 +11,16 @@ if(WIN32) endif(WIN32) find_package(PkgConfig) -pkg_check_modules (GPAC REQUIRED gpac) - -set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS}) -set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) +if (WITH_GPAC) + pkg_check_modules (GPAC gpac) + if (GPAC_FOUND) + set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS}) + set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPAC") + else () + message(WARNING "GPAC not found. Compiling without GPAC support.") + endif () +endif () if (WITH_FFMPEG) find_package(PkgConfig) diff --git a/src/lib_ccx/mp4.c b/src/lib_ccx/mp4.c index 93d10e340..288c35ae9 100644 --- a/src/lib_ccx/mp4.c +++ b/src/lib_ccx/mp4.c @@ -2,14 +2,17 @@ #include #include +#include "lib_ccx.h" +#include "ccx_mp4.h" + +#ifdef ENABLE_GPAC + #include #include -#include "lib_ccx.h" #include "utility.h" #include "ccx_encoders_common.h" #include "ccx_encoders_mcc.h" #include "ccx_common_option.h" -#include "ccx_mp4.h" #include "activity.h" #include "ccx_dtvcc.h" #include "vobsub_decoder.h" @@ -1121,11 +1124,11 @@ int processmp4(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) const LLONG timestamp = (LLONG)((sample->DTS + sample->CTS_Offset) * 1000) / timescale; #endif set_current_pts(dec_ctx->timing, (sample->DTS + sample->CTS_Offset) * MPEG_CLOCK_FREQ / timescale); - // For caption-only tracks (c608/c708), set frame type to I-frame + // For caption-only tracks (c608/c708, tx3g), set frame type to I-frame // so that set_fts() will set min_pts from the first sample. // Without video frames, frame type would stay Unknown and // min_pts would never be set, causing broken timestamps. - if (type == GF_ISOM_MEDIA_CLOSED_CAPTION) + if (type == GF_ISOM_MEDIA_CLOSED_CAPTION || type == GF_ISOM_MEDIA_TEXT || type == GF_ISOM_MEDIA_SUBT) dec_ctx->timing->current_picture_coding_type = CCX_FRAME_TYPE_I_FRAME; set_fts(dec_ctx->timing); @@ -1293,3 +1296,24 @@ int dumpchapters(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) gf_fclose(t); return mp4_ret; } + +#else + +int processmp4(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) +{ + mprint("GPAC support is disabled. MP4 parsing will not work.\n"); + return -1; +} + +int dumpchapters(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) +{ + return -1; +} + +unsigned char *ccdp_find_data(unsigned char *ccdp_atom_content, unsigned int len, unsigned int *cc_count) +{ + *cc_count = 0; + return NULL; +} + +#endif diff --git a/src/lib_ccx/params.c b/src/lib_ccx/params.c index 042957cea..0e09ddae6 100644 --- a/src/lib_ccx/params.c +++ b/src/lib_ccx/params.c @@ -1,7 +1,9 @@ #include #include "zlib.h" +#ifdef ENABLE_GPAC #include "gpac/setup.h" #include "gpac/version.h" +#endif #include "lib_ccx.h" #include "ccx_common_option.h" #include "utility.h" @@ -778,7 +780,9 @@ void version(char *location) mprint(" Leptonica Version: %s\n", leptversion); lept_free(leptversion); #endif // ENABLE_OCR +#ifdef ENABLE_GPAC mprint(" libGPAC Version: %s\n", GPAC_VERSION); +#endif mprint(" zlib: %s\n", ZLIB_VERSION); mprint(" utf8proc Version: %s\n", (const char *)utf8proc_version()); mprint(" libpng Version: %s\n", PNG_LIBPNG_VER_STRING); diff --git a/windows/ccextractor.vcxproj b/windows/ccextractor.vcxproj index 03271462c..8e58927f0 100644 --- a/windows/ccextractor.vcxproj +++ b/windows/ccextractor.vcxproj @@ -289,7 +289,7 @@ ..\src\thirdparty\freetype\include;..\src;..\src\thirdparty\win_spec_incld;..\src\lib_ccx;..\src\thirdparty\lib_hash;..\src\lib_ccx\zvbi;..\src\thirdparty\win_iconv;..\src\thirdparty\;..\src;$(VCPKG_ROOT)\installed\$(VCPKG_DEFAULT_TRIPLET)\include; "$(GpacDir)\sdk\include";%(AdditionalIncludeDirectories) - $(ExtraDefines);SEGMENT_BY_FILE_TIME;ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) + $(ExtraDefines);SEGMENT_BY_FILE_TIME;ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;ENABLE_OCR;ENABLE_GPAC;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) Default MultiThreadedDebug @@ -337,7 +337,7 @@ ..\src\thirdparty\freetype\include;..\src;..\src\thirdparty\win_spec_incld;..\src\lib_ccx;..\src\thirdparty\lib_hash;..\src\lib_ccx\zvbi;..\src\thirdparty\win_iconv;..\src\thirdparty\;..\src;$(VCPKG_ROOT)\installed\$(VCPKG_DEFAULT_TRIPLET)\include; "$(GpacDir)\sdk\include";%(AdditionalIncludeDirectories) - $(ExtraDefines);SEGMENT_BY_FILE_TIME;ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) + $(ExtraDefines);SEGMENT_BY_FILE_TIME;ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;ENABLE_OCR;ENABLE_GPAC;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) Default MultiThreadedDebug @@ -384,7 +384,7 @@ ..\src\thirdparty\freetype\include;..\src;..\src\thirdparty\win_spec_incld;..\src\lib_ccx;..\src\thirdparty\lib_hash;..\src\lib_ccx\zvbi;..\src\thirdparty\win_iconv;..\src\thirdparty\;..\src;$(VCPKG_ROOT)\installed\$(VCPKG_DEFAULT_TRIPLET)\include; "$(GpacDir)\sdk\include";%(AdditionalIncludeDirectories) - $(ExtraDefines);ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;VERSION_FILE_PRESENT;ENABLE_OCR;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) + $(ExtraDefines);ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;VERSION_FILE_PRESENT;ENABLE_OCR;ENABLE_GPAC;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) MultiThreaded @@ -432,7 +432,7 @@ ..\src\thirdparty\freetype\include;..\src;..\src\thirdparty\win_spec_incld;..\src\lib_ccx;..\src\thirdparty\lib_hash;..\src\lib_ccx\zvbi;..\src\thirdparty\win_iconv;..\src\thirdparty\;..\src;$(VCPKG_ROOT)\installed\$(VCPKG_DEFAULT_TRIPLET)\include; "$(GpacDir)\sdk\include";%(AdditionalIncludeDirectories) - $(ExtraDefines);ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;VERSION_FILE_PRESENT;ENABLE_OCR;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) + $(ExtraDefines);ENABLE_HARDSUBX;FT2_BUILD_LIBRARY;GPAC_DISABLE_VTT;GPAC_DISABLE_OD_DUMP;VERSION_FILE_PRESENT;ENABLE_OCR;ENABLE_GPAC;WIN32;NDEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;GPAC_DISABLE_REMOTERY;GPAC_DISABLE_ZLIB;%(PreprocessorDefinitions) MultiThreaded From b46ea57242c9d779cee437ccc869dcf0a091bb0b Mon Sep 17 00:00:00 2001 From: shubhrai23 Date: Thu, 13 Aug 2026 03:11:16 +0530 Subject: [PATCH 2/3] feat: automatically fetch and build GPAC if missing on system --- src/lib_ccx/CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib_ccx/CMakeLists.txt b/src/lib_ccx/CMakeLists.txt index 6356c49f2..3b62ae90d 100644 --- a/src/lib_ccx/CMakeLists.txt +++ b/src/lib_ccx/CMakeLists.txt @@ -18,7 +18,19 @@ if (WITH_GPAC) set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPAC") else () - message(WARNING "GPAC not found. Compiling without GPAC support.") + message(STATUS "GPAC not found via pkg-config. Falling back to FetchContent...") + include(FetchContent) + FetchContent_Declare( + gpac + GIT_REPOSITORY https://github.com/gpac/gpac.git + GIT_TAG master + ) + FetchContent_MakeAvailable(gpac) + + # Link against the fetched GPAC + set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${gpac_SOURCE_DIR}/include) + set (EXTRA_LIBS ${EXTRA_LIBS} libgpac) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPAC") endif () endif () From 53e8b68c187e3e59c4e894eaf4c43c9e9c7a02bc Mon Sep 17 00:00:00 2001 From: shubhrai23 Date: Fri, 14 Aug 2026 05:37:09 +0530 Subject: [PATCH 3/3] fix: address review comments for CMake and GPAC stubs --- src/CMakeLists.txt | 2 +- src/lib_ccx/CMakeLists.txt | 8 ++++++-- src/lib_ccx/mp4.c | 3 ++- temp_mp4_diff.patch | Bin 0 -> 4240 bytes 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 temp_mp4_diff.patch diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a62a826e6..bb4d4885a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,7 +181,7 @@ add_subdirectory (lib_ccx) aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE) set (EXTRA_LIBS ${EXTRA_LIBS} ccx) -if (WITH_GPAC) +if (WITH_GPAC AND GPAC_FOUND) set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) endif() # set (EXTRA_LIBS ${EXTRA_LIBS} m) diff --git a/src/lib_ccx/CMakeLists.txt b/src/lib_ccx/CMakeLists.txt index 3b62ae90d..b6d7ada7e 100644 --- a/src/lib_ccx/CMakeLists.txt +++ b/src/lib_ccx/CMakeLists.txt @@ -16,7 +16,9 @@ if (WITH_GPAC) if (GPAC_FOUND) set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS}) set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES}) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPAC") + add_definitions(-DENABLE_GPAC) + set (GPAC_FOUND ${GPAC_FOUND} PARENT_SCOPE) + set (GPAC_LIBRARIES ${GPAC_LIBRARIES} PARENT_SCOPE) else () message(STATUS "GPAC not found via pkg-config. Falling back to FetchContent...") include(FetchContent) @@ -30,7 +32,9 @@ if (WITH_GPAC) # Link against the fetched GPAC set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${gpac_SOURCE_DIR}/include) set (EXTRA_LIBS ${EXTRA_LIBS} libgpac) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPAC") + add_definitions(-DENABLE_GPAC) + set (GPAC_FOUND TRUE PARENT_SCOPE) + set (GPAC_LIBRARIES libgpac PARENT_SCOPE) endif () endif () diff --git a/src/lib_ccx/mp4.c b/src/lib_ccx/mp4.c index 288c35ae9..036aa4b66 100644 --- a/src/lib_ccx/mp4.c +++ b/src/lib_ccx/mp4.c @@ -1301,12 +1301,13 @@ int dumpchapters(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) int processmp4(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) { - mprint("GPAC support is disabled. MP4 parsing will not work.\n"); + mprint("GPAC support is disabled. MP4 parsing will not work. Recompile with GPAC support to enable this feature.\n"); return -1; } int dumpchapters(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file) { + mprint("GPAC support is disabled. MP4 chapters will not work. Recompile with GPAC support to enable this feature.\n"); return -1; } diff --git a/temp_mp4_diff.patch b/temp_mp4_diff.patch new file mode 100644 index 0000000000000000000000000000000000000000..b8548af8bdddd155c78adeffe68709b6a8407b7c GIT binary patch literal 4240 zcmd6qYi}D>5QgWgk@ycs>6Zk@iF2U^K~Yn;jSx*KBo!bbt?acEqB?fuwG*nAzYaX_ zoL%qwlE$S)idJsUb`j>}zIS+p#9|J>&-;H|;*-eUk*~ z*H~FM-KhKbAzD7NN4(HL!%g0Qz_^}|rIB_eH`qP5Ck2~{TNUhEa61PZS@VZ|_nvbZ zC%ZYS)w9vYMagS(9?+e&9Fb+Gqo0zgpUTta3#YENy#CZ)*nvH^=Zq3Nw3p0Ux%8WD zJtGF%cyJq=GaI_yilp|f)|WRGM?E5LpLd7ob6UAuUxM(>I4twW8lI6y6uo162$)YQ??||dPIYbOlqFY9Ck#{>}-7XQK?A!6|iz_?Rm3UHYBA&X$M?)m` zcp(EZG1EGuG3yhzEzD()cx>z}^hG|}M9%Du0z-K}%4`vxXPna=jdUj^58J$>)l-kO zo^9lLU$f$qwF8$Q$g$`4Bl&j7oq{d&a@$`C_K@}U%Bc-zvL^2Lv9bZPJh2ly=474U z{9eoV5?&FfXWSU0lQb;&wCVG0=A{NHFG%_~Q`S-z#L5skps=Qv%M^+eY#(t;o=7}G zGqjB!E>M=f@f~?A;`Zq*I)bg9f@T6^3E7tY!1$T{%<4~AxZKK(+|I_-M>S6B>@$2N ze+rK>;~MV4J{%&}WsCAa*%&QNuw=}5-6QSVGowG<4IrRcC?Y1}BDRZ? zgo(0A+#6+<(Z98jUD0p9a9&yro%4gUnc`5|m8fR!jdEV~!nNP+6TOiO+V1UF==qx8 z(60GcU6Hb4J|m(I^Hx-l0zaoA-0amjUz@!IP06aA{JsvD}Y>bE!f1@CHu$Di`8 zi&d(5vAT%`V;^)^s_GfBE{0L>J#@xV+?STu$RAZbRVQUotlvq#S|I#ao+(k%83A}u1`uvx?lZ0~NgRq7m8ll-(}SG%GrjySG}uBt7;ipN4;0