diff --git a/src/ccextractor.c b/src/ccextractor.c index 1add39d3..19689f74 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) return 0; } #endif - // Initialize libraries + // Initialize CCExtractor libraries ctx = init_libraries(&ccx_options); if (!ctx && errno == ENOMEM) fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); @@ -68,6 +68,7 @@ int main(int argc, char *argv[]) else if (!ctx) fatal (EXIT_NOT_CLASSIFIED, "Unable to create Library Context %d\n",errno); + int show_myth_banner = 0; params_dump(ctx); diff --git a/src/lib_ccx/ccx_common_constants.h b/src/lib_ccx/ccx_common_constants.h index c5de8c75..3b072916 100644 --- a/src/lib_ccx/ccx_common_constants.h +++ b/src/lib_ccx/ccx_common_constants.h @@ -169,6 +169,7 @@ enum ccx_output_format CCX_OF_WEBVTT = 9, CCX_OF_SIMPLE_XML = 10, CCX_OF_G608 = 11, + CCX_OF_CURL = 12, }; enum ccx_output_date_format diff --git a/src/lib_ccx/ccx_common_option.c b/src/lib_ccx/ccx_common_option.c index ace4dd92..fc882f00 100644 --- a/src/lib_ccx/ccx_common_option.c +++ b/src/lib_ccx/ccx_common_option.c @@ -138,6 +138,9 @@ void init_options (struct ccx_s_options *options) options->translate_key = NULL; options->translate_langs = NULL; #endif //ENABLE_SHARING +#ifdef WITH_LIBCURL + options->curlposturl = NULL; +#endif // Prepare time structures init_boundary_time (&options->extraction_start); diff --git a/src/lib_ccx/ccx_common_option.h b/src/lib_ccx/ccx_common_option.h index 72463ede..37e6f5fb 100644 --- a/src/lib_ccx/ccx_common_option.h +++ b/src/lib_ccx/ccx_common_option.h @@ -46,6 +46,7 @@ struct encoder_cfg int trim_subs; // " Remove spaces at sides? " int sentence_cap ; // FIX CASE? = Fix case? int splitbysentence; // Split text into complete sentences and prorate time? + char *curlposturl; // If out=curl, where do we send the data to? int with_semaphore; // Write a .sem file on file open and delete it on close? /* Credit stuff */ @@ -86,7 +87,6 @@ struct ccx_s_options // Options from user parameters struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process int print_file_reports; - ccx_decoder_608_settings settings_608; // Contains the settings for the 608 decoder. ccx_decoder_dtvcc_settings settings_dtvcc; //Same for 708 decoder @@ -163,6 +163,10 @@ struct ccx_s_options // Options from user parameters int cc_to_stdout; // If this is set to 1, the stdout will be flushed when data was written to the screen during a process_608 call. int multiprogram; int out_interval; +#ifdef WITH_LIBCURL + char *curlposturl; +#endif + #ifdef ENABLE_SHARING //CC sharing diff --git a/src/lib_ccx/ccx_decoders_common.c b/src/lib_ccx/ccx_decoders_common.c index 9f760c64..2c810de5 100644 --- a/src/lib_ccx/ccx_decoders_common.c +++ b/src/lib_ccx/ccx_decoders_common.c @@ -315,7 +315,8 @@ struct lib_cc_decode* init_cc_decode (struct ccx_decoders_common_settings_t *set setting->output_format==CCX_OF_SPUPNG || setting->output_format==CCX_OF_SIMPLE_XML || setting->output_format==CCX_OF_G608 || - setting->output_format==CCX_OF_NULL) + setting->output_format==CCX_OF_NULL || + setting->output_format==CCX_OF_CURL) ctx->writedata = process608; else fatal(CCX_COMMON_EXIT_BUG_BUG, "Invalid Write Format Selected"); diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index 83159f10..61210431 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -1125,6 +1125,11 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) case CCX_OF_SIMPLE_XML: wrote_something = write_cc_bitmap_as_simplexml(sub, context); break; +#ifdef WITH_LIBCURL + case CCX_OF_CURL: + wrote_something = write_cc_bitmap_as_libcurl(sub, context); + break; +#endif default: break; } diff --git a/src/lib_ccx/ccx_encoders_common.h b/src/lib_ccx/ccx_encoders_common.h index d5fa3e4c..f6776a7c 100644 --- a/src/lib_ccx/ccx_encoders_common.h +++ b/src/lib_ccx/ccx_encoders_common.h @@ -189,6 +189,7 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context int write_cc_bitmap_as_smptett(struct cc_subtitle *sub, struct encoder_ctx *context); int write_cc_bitmap_to_sentence_buffer(struct cc_subtitle *sub, struct encoder_ctx *context); +int write_cc_bitmap_as_libcurl(struct cc_subtitle *sub, struct encoder_ctx *context); int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *context); int write_cc_buffer_as_transcript2(struct eia608_screen *data, struct encoder_ctx *context); diff --git a/src/lib_ccx/ccx_encoders_curl.c b/src/lib_ccx/ccx_encoders_curl.c new file mode 100644 index 00000000..a4cee251 --- /dev/null +++ b/src/lib_ccx/ccx_encoders_curl.c @@ -0,0 +1,81 @@ +#ifdef WITH_LIBCURL +#include "ccx_decoders_common.h" +#include "ccx_encoders_common.h" +#include "spupng_encoder.h" +#include "ccx_encoders_spupng.h" +#include "utility.h" +#include "ocr.h" +#include "ccx_decoders_608.h" +#include "ccx_decoders_708.h" +#include "ccx_decoders_708_output.h" +#include "ccx_encoders_xds.h" +#include "ccx_encoders_helpers.h" +#include "utf8proc.h" + +int write_cc_bitmap_as_libcurl(struct cc_subtitle *sub, struct encoder_ctx *context) +{ + int ret = 0; +#ifdef ENABLE_OCR + struct cc_bitmap* rect; + LLONG ms_start, ms_end; + unsigned h1, m1, s1, ms1; + unsigned h2, m2, s2, ms2; + char timeline[128]; + int len = 0; + int used; + int i = 0; + char *str; + + if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER)) + { + ms_start = context->prev_start; + ms_end = sub->start_time; + } + else if (!(sub->flags & SUB_EOD_MARKER)) + { + ms_start = sub->start_time; + ms_end = sub->end_time; + } + else if (context->prev_start == -1 && (sub->flags & SUB_EOD_MARKER)) + { + ms_start = 1; + ms_end = sub->start_time; + } + + if (sub->nb_data == 0) + return 0; + + if (sub->flags & SUB_EOD_MARKER) + context->prev_start = sub->start_time; + + str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); + if (str) + { + if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) + { + mstotime(ms_start, &h1, &m1, &s1, &ms1); + mstotime(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. + context->srt_counter++; + sprintf(timeline, "group_id=ccextractordev&start_time=%llu&end_time=%llu&lang=en", ms_start, ms_end); + char *curlline = NULL; + curlline = str_reallocncat(curlline, timeline); + curlline = str_reallocncat(curlline, "&payload="); + curlline = str_reallocncat(curlline, str); + mprint("%s", curlline); + + + } + freep(&str); + } + for (i = 0, rect = sub->data; i < sub->nb_data; i++, rect++) + { + freep(rect->data); + freep(rect->data + 1); + } +#endif + sub->nb_data = 0; + freep(&sub->data); + return ret; + +} +#endif \ No newline at end of file diff --git a/src/lib_ccx/lib_ccx.c b/src/lib_ccx/lib_ccx.c index 482f0c61..2c521c87 100644 --- a/src/lib_ccx/lib_ccx.c +++ b/src/lib_ccx/lib_ccx.c @@ -351,7 +351,7 @@ struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct ca } extension = get_file_extension(ccx_options.enc_cfg.write_format); - if(!extension) + if (!extension && ccx_options.enc_cfg.write_format != CCX_OF_CURL) return NULL; if(ctx->multiprogram == CCX_FALSE) diff --git a/src/lib_ccx/lib_ccx.h b/src/lib_ccx/lib_ccx.h index df53d63e..4c0ec9fc 100644 --- a/src/lib_ccx/lib_ccx.h +++ b/src/lib_ccx/lib_ccx.h @@ -19,6 +19,11 @@ #include "networking.h" #include "avc_functions.h" + +#ifdef WITH_LIBCURL +// #include +#endif + //#include "ccx_decoders_708.h" /* Report information */ diff --git a/src/lib_ccx/params.c b/src/lib_ccx/params.c index dd81142d..6c5777df 100644 --- a/src/lib_ccx/params.c +++ b/src/lib_ccx/params.c @@ -221,6 +221,10 @@ void set_output_format (struct ccx_s_options *opt, const char *format) opt->write_format=CCX_OF_SIMPLE_XML; else if (strcmp (format,"g608")==0) opt->write_format=CCX_OF_G608; +#ifdef WITH_LIBCURL + else if (strcmp(format, "curl") == 0) + opt->write_format = CCX_OF_CURL; +#endif else fatal (EXIT_MALFORMED_PARAMETER, "Unknown output file format: %s\n", format); } @@ -2071,6 +2075,15 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) i++; continue; } +#ifdef WITH_LIBCURL + if (strcmp (argv[i],"-curlposturl")==0 && icurlposturl = argv[i + 1]; + i++; + continue; + } +#endif + #ifdef ENABLE_SHARING if (!strcmp(argv[i], "-enable-sharing")) { opt->sharing_enabled = 1; @@ -2188,6 +2201,16 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) mprint("Note: Output format is WebVTT, forcing UTF-8"); opt->enc_cfg.encoding = CCX_ENC_UTF_8; } + if (opt->write_format==CCX_OF_CURL && opt->curlposturl==NULL) + { + print_error(opt->gui_mode_reports, "You must pass a URL (-curlposturl) if output format is curl"); + return EXIT_INCOMPATIBLE_PARAMETERS; + } + if (opt->write_format != CCX_OF_CURL && opt->curlposturl != NULL) + { + print_error(opt->gui_mode_reports, "-curlposturl requires that the format is curl"); + return EXIT_INCOMPATIBLE_PARAMETERS; + } /* Initialize some Encoder Configuration */ opt->enc_cfg.extract = opt->extract; @@ -2213,5 +2236,8 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) opt->enc_cfg.output_filename = strdup(opt->output_filename); else opt->enc_cfg.output_filename = NULL; +#ifdef WITH_LIBCURL + opt->enc_cfg.curlposturl = opt->curlposturl; +#endif return EXIT_OK; } diff --git a/src/lib_ccx/utility.c b/src/lib_ccx/utility.c index 2b53baaa..52aa51e5 100644 --- a/src/lib_ccx/utility.c +++ b/src/lib_ccx/utility.c @@ -513,8 +513,10 @@ char *get_file_extension(enum ccx_output_format write_format) return strdup(".g608"); case CCX_OF_NULL: return NULL; + case CCX_OF_CURL: + return NULL; default: - mprint ("write_format doesn't have any legal value, this is a bug.\n"); + fatal (CCX_COMMON_EXIT_BUG_BUG, "write_format doesn't have any legal value, this is a bug.\n"); errno = EINVAL; return NULL; } @@ -591,6 +593,20 @@ LLONG change_timebase(LLONG val, struct ccx_rational cur_tb, struct ccx_rational return val; } +char *str_reallocncat(char *dst, char *src) +{ + int nl = dst==NULL? (strlen (src)+1) : (strlen(dst) + strlen(src) + 1); + char *orig = dst; + dst = (char *)realloc(dst, nl); + if (!dst) + return NULL; + if (orig == NULL) + strcpy(dst, src); + else + strcat(dst, src); + return dst; +} + #ifdef _WIN32 char *strndup(const char *s, size_t n) { diff --git a/src/lib_ccx/utility.h b/src/lib_ccx/utility.h index 6ad94445..c63ca8d3 100644 --- a/src/lib_ccx/utility.h +++ b/src/lib_ccx/utility.h @@ -30,6 +30,7 @@ char *create_outfilename(const char *basename, const char *suffix, const char *e int verify_crc32(uint8_t *buf, int len); size_t utf16_to_utf8(unsigned short utf16_char, unsigned char *out); LLONG change_timebase(LLONG val, struct ccx_rational cur_tb, struct ccx_rational dest_tb); +char *str_reallocncat(char *dst, char *src); void dump (LLONG mask, unsigned char *start, int l, unsigned long abs_start, unsigned clear_high_bit); #ifdef _WIN32 diff --git a/windows/ccextractor.vcxproj b/windows/ccextractor.vcxproj index 193fe444..544c47eb 100644 --- a/windows/ccextractor.vcxproj +++ b/windows/ccextractor.vcxproj @@ -184,6 +184,7 @@ + @@ -335,7 +336,7 @@ Disabled ../src/utf8proc;../src/win_spec_incld;../src/gpacmp4;../src/libpng;../src/zlib;../src;../src/lib_ccx;../src/zvbi;%(AdditionalIncludeDirectories) - ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) + WITH_LIBCURL;ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL diff --git a/windows/ccextractor.vcxproj.filters b/windows/ccextractor.vcxproj.filters index e9c44f6f..ce2ad3d3 100644 --- a/windows/ccextractor.vcxproj.filters +++ b/windows/ccextractor.vcxproj.filters @@ -755,6 +755,9 @@ Source Files\utf8proc + + Source Files\ccx_encoders +