mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-09 02:16:41 +00:00
Initial libcurl integration work, linux only. Just groundwork, lots of dummy things yet.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
81
src/lib_ccx/ccx_encoders_curl.c
Normal file
81
src/lib_ccx/ccx_encoders_curl.c
Normal file
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
#include "networking.h"
|
||||
#include "avc_functions.h"
|
||||
|
||||
#ifdef WITH_LIBCURL
|
||||
// #include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
//#include "ccx_decoders_708.h"
|
||||
|
||||
/* Report information */
|
||||
|
||||
@@ -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 && i<argc-1)
|
||||
{
|
||||
opt->curlposturl = 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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -184,6 +184,7 @@
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_demuxer.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_dtvcc.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_common.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_curl.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_g608.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_helpers.c" />
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_sami.c" />
|
||||
@@ -335,7 +336,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>../src/utf8proc;../src/win_spec_incld;../src/gpacmp4;../src/libpng;../src/zlib;../src;../src/lib_ccx;../src/zvbi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WITH_LIBCURL;ENABLE_OCR;WIN32;_DEBUG;_CONSOLE;_FILE_OFFSET_BITS=64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
|
||||
@@ -755,6 +755,9 @@
|
||||
<ClCompile Include="..\src\utf8proc\utf8proc.c">
|
||||
<Filter>Source Files\utf8proc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\lib_ccx\ccx_encoders_curl.c">
|
||||
<Filter>Source Files\ccx_encoders</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\src\lib_ccx\ccx_sub_entry_message.proto">
|
||||
|
||||
Reference in New Issue
Block a user