Skip to content

Commit acc40f3

Browse files
committed
feat: add default X-TIMESTAMP-MAP header for empty subtitle files in WebVTT for HLS compatibility
1 parent 3f44115 commit acc40f3

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

docs/CHANGES.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.0 (to be released)
22
-----------------
3+
- IMPROVEMENT: Add default X-TIMESTAMP-MAP header for empty subtitle files in WebVTT for better compatibility of HLS streaming (#1743)
34
- Fix: HardSubX OCR on Rust
45
- Removed the Share Module
56
- Fix: Regression failures on DVD files

src/ccextractor.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ License: GPL 2.0
66
#include "ccextractor.h"
77
#include <stdio.h>
88
#include <locale.h>
9+
#include <ccx_encoders_helpers.h>
910

1011
volatile int terminate_asap = 0;
1112

@@ -138,10 +139,27 @@ int start_ccx()
138139
#endif
139140
terminate_asap = 0;
140141

142+
#ifdef ENABLE_SHARING
143+
if (ccx_options.translate_enabled && ctx->num_input_files > 1)
144+
{
145+
mprint("[share] WARNING: simultaneous translation of several input files is not supported yet\n");
146+
ccx_options.translate_enabled = 0;
147+
ccx_options.sharing_enabled = 0;
148+
}
149+
if (ccx_options.translate_enabled)
150+
{
151+
mprint("[share] launching translate service\n");
152+
ccx_share_launch_translator(ccx_options.translate_langs, ccx_options.translate_key);
153+
}
154+
#endif // ENABLE_SHARING
141155
ret = 0;
142156
while (switch_to_next_file(ctx, 0))
143157
{
144158
prepare_for_new_file(ctx);
159+
#ifdef ENABLE_SHARING
160+
if (ccx_options.sharing_enabled)
161+
ccx_share_start(ctx->basefilename);
162+
#endif // ENABLE_SHARING
145163

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

314+
#ifdef ENABLE_SHARING
315+
if (ccx_options.sharing_enabled)
316+
{
317+
ccx_share_stream_done(ctx->basefilename);
318+
ccx_share_stop();
319+
}
320+
#endif // ENABLE_SHARING
321+
296322
if (dec_ctx->total_pulldownframes)
297323
mprint("incl. pulldown frames: %s (%u frames at %.2ffps)\n",
298324
print_mstime_static((LLONG)(dec_ctx->total_pulldownframes * 1000 / current_fps)),
@@ -391,8 +417,10 @@ int start_ccx()
391417
dinit_libraries(&ctx);
392418

393419
if (!ret)
420+
{
421+
webvtt_write_minimal_header();
394422
mprint("\nNo captions were found in input.\n");
395-
423+
}
396424
print_end_msg();
397425

398426
if (show_myth_banner)

src/lib_ccx/ccx_common_option.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ struct ccx_s_options // Options from user parameters
198198
#ifdef WITH_LIBCURL
199199
char *curlposturl;
200200
#endif
201+
202+
203+
#ifdef ENABLE_SHARING
204+
//CC sharing
205+
int sharing_enabled;
206+
char *sharing_url;
207+
//Translating
208+
int translate_enabled;
209+
char *translate_langs;
210+
char *translate_key;
211+
#endif
201212
};
202213

203214
extern struct ccx_s_options ccx_options;

src/lib_ccx/ccx_encoders_helpers.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "ccx_common_constants.h"
44
#include "ccx_common_structs.h"
55
#include "ccx_decoders_common.h"
6+
#include "ccx_encoders_common.h"
7+
#include "utility.h"
8+
#include "lib_ccx.h"
69

710
#include <assert.h>
811

@@ -487,3 +490,33 @@ void ccx_encoders_helpers_perform_shellsort_words(void)
487490
shell_sort(capitalization_list.words, capitalization_list.len, sizeof(*capitalization_list.words), string_cmp_function, NULL);
488491
shell_sort(profane.words, profane.len, sizeof(*profane.words), string_cmp_function, NULL);
489492
}
493+
494+
void webvtt_write_minimal_header()
495+
{
496+
struct lib_ccx_ctx *ctx = NULL;
497+
// Initialize CCExtractor libraries
498+
ctx = init_libraries(&ccx_options);
499+
500+
struct encoder_ctx *enc_ctx = NULL;
501+
502+
if (ccx_options.write_format == CCX_OF_WEBVTT && ccx_options.timestamp_map) {
503+
// Initialize encoder with encoder_cfg
504+
enc_ctx = init_encoder(&ccx_options.enc_cfg);
505+
506+
if (enc_ctx) {
507+
const char *xtimestamp_line = ccx_options.enc_cfg.line_terminator_lf
508+
? "X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000\n\n"
509+
: "X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000\r\n\r\n";
510+
511+
int used = encode_line(enc_ctx, enc_ctx->buffer, (unsigned char *)xtimestamp_line);
512+
513+
// fh is already an int fd
514+
write_wrapped(enc_ctx->out->fh, (const char *)enc_ctx->buffer, used);
515+
516+
enc_ctx->wrote_webvtt_header = 1;
517+
518+
// Proper cleanup
519+
dinit_encoder(&enc_ctx, 0);
520+
}
521+
}
522+
}

src/lib_ccx/ccx_encoders_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ void shell_sort(void *base, int nb, size_t size, int (*compar)(const void *p1, c
4949

5050
void ccx_encoders_helpers_perform_shellsort_words(void);
5151
void ccx_encoders_helpers_setup(enum ccx_encoding_type encoding, int no_font_color, int no_type_setting, int trim_subs);
52+
53+
void webvtt_write_minimal_header(void);
5254
#endif

0 commit comments

Comments
 (0)