Skip to content
Open
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)
-----------------
- IMPROVEMENT: Add default X-TIMESTAMP-MAP header for empty subtitle files in WebVTT for better compatibility of HLS streaming (#1743)
- Fix: HardSubX OCR on Rust
- Removed the Share Module
- Fix: Regression failures on DVD files
Expand Down
30 changes: 29 additions & 1 deletion src/ccextractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ License: GPL 2.0
#include "ccextractor.h"
#include <stdio.h>
#include <locale.h>
#include <ccx_encoders_helpers.h>

volatile int terminate_asap = 0;

Expand Down Expand Up @@ -138,10 +139,27 @@ int start_ccx()
#endif
terminate_asap = 0;

#ifdef ENABLE_SHARING
if (ccx_options.translate_enabled && ctx->num_input_files > 1)
{
mprint("[share] WARNING: simultaneous translation of several input files is not supported yet\n");
ccx_options.translate_enabled = 0;
ccx_options.sharing_enabled = 0;
}
if (ccx_options.translate_enabled)
{
mprint("[share] launching translate service\n");
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 (ccx_options.sharing_enabled)
ccx_share_start(ctx->basefilename);
#endif // ENABLE_SHARING

stream_mode = ctx->demux_ctx->get_stream_mode(ctx->demux_ctx);
// Disable sync check for raw formats - they have the right timeline.
Expand Down Expand Up @@ -293,6 +311,14 @@ int start_ccx()
dec_ctx->timing->fts_now = 0;
dec_ctx->timing->fts_max = 0;

#ifdef ENABLE_SHARING
if (ccx_options.sharing_enabled)
{
ccx_share_stream_done(ctx->basefilename);
ccx_share_stop();
}
#endif // ENABLE_SHARING

if (dec_ctx->total_pulldownframes)
mprint("incl. pulldown frames: %s (%u frames at %.2ffps)\n",
print_mstime_static((LLONG)(dec_ctx->total_pulldownframes * 1000 / current_fps)),
Expand Down Expand Up @@ -391,8 +417,10 @@ int start_ccx()
dinit_libraries(&ctx);

if (!ret)
{
webvtt_write_minimal_header();
mprint("\nNo captions were found in input.\n");

}
print_end_msg();

if (show_myth_banner)
Expand Down
11 changes: 11 additions & 0 deletions src/lib_ccx/ccx_common_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ struct ccx_s_options // Options from user parameters
#ifdef WITH_LIBCURL
char *curlposturl;
#endif


#ifdef ENABLE_SHARING
//CC sharing
int sharing_enabled;
char *sharing_url;
//Translating
int translate_enabled;
char *translate_langs;
char *translate_key;
#endif
};

extern struct ccx_s_options ccx_options;
Expand Down
35 changes: 35 additions & 0 deletions src/lib_ccx/ccx_encoders_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "ccx_common_constants.h"
#include "ccx_common_structs.h"
#include "ccx_decoders_common.h"
#include "ccx_encoders_common.h"
#include "utility.h"
#include "lib_ccx.h"

#include <assert.h>

Expand Down Expand Up @@ -487,3 +490,35 @@ void ccx_encoders_helpers_perform_shellsort_words(void)
shell_sort(capitalization_list.words, capitalization_list.len, sizeof(*capitalization_list.words), string_cmp_function, NULL);
shell_sort(profane.words, profane.len, sizeof(*profane.words), string_cmp_function, NULL);
}

void webvtt_write_minimal_header()
{
struct lib_ccx_ctx *ctx = NULL;
// Initialize CCExtractor libraries
ctx = init_libraries(&ccx_options);

struct encoder_ctx *enc_ctx = NULL;

if (ccx_options.write_format == CCX_OF_WEBVTT && ccx_options.timestamp_map)
{
// Initialize encoder with encoder_cfg
enc_ctx = init_encoder(&ccx_options.enc_cfg);

if (enc_ctx)
{
const char *xtimestamp_line = ccx_options.enc_cfg.line_terminator_lf
? "X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000\n\n"
: "X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000\r\n\r\n";

int used = encode_line(enc_ctx, enc_ctx->buffer, (unsigned char *)xtimestamp_line);

// fh is already an int fd
write_wrapped(enc_ctx->out->fh, (const char *)enc_ctx->buffer, used);

enc_ctx->wrote_webvtt_header = 1;

// Proper cleanup
dinit_encoder(&enc_ctx, 0);
}
}
}
2 changes: 2 additions & 0 deletions src/lib_ccx/ccx_encoders_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ void shell_sort(void *base, int nb, size_t size, int (*compar)(const void *p1, c

void ccx_encoders_helpers_perform_shellsort_words(void);
void ccx_encoders_helpers_setup(enum ccx_encoding_type encoding, int no_font_color, int no_type_setting, int trim_subs);

void webvtt_write_minimal_header(void);
#endif
Loading