Skip to content
Permalink
Browse files

[FIX] Remove webvtt styling when not using webvtt-full (#1092)

* no styling unless in full mode

* part 1 of moving style to here

* no style header unless requested with webvtt-full

* only one new line to support x-timestamp-map

* move x-timestamp-map up to abide by specifications

and support ffmpeg and brightcove

* remove stray new line, crlfs are added upstream

297 seems to contain a null bug

* don't write null characters to sub file

* needed space after -full mode style

* typo
  • Loading branch information...
rayfoss authored and cfsmp3 committed Jun 5, 2019
1 parent 9e212fa commit 403581462e8beb171b105b82ab8b60ace96b1695
Showing with 23 additions and 22 deletions.
  1. +1 −1 src/lib_ccx/ccx_encoders_common.c
  2. +22 −21 src/lib_ccx/ccx_encoders_webvtt.c
@@ -93,7 +93,7 @@ static const char *smptett_header = "<?xml version=\"1.0\" encoding=\"UTF-8\" st
" <body>\n"
" <div>\n";

static const char *webvtt_header[] = {"WEBVTT","\r\n","\r\n","STYLE","\r\n","\r\n",NULL};
static const char *webvtt_header[] = {"WEBVTT","\r\n",NULL};

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

@@ -8,7 +8,8 @@

static const char *webvtt_outline_css = "@import(%s)\n";

static const char *webvtt_inline_css = "/* default values */\n"
static const char *webvtt_inline_css = "\r\nSTYLE\n\n"
"/* default values */\n"
"::cue {\n"
" line-height: 5.33vh;\n"
" font-size: 4.1vh;\n"
@@ -207,6 +208,20 @@ int write_webvtt_header(struct encoder_ctx *context)
if (context->wrote_webvtt_header) // Already done
return 1;

if (context->timing->sync_pts2fts_set)
{
char header_string[200];
int used;
unsigned h1, m1, s1, ms1;
millis_to_time(context->timing->sync_pts2fts_fts, &h1, &m1, &s1, &ms1);
sprintf(header_string, "X-TIMESTAMP-MAP=MPEGTS:%ld, LOCAL %02u:%02u:%02u.%03u\r\n\n",
context->timing->sync_pts2fts_pts,
h1, m1, s1, ms1);
used = encode_line(context, context->buffer, (unsigned char *)header_string);
write(context->out->fh, context->buffer, used);

}

if (ccx_options.webvtt_create_css)
{
char *basefilename = get_basename(context->first_input_file);
@@ -225,7 +240,7 @@ int write_webvtt_header(struct encoder_ctx *context)
char* outline_css_file = (char*)malloc((strlen(css_file_name) + strlen(webvtt_outline_css)) * sizeof(char));
sprintf(outline_css_file, webvtt_outline_css, css_file_name);
write (context->out->fh, outline_css_file, strlen(outline_css_file));
} else {
} else if (ccx_options.use_webvtt_styling) {
write(context->out->fh, webvtt_inline_css, strlen(webvtt_inline_css));
if(ccx_options.enc_cfg.line_terminator_lf == 1) // If -lf parameter is set.
{
@@ -235,23 +250,8 @@ int write_webvtt_header(struct encoder_ctx *context)
{
write(context->out->fh,"\r\n",2);
}
}

write(context->out->fh, "##\n", 3);
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);

if (context->timing->sync_pts2fts_set)
{
char header_string[200];
int used;
unsigned h1, m1, s1, ms1;
millis_to_time(context->timing->sync_pts2fts_fts, &h1, &m1, &s1, &ms1);
sprintf(header_string, "X-TIMESTAMP-MAP=MPEGTS:%ld, LOCAL %02u:%02u:%02u.%03u\r\n\n",
context->timing->sync_pts2fts_pts,
h1, m1, s1, ms1);
used = encode_line(context, context->buffer, (unsigned char *)header_string);
write(context->out->fh, context->buffer, used);

write(context->out->fh, "##\n", 3);
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
}

context->wrote_webvtt_header = 1; // Do it even if couldn't write the header, because it won't be possible anyway
@@ -294,7 +294,7 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte
sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u%s",
h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf);
used = encode_line(context, context->buffer, (unsigned char *)timeline);
write(context->out->fh, context->buffer, used);
write(context->out->fh, context->buffer, used);
len = strlen(str);
write(context->out->fh, str, len);
write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
@@ -492,7 +492,8 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
}

// write current text symbol
write(context->out->fh, &(context->subline[j]), 1);
if (context->subline[j] != '\0')
write(context->out->fh, &(context->subline[j]), 1);

if (ccx_options.use_webvtt_styling)
{

0 comments on commit 4035814

Please sign in to comment.
You can’t perform that action at this time.