diff --git a/docs/using_cmake_build.txt b/docs/using_cmake_build.txt new file mode 100644 index 00000000..67077d27 --- /dev/null +++ b/docs/using_cmake_build.txt @@ -0,0 +1,28 @@ +For building ccextractor using cmake folllow below steps.. + +Step 1) Check you have right version of cmake installed. ( version >= 3.0.2 ) + We are using CMP0037 policy of cmake which was introduced in 3.0.0 + since we have tested our system only with cmake version 3.0.2, I would + suggest to use 3.0.2 or higher version. + + +Step 2) create a seprate directory where you want to build the target. + In Unix you can do it using follwing commands. + ~> cd ccextractor + ~> mkdir build + +Step 3) make the build sytem using cmake + ~> cmake ../src/ + +Step 4) Compile the code. + ~> make + ~> make install + +Step 5) Use CCextractor as you would like + + +If you want to build CCExtractor with FFMpeg you need to pass +cmake -DWITH_FFMPEG=ON ../src/ + +Hint for looking all the things you want to set from outside +cmake -LAH ../src/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 229f22ba..f0093143 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 3.0.2) project (CCExtractor) +option(WITH_FFMPEG "Build using FFmpeg demuxer and decoder" OFF) #Version number set (CCEXTRACTOR_VERSION_MAJOR 0) set (CCEXTRACTOR_VERSION_MINOR 75) @@ -13,6 +14,7 @@ configure_file ( "${PROJECT_BINARY_DIR}/CCExtractorConfig.h" ) + include_directories ("${PROJECT_SOURCE_DIR}") include_directories ("${PROJECT_SOURCE_DIR}/lib_ccx") include_directories ("${PROJECT_SOURCE_DIR}/gpacmp4/") @@ -22,7 +24,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/libccx_common/") LINK_DIRECTORIES(/opt/local/lib) LINK_DIRECTORIES(/usr/local/lib) -SET (CMAKE_C_FLAGS "-O0 -Wall -g -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64") +SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -g -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64") add_subdirectory (lib_ccx) AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR} SOURCEFILE) @@ -30,6 +32,22 @@ set (EXTRA_LIBS ${EXTRA_LIBS} ccx) set (EXTRA_LIBS ${EXTRA_LIBS} png) set (EXTRA_LIBS ${EXTRA_LIBS} m) +######################################################## +# Build using FFmpeg libraries +# +if (WITH_FFMPEG) + +find_package(PkgConfig) +pkg_check_modules(AVFORMAT REQUIRED libavformat) +pkg_check_modules(AVUTIL REQUIRED libavutil) +pkg_check_modules(AVCODEC REQUIRED libavcodec) +set (EXTRA_LIBS ${EXTRA_LIBS} ${AVFORMAT_STATIC_LIBRARIES} ) +set (EXTRA_LIBS ${EXTRA_LIBS} ${AVUTIL_STATIC_LIBRARIES} ) +set (EXTRA_LIBS ${EXTRA_LIBS} ${AVCODEC_STATIC_LIBRARIES} ) + +SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_FFMPEG") +endif (WITH_FFMPEG) + add_executable(ccextractor ${SOURCEFILE}) target_link_libraries (ccextractor ${EXTRA_LIBS}) diff --git a/src/ccextractor.c b/src/ccextractor.c index 2ce4f22a..b1e9cdb6 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -28,7 +28,9 @@ int main(int argc, char *argv[]) char *c; struct encoder_ctx enc_ctx[2]; struct cc_subtitle dec_sub; +#ifdef ENABLE_FFMPEG void *ffmpeg_ctx = NULL; +#endif struct lib_ccx_ctx *ctx; struct lib_cc_decode *dec_ctx = NULL; @@ -416,20 +418,12 @@ int main(int argc, char *argv[]) ffmpeg_ctx = init_ffmpeg(ctx->inputfile[0]); if(ffmpeg_ctx) { - int i =0; - ctx->buffer = malloc(1024); - if(!ctx->buffer) - { - mprint("no memory left\n"); - break; - } do { int ret = 0; - char *bptr = ctx->buffer; + unsigned char *bptr = ctx->buffer; int len = ff_get_ccframe(ffmpeg_ctx, bptr, 1024); int cc_count = 0; - memset(bptr,0,1024); if(len == AVERROR(EAGAIN)) { continue; @@ -446,15 +440,13 @@ int main(int argc, char *argv[]) } else cc_count = len/3; - store_hdcc(ctx, bptr, cc_count, i++,fts_now,&dec_sub); - if(dec_sub.got_output) + ret = process_cc_data(dec_ctx, bptr, cc_count, &dec_sub); + if(ret >= 0 && dec_sub.got_output) { encode_sub(enc_ctx, &dec_sub); dec_sub.got_output = 0; } }while(1); - - free(ctx->buffer); continue; } else @@ -462,7 +454,6 @@ int main(int argc, char *argv[]) mprint ("\rFailed to initialized ffmpeg falling back to legacy\n"); } #endif - if (ctx->auto_stream == CCX_SM_AUTODETECT) { detect_stream_type(ctx); @@ -711,7 +702,7 @@ int main(int argc, char *argv[]) // and need to be written after the last file is processed. cb_field1 = 0; cb_field2 = 0; cb_708 = 0; fts_now = 0; - fts_max = 0; + fts_max = 0; } // file loop close_input_file(ctx); diff --git a/src/lib_ccx/CMakeLists.txt b/src/lib_ccx/CMakeLists.txt index 475c7c70..3a36f53f 100644 --- a/src/lib_ccx/CMakeLists.txt +++ b/src/lib_ccx/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_policy(SET CMP0037 NEW) SET (CMAKE_C_FLAGS "-O0 -Wall -g -std=gnu99") + +if (WITH_FFMPEG) +SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_FFMPEG") +endif (WITH_FFMPEG) + AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/lib_ccx/" SOURCEFILE) AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/gpacmp4/" SOURCEFILE) #AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/libpng/" SOURCEFILE) diff --git a/src/lib_ccx/ccx_decoders_common.c b/src/lib_ccx/ccx_decoders_common.c index 9c182667..8cd800a2 100644 --- a/src/lib_ccx/ccx_decoders_common.c +++ b/src/lib_ccx/ccx_decoders_common.c @@ -100,7 +100,7 @@ unsigned get_decoder_line_basic(unsigned char *buffer, int line_num, struct eia6 int process_cc_data (struct lib_cc_decode *ctx, unsigned char *cc_data, int cc_count, struct cc_subtitle *sub) { - int ret = 0; + int ret = -1; for (int j = 0; j < cc_count * 3; j = j + 3) { if (validate_cc_data_pair( cc_data + j ) ) diff --git a/src/lib_ccx/ffmpeg_intgr.c b/src/lib_ccx/ffmpeg_intgr.c index 6fe5b14f..0a74ec9c 100644 --- a/src/lib_ccx/ffmpeg_intgr.c +++ b/src/lib_ccx/ffmpeg_intgr.c @@ -126,7 +126,7 @@ fail: * @param maxlen length of buffer, where data will be copied * @return number of bytes recieved as data */ -int ff_get_ccframe(void *arg,char*data,int maxlen) +int ff_get_ccframe(void *arg, unsigned char*data, int maxlen) { struct ffmpeg_ctx *ctx = arg; int len = 0; diff --git a/src/lib_ccx/ffmpeg_intgr.h b/src/lib_ccx/ffmpeg_intgr.h index efc963d9..3d0bce0b 100644 --- a/src/lib_ccx/ffmpeg_intgr.h +++ b/src/lib_ccx/ffmpeg_intgr.h @@ -19,5 +19,5 @@ void *init_ffmpeg(char *path); * @param maxlen length of buffer, where data will be copied * @return number of bytes recieved as data */ -int ff_get_ccframe(void *arg,char*data,int maxlen); +int ff_get_ccframe(void *arg, unsigned char*data, int maxlen); #endif diff --git a/src/lib_ccx/ts_tables.c b/src/lib_ccx/ts_tables.c index 451f1f51..23de753f 100644 --- a/src/lib_ccx/ts_tables.c +++ b/src/lib_ccx/ts_tables.c @@ -271,7 +271,7 @@ int parse_PMT (struct lib_ccx_ctx *ctx, unsigned char *buf, int len, int pos) #ifndef ENABLE_OCR if(ccx_options.write_format != CCX_OF_SPUPNG ) { - mprint ("Please Compile with ENABLE_OCR flag \n"); + mprint ("DVB subtitles detected, OCR subsystem not present. Use -out=spupng for graphic output\n"); continue; } #endif