mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2024-12-26 04:41:53 +00:00
Added PAC row positioning
This commit is contained in:
parent
4308247624
commit
f2b8b43bae
@ -935,7 +935,7 @@ struct encoder_ctx *init_encoder(struct encoder_cfg *opt)
|
|||||||
|
|
||||||
ctx->capacity=INITIAL_ENC_BUFFER_CAPACITY;
|
ctx->capacity=INITIAL_ENC_BUFFER_CAPACITY;
|
||||||
ctx->srt_counter = 0;
|
ctx->srt_counter = 0;
|
||||||
ctx->wrote_webvtt_sync_header = 0;
|
ctx->wrote_webvtt_header = 0;
|
||||||
|
|
||||||
ctx->program_number = opt->program_number;
|
ctx->program_number = opt->program_number;
|
||||||
ctx->send_to_srv = opt->send_to_srv;
|
ctx->send_to_srv = opt->send_to_srv;
|
||||||
|
@ -45,8 +45,8 @@ struct encoder_ctx
|
|||||||
/* keep count of srt subtitle*/
|
/* keep count of srt subtitle*/
|
||||||
unsigned int srt_counter;
|
unsigned int srt_counter;
|
||||||
|
|
||||||
/* Did we write the WebVTT sync header already? */
|
/* Did we write the WebVTT header already? */
|
||||||
unsigned int wrote_webvtt_sync_header;
|
unsigned int wrote_webvtt_header;
|
||||||
|
|
||||||
/* Input outputs */
|
/* Input outputs */
|
||||||
/* Flag giving hint that output is send to server through network */
|
/* Flag giving hint that output is send to server through network */
|
||||||
|
@ -115,6 +115,9 @@ static const char *webvtt_inline_css = "/* default values */\n"
|
|||||||
" background-color: rgba(0, 0, 0, 0.5);\n"
|
" background-color: rgba(0, 0, 0, 0.5);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
static const char** webvtt_pac_row_percent[] = { "10", "15.33", "20.66", "26", "31.33", "36.66", "42",
|
||||||
|
"47.33", "52.66", "58", "63.33", "68.66", "74", "79.33", "84.66" };
|
||||||
|
|
||||||
/* The timing here is not PTS based, but output based, i.e. user delay must be accounted for
|
/* The timing here is not PTS based, but output based, i.e. user delay must be accounted for
|
||||||
if there is any */
|
if there is any */
|
||||||
int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_start, LLONG ms_end)
|
int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_start, LLONG ms_end)
|
||||||
@ -198,9 +201,9 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_xtimestamp_header(struct encoder_ctx *context)
|
int write_webvtt_header(struct encoder_ctx *context)
|
||||||
{
|
{
|
||||||
if (context->wrote_webvtt_sync_header) // Already done
|
if (context->wrote_webvtt_header) // Already done
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (ccx_options.webvtt_create_css)
|
if (ccx_options.webvtt_create_css)
|
||||||
@ -242,7 +245,7 @@ int write_xtimestamp_header(struct encoder_ctx *context)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context->wrote_webvtt_sync_header = 1; // Do it even if couldn't write the header, because it won't be possible anyway
|
context->wrote_webvtt_header = 1; // Do it even if couldn't write the header, because it won't be possible anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +269,7 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte
|
|||||||
if (sub->nb_data == 0)
|
if (sub->nb_data == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
write_xtimestamp_header(context);
|
write_webvtt_header(context);
|
||||||
|
|
||||||
if (sub->flags & SUB_EOD_MARKER)
|
if (sub->flags & SUB_EOD_MARKER)
|
||||||
context->prev_start = sub->start_time;
|
context->prev_start = sub->start_time;
|
||||||
@ -425,7 +428,6 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
|||||||
ms_start = data->start_time;
|
ms_start = data->start_time;
|
||||||
|
|
||||||
int empty_buf = 1;
|
int empty_buf = 1;
|
||||||
char timeline[128] = "";
|
|
||||||
for (int i = 0; i<15; i++)
|
for (int i = 0; i<15; i++)
|
||||||
{
|
{
|
||||||
if (data->row_used[i])
|
if (data->row_used[i])
|
||||||
@ -441,28 +443,30 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
|||||||
if (ms_start<0) // Drop screens that because of subs_delay start too early
|
if (ms_start<0) // Drop screens that because of subs_delay start too early
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
write_xtimestamp_header(context);
|
write_webvtt_header(context);
|
||||||
|
|
||||||
ms_end = data->end_time;
|
ms_end = data->end_time;
|
||||||
|
|
||||||
millis_to_time(ms_start, &h1, &m1, &s1, &ms1);
|
millis_to_time(ms_start, &h1, &m1, &s1, &ms1);
|
||||||
millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line.
|
millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line.
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n");
|
|
||||||
dbg_print(CCX_DMT_DECODER_608, "%s", timeline);
|
|
||||||
|
|
||||||
written = write(context->out->fh, context->buffer, used);
|
|
||||||
if (written != used)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (int i = 0; i<15; i++)
|
for (int i = 0; i<15; i++)
|
||||||
{
|
{
|
||||||
if (data->row_used[i])
|
if (data->row_used[i])
|
||||||
{
|
{
|
||||||
|
char timeline[128] = "";
|
||||||
|
|
||||||
|
sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u line:%s%%%s",
|
||||||
|
h1, m1, s1, ms1, h2, m2, s2, ms2, webvtt_pac_row_percent[i], context->encoded_crlf);
|
||||||
|
used = encode_line(context, context->buffer, (unsigned char *)timeline);
|
||||||
|
|
||||||
|
dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n");
|
||||||
|
dbg_print(CCX_DMT_DECODER_608, "%s", timeline);
|
||||||
|
|
||||||
|
written = write(context->out->fh, context->buffer, used);
|
||||||
|
if (written != used)
|
||||||
|
return -1;
|
||||||
|
|
||||||
int length = get_line_encoded(context, context->subline, i, data);
|
int length = get_line_encoded(context, context->subline, i, data);
|
||||||
|
|
||||||
if (context->encoding != CCX_ENC_UNICODE)
|
if (context->encoding != CCX_ENC_UNICODE)
|
||||||
@ -544,14 +548,14 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
|
|||||||
if (written != context->encoded_crlf_length)
|
if (written != context->encoded_crlf_length)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
||||||
|
if (written != context->encoded_crlf_length)
|
||||||
|
return -1;
|
||||||
|
|
||||||
wrote_something = 1;
|
wrote_something = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
|
||||||
|
|
||||||
written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
|
|
||||||
if (written != context->encoded_crlf_length)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return wrote_something;
|
return wrote_something;
|
||||||
}
|
}
|
||||||
|
@ -1651,7 +1651,7 @@ int dvbsub_decode(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, co
|
|||||||
enc_ctx->prev_start = enc_ctx->prev->prev_start;
|
enc_ctx->prev_start = enc_ctx->prev->prev_start;
|
||||||
sub->prev->got_output = 0;
|
sub->prev->got_output = 0;
|
||||||
if (enc_ctx->write_format == CCX_OF_WEBVTT) { // we already wrote header, but since we encoded last sub, we must prevent multiple headers in future
|
if (enc_ctx->write_format == CCX_OF_WEBVTT) { // we already wrote header, but since we encoded last sub, we must prevent multiple headers in future
|
||||||
enc_ctx->wrote_webvtt_sync_header = 1;
|
enc_ctx->wrote_webvtt_header = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(enc_ctx->prev, enc_ctx, sizeof(struct encoder_ctx)); //we save the current encoder context
|
memcpy(enc_ctx->prev, enc_ctx, sizeof(struct encoder_ctx)); //we save the current encoder context
|
||||||
|
Loading…
Reference in New Issue
Block a user