Skip to content

Commit c83ebd9

Browse files
committed
feat(mp4): add FFmpeg/libavformat backend for MP4 demuxing
Replace the custom GPAC-based MP4 parser with an FFmpeg/libavformat implementation for subtitle extraction. This provides broader codec support, better container compatibility, and leverages FFmpeg's mature demuxing infrastructure for handling MP4/MOV files. - Add mp4_ffmpeg.c with full libavformat-based demuxing pipeline - Update CMakeLists to detect and link FFmpeg libraries (libavformat, libavcodec, libavutil) with fallback to GPAC when unavailable - Integrate FFmpeg pathway into ccextractor main entry point - Preserve existing GPAC codepath as fallback
1 parent b8d067c commit c83ebd9

File tree

5 files changed

+1371
-12
lines changed

5 files changed

+1371
-12
lines changed

src/CMakeLists.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include (CTest)
66
option (WITH_FFMPEG "Build using FFmpeg demuxer and decoder" OFF)
77
option (WITH_OCR "Build with OCR (Optical Character Recognition) feature" OFF)
88
option (WITH_HARDSUBX "Build with support for burned-in subtitles" OFF)
9+
option (USE_FFMPEG_MP4 "Use FFmpeg libavformat for MP4 parsing instead of GPAC" OFF)
910

1011
# Version number
1112
set (CCEXTRACTOR_VERSION_MAJOR 0)
@@ -40,10 +41,13 @@ configure_file (
4041
"${PROJECT_SOURCE_DIR}/lib_ccx/compile_info_real.h"
4142
)
4243

43-
add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP)
44-
45-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
46-
add_definitions(-DGPAC_64_BITS)
44+
if (USE_FFMPEG_MP4)
45+
add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DNO_GZIP -DUSE_FFMPEG_MP4)
46+
else()
47+
add_definitions(-DVERSION_FILE_PRESENT -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP)
48+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
49+
add_definitions(-DGPAC_64_BITS)
50+
endif()
4751
endif()
4852

4953
include_directories(${PROJECT_SOURCE_DIR})
@@ -149,18 +153,17 @@ add_subdirectory (lib_ccx)
149153

150154
aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE)
151155
set (EXTRA_LIBS ${EXTRA_LIBS} ccx)
152-
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
156+
if (NOT USE_FFMPEG_MP4)
157+
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
158+
endif()
153159
# set (EXTRA_LIBS ${EXTRA_LIBS} m)
154160

155161
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
156162
set (EXTRA_LIBS ${EXTRA_LIBS} iconv)
157163
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
158164

159165

160-
# Unix-specific system libraries (not available on Windows)
161-
if(NOT WIN32)
162-
set (EXTRA_LIBS ${EXTRA_LIBS} -lm -lpthread -ldl)
163-
endif()
166+
set (EXTRA_LIBS ${EXTRA_LIBS} -lm -lpthread -ldl)
164167

165168
find_package (PkgConfig)
166169

src/ccextractor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ int start_ccx()
222222
ret = tmp;
223223
break;
224224
case CCX_SM_MP4:
225+
#ifdef USE_FFMPEG_MP4
226+
mprint("\rAnalyzing data with FFmpeg (libavformat)\n");
227+
#else
225228
mprint("\rAnalyzing data with GPAC (MP4 library)\n");
229+
#endif
226230
close_input_file(ctx); // No need to have it open. GPAC will do it for us
227231
if (ctx->current_file == -1) // We don't have a file to open, must be stdin, and GPAC is incompatible with stdin
228232
{

src/lib_ccx/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ if(WIN32)
1111
endif(WIN32)
1212

1313
find_package(PkgConfig)
14-
pkg_check_modules (GPAC REQUIRED gpac)
1514

16-
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS})
17-
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
15+
if (USE_FFMPEG_MP4)
16+
# Use FFmpeg libavformat/libavutil for MP4 parsing instead of GPAC
17+
pkg_check_modules (AVFORMAT REQUIRED libavformat)
18+
pkg_check_modules (AVUTIL REQUIRED libavutil)
19+
20+
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${AVFORMAT_INCLUDE_DIRS})
21+
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${AVUTIL_INCLUDE_DIRS})
22+
set (EXTRA_LIBS ${EXTRA_LIBS} ${AVFORMAT_LIBRARIES})
23+
set (EXTRA_LIBS ${EXTRA_LIBS} ${AVUTIL_LIBRARIES})
24+
25+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_FFMPEG_MP4")
26+
else()
27+
pkg_check_modules (GPAC REQUIRED gpac)
28+
set (EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GPAC_INCLUDE_DIRS})
29+
set (EXTRA_LIBS ${EXTRA_LIBS} ${GPAC_LIBRARIES})
30+
endif()
1831

1932
if (WITH_FFMPEG)
2033
find_package(PkgConfig)

src/lib_ccx/mp4.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef USE_FFMPEG_MP4
2+
/* When USE_FFMPEG_MP4 is defined, mp4_ffmpeg.c provides processmp4/dumpchapters instead */
3+
14
#include <stdio.h>
25
#include <time.h>
36
#include <stdlib.h>
@@ -1293,3 +1296,5 @@ int dumpchapters(struct lib_ccx_ctx *ctx, struct ccx_s_mp4Cfg *cfg, char *file)
12931296
gf_fclose(t);
12941297
return mp4_ret;
12951298
}
1299+
1300+
#endif /* USE_FFMPEG_MP4 */

0 commit comments

Comments
 (0)