Skip to content

Commit 492f0d5

Browse files
authored
[FIX] WebVTT X-TIMESTAMP-MAP header placement (#1463) (#1464)
* [FIX] WebVTT X-TIMESTAMP-MAP header placement (#1463) * Fixed --no-timestamp-map flag * Disable X-TIMESTAMP-MAP by default * X-TIMESTAMP-MAP is only part of the HLS spec, and is not valid WebVTT, so it should be disabled by default. * Write second WebVTT newline when timing info is missing
1 parent 4b0928a commit 492f0d5

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

docs/CHANGES.TXT

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
- Fix: segmentation fault in using hardsubx
66
- New: Add function (and command) that extracts closed caption subtitles as well as burnt-in subtitles from a file in a single pass. (As proposed in issue 726)
77
- Refactored: the `general_loop` function has some code moved to a new function
8-
8+
- Fix: WebVTT X-TIMESTAMP-MAP placement (#1463)
9+
- Disable X-TIMESTAMP-MAP by default (changed option --no-timestamp-map to --timestamp-map)
910

1011
0.94 (2021-12-14)
1112
-----------------

src/lib_ccx/ccx_common_option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void init_options(struct ccx_s_options *options)
4141
options->live_stream = 0; // 0 -> A regular file
4242
options->messages_target = 1; // 1=stdout
4343
options->print_file_reports = 0;
44-
options->no_timestamp_map = 0; // Enable timestamps by default
44+
options->timestamp_map = 0; // Disable X-TIMESTAMP-MAP header by default
4545

4646
/* Levenshtein's parameters, for string comparison */
4747
options->dolevdist = 1; // By default attempt to correct typos

src/lib_ccx/ccx_common_option.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct encoder_cfg
3737
int force_flush; // Force flush on content write
3838
int append_mode; // Append mode for output files
3939
int ucla; // 1 if -UCLA used, 0 if not
40-
int no_timestamp_map; // 1 if timestamps disabled for WebVTT
4140

4241
enum ccx_encoding_type encoding;
4342
enum ccx_output_date_format date_format;
@@ -118,7 +117,7 @@ struct ccx_s_options // Options from user parameters
118117
>0 -> Live stream with a timeout of this value in seconds */
119118
char *filter_profanity_file; // Extra profanity word file
120119
int messages_target; // 0 = nowhere (quiet), 1=stdout, 2=stderr
121-
int no_timestamp_map; // 1 for no timestamps for WebVTT, 0 for the timestamp header
120+
int timestamp_map; // If 1, add WebVTT X-TIMESTAMP-MAP header
122121
/* Levenshtein's parameters, for string comparison */
123122
int dolevdist; // 0 => don't attempt to correct typos with this algorithm
124123
int levdistmincnt, levdistmaxpct; // Means 2 fails or less is "the same", 10% or less is also "the same"

src/lib_ccx/ccx_encoders_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static const char *smptett_header = "<?xml version=\"1.0\" encoding=\"UTF-8\" st
9292
" <body>\n"
9393
" <div>\n";
9494

95-
static const char *webvtt_header[] = {"WEBVTT", "\r\n", "\r\n", NULL};
95+
static const char *webvtt_header[] = {"WEBVTT", "\r\n", NULL};
9696

9797
static const char *simple_xml_header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<captions>\r\n";
9898

@@ -962,7 +962,6 @@ struct encoder_ctx *init_encoder(struct encoder_cfg *opt)
962962
ctx->srt_counter = 0;
963963
ctx->cea_708_counter = 0;
964964
ctx->wrote_webvtt_header = 0;
965-
ctx->no_timestamp_map = opt->no_timestamp_map;
966965
ctx->wrote_ccd_channel_header = false;
967966

968967
ctx->program_number = opt->program_number;

src/lib_ccx/ccx_encoders_common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ struct encoder_ctx
8989
int force_flush;
9090
/* Keep track of whether -UCLA used */
9191
int ucla;
92-
/* Disable timestamps for WebVTT */
93-
int no_timestamp_map;
9492

9593
struct ccx_common_timing_ctx *timing; /* Some encoders need access to PTS, such as WebVTT */
9694

src/lib_ccx/ccx_encoders_webvtt.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,33 @@ void write_webvtt_header(struct encoder_ctx *context)
207207
if (context->wrote_webvtt_header) // Already done
208208
return;
209209

210-
if (context->timing != NULL && context->timing->sync_pts2fts_set)
210+
if (ccx_options.timestamp_map && context->timing != NULL && context->timing->sync_pts2fts_set)
211211
{
212212
char header_string[200];
213213
int used;
214214
unsigned h1, m1, s1, ms1;
215215
millis_to_time(context->timing->sync_pts2fts_fts, &h1, &m1, &s1, &ms1);
216216

217-
// If the user has not disabled X-TIMESTAMP-MAP
218-
if (!context->no_timestamp_map)
219-
{
220-
sprintf(header_string, "X-TIMESTAMP-MAP=MPEGTS:%ld,LOCAL:%02u:%02u:%02u.%03u%s",
221-
context->timing->sync_pts2fts_pts, h1, m1, s1, ms1,
222-
ccx_options.enc_cfg.line_terminator_lf ? "\n\n" : "\r\n\r\n");
223-
}
217+
// If the user has enabled X-TIMESTAMP-MAP
218+
sprintf(header_string, "X-TIMESTAMP-MAP=MPEGTS:%ld,LOCAL:%02u:%02u:%02u.%03u%s",
219+
context->timing->sync_pts2fts_pts, h1, m1, s1, ms1,
220+
ccx_options.enc_cfg.line_terminator_lf ? "\n\n" : "\r\n\r\n");
221+
224222
used = encode_line(context, context->buffer, (unsigned char *)header_string);
225223
write_wrapped(context->out->fh, context->buffer, used);
226224
}
225+
else
226+
{
227+
// Must have another newline if X-TIMESTAMP-MAP is not used
228+
if (ccx_options.enc_cfg.line_terminator_lf == 1) // If -lf parameter is set.
229+
{
230+
write_wrapped(context->out->fh, "\n", 1);
231+
}
232+
else
233+
{
234+
write_wrapped(context->out->fh, "\r\n", 2);
235+
}
236+
}
227237

228238
if (ccx_options.webvtt_create_css)
229239
{

src/lib_ccx/params.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void print_usage(void)
568568
mprint(" less or equal than the max allowed..\n");
569569
mprint("-anvid --analyzevideo Analyze the video stream even if it's not used for\n");
570570
mprint(" subtitles. This allows to provide video information.\n");
571-
mprint(" --no-timestamp-map Use this flag to disable the X-TIMESTAMP-MAP header for WebVTT\n");
571+
mprint(" --timestamp-map Enable the X-TIMESTAMP-MAP header for WebVTT (HLS)\n");
572572
mprint("Levenshtein distance:\n\n");
573573
mprint(" When processing teletext files CCExtractor tries to correct typos by\n");
574574
mprint(" comparing consecutive lines. If line N+1 is almost identical to line N except\n");
@@ -1528,9 +1528,9 @@ int parse_parameters(struct ccx_s_options *opt, int argc, char *argv[])
15281528
continue;
15291529
}
15301530

1531-
if (strcmp(argv[i], "--no-timestamp-map") == 0 || strcmp(argv[i], "-ntm") == 0)
1531+
if (strcmp(argv[i], "--timestamp-map") == 0 || strcmp(argv[i], "-tm") == 0)
15321532
{
1533-
opt->no_timestamp_map = 1;
1533+
opt->timestamp_map = 1;
15341534
continue;
15351535
}
15361536

0 commit comments

Comments
 (0)