Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGES.TXT
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.0 (to be released)
-----------------
- Refactor: Remove API structures from ccextractor
- New: Add Encoder Module to Rust
- Fix: Elementary stream regressions
- Fix: Segmentation faults on XDS files
Expand Down
59 changes: 27 additions & 32 deletions src/ccextractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void print_end_msg(void)
mprint("https://github.com/CCExtractor/ccextractor/issues\n");
}

int api_start(struct ccx_s_options api_options)
int start_ccx()
{
struct lib_ccx_ctx *ctx = NULL; // Context for libs
struct lib_cc_decode *dec_ctx = NULL; // Context for decoder
Expand All @@ -49,7 +49,7 @@ int api_start(struct ccx_s_options api_options)
setMsgSeverity(LEPT_MSG_SEVERITY);
#endif
// Initialize CCExtractor libraries
ctx = init_libraries(&api_options);
ctx = init_libraries(&ccx_options);

if (!ctx)
{
Expand All @@ -66,10 +66,10 @@ int api_start(struct ccx_s_options api_options)
}

#ifdef ENABLE_HARDSUBX
if (api_options.hardsubx)
if (ccx_options.hardsubx)
{
// Perform burned in subtitle extraction
hardsubx(&api_options, ctx);
hardsubx(&ccx_options, ctx);
return 0;
}
#endif
Expand Down Expand Up @@ -97,19 +97,19 @@ int api_start(struct ccx_s_options api_options)
tlt_config.page = ((tlt_config.page / 100) << 8) | (((tlt_config.page / 10) % 10) << 4) | (tlt_config.page % 10);
}

if (api_options.transcript_settings.xds)
if (ccx_options.transcript_settings.xds)
{
if (api_options.write_format != CCX_OF_TRANSCRIPT)
if (ccx_options.write_format != CCX_OF_TRANSCRIPT)
{
api_options.transcript_settings.xds = 0;
ccx_options.transcript_settings.xds = 0;
mprint("Warning: -xds ignored, XDS can only be exported to transcripts at this time.\n");
}
}

time_t start, final;
time(&start);

if (api_options.binary_concat)
if (ccx_options.binary_concat)
{
ctx->total_inputsize = get_total_file_size(ctx);
if (ctx->total_inputsize < 0)
Expand Down Expand Up @@ -139,24 +139,24 @@ int api_start(struct ccx_s_options api_options)
terminate_asap = 0;

#ifdef ENABLE_SHARING
if (api_options.translate_enabled && ctx->num_input_files > 1)
if (ccx_options.translate_enabled && ctx->num_input_files > 1)
{
mprint("[share] WARNING: simultaneous translation of several input files is not supported yet\n");
api_options.translate_enabled = 0;
api_options.sharing_enabled = 0;
ccx_options.translate_enabled = 0;
ccx_options.sharing_enabled = 0;
}
if (api_options.translate_enabled)
if (ccx_options.translate_enabled)
{
mprint("[share] launching translate service\n");
ccx_share_launch_translator(api_options.translate_langs, api_options.translate_key);
ccx_share_launch_translator(ccx_options.translate_langs, ccx_options.translate_key);
}
#endif // ENABLE_SHARING
ret = 0;
while (switch_to_next_file(ctx, 0))
{
prepare_for_new_file(ctx);
#ifdef ENABLE_SHARING
if (api_options.sharing_enabled)
if (ccx_options.sharing_enabled)
ccx_share_start(ctx->basefilename);
#endif // ENABLE_SHARING

Expand Down Expand Up @@ -185,8 +185,8 @@ int api_start(struct ccx_s_options api_options)
{
// Note: This case is meant to fall through
case CCX_SM_ELEMENTARY_OR_NOT_FOUND:
if (!api_options.use_gop_as_pts) // If !0 then the user selected something
api_options.use_gop_as_pts = 1; // Force GOP timing for ES
if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something
ccx_options.use_gop_as_pts = 1; // Force GOP timing for ES
ccx_common_timing_settings.is_elementary_stream = 1;
case CCX_SM_TRANSPORT:
case CCX_SM_PROGRAM:
Expand All @@ -197,9 +197,9 @@ int api_start(struct ccx_s_options api_options)
#ifdef ENABLE_FFMPEG
case CCX_SM_FFMPEG:
#endif
if (!api_options.use_gop_as_pts) // If !0 then the user selected something
api_options.use_gop_as_pts = 0;
if (api_options.ignore_pts_jumps)
if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something
ccx_options.use_gop_as_pts = 0;
if (ccx_options.ignore_pts_jumps)
ccx_common_timing_settings.disable_sync_check = 1;
mprint("\rAnalyzing data in general mode\n");
tmp = general_loop(ctx);
Expand Down Expand Up @@ -232,15 +232,15 @@ int api_start(struct ccx_s_options api_options)
{
fatal(EXIT_INCOMPATIBLE_PARAMETERS, "MP4 requires an actual file, it's not possible to read from a stream, including stdin.\n");
}
if (api_options.extract_chapters)
if (ccx_options.extract_chapters)
{
tmp = dumpchapters(ctx, &ctx->mp4_cfg, ctx->inputfile[ctx->current_file]);
}
else
{
tmp = processmp4(ctx, &ctx->mp4_cfg, ctx->inputfile[ctx->current_file]);
}
if (api_options.print_file_reports)
if (ccx_options.print_file_reports)
print_file_report(ctx);
if (!ret)
ret = tmp;
Expand Down Expand Up @@ -311,7 +311,7 @@ int api_start(struct ccx_s_options api_options)
dec_ctx->timing->fts_max = 0;

#ifdef ENABLE_SHARING
if (api_options.sharing_enabled)
if (ccx_options.sharing_enabled)
{
ccx_share_stream_done(ctx->basefilename);
ccx_share_stop();
Expand Down Expand Up @@ -430,23 +430,18 @@ int api_start(struct ccx_s_options api_options)
return ret ? EXIT_OK : EXIT_NO_CAPTIONS;
}

struct ccx_s_options *api_init_options()
{
init_options(&ccx_options);
return &ccx_options;
}

int main(int argc, char *argv[])
{
setlocale(LC_ALL, ""); // Supports non-English CCs
// Use POSIX locale for numbers so we get "." as decimal separator and no
// thousands' groupoing instead of what the locale might say
setlocale(LC_NUMERIC, "POSIX");

struct ccx_s_options *api_options = api_init_options();
parse_configuration(api_options);
init_options(&ccx_options);

// If "ccextractor.cnf" is present, takes options from it.
// See docs/ccextractor.cnf.sample for more info.
parse_configuration(&ccx_options);

#ifndef DISABLE_RUST
ccxr_init_basic_logger();
Expand All @@ -455,7 +450,7 @@ int main(int argc, char *argv[])
#ifndef DISABLE_RUST
int compile_ret = ccxr_parse_parameters(argc, argv);
#else
int compile_ret = parse_parameters(api_options, argc, argv);
int compile_ret = parse_parameters(&ccx_options, argc, argv);
#endif

if (compile_ret == EXIT_NO_INPUT_FILES)
Expand All @@ -472,6 +467,6 @@ int main(int argc, char *argv[])
exit(compile_ret);
}

int start_ret = api_start(*api_options);
int start_ret = start_ccx();
return start_ret;
}
Loading