diff --git a/src/lib_ccx/ccx_decoders_common.c b/src/lib_ccx/ccx_decoders_common.c index 329289027..b1975285b 100644 --- a/src/lib_ccx/ccx_decoders_common.c +++ b/src/lib_ccx/ccx_decoders_common.c @@ -15,7 +15,7 @@ made to reuse, not duplicate, as many functions as possible */ #include "ccx_encoders_mcc.h" #include "ccx_dtvcc.h" -uint64_t utc_refvalue = UINT64_MAX; /* _UI64_MAX means don't use UNIX, 0 = use current system time as reference, +1 use a specific reference */ +uint64_t utc_refvalue = UINT64_MAX; /* _UI64_MAX/UINT64_MAX means don't use UNIX, 0 = use current system time as reference, +1 use a specific reference */ extern int in_xds_mode; diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index 5a16df112..59efe28b8 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -693,13 +693,12 @@ static void try_to_add_end_credits(struct encoder_ctx *context, struct ccx_s_wri } } -void try_to_add_start_credits(struct encoder_ctx *context,LLONG start_ms) +void try_to_add_start_credits(struct encoder_ctx *context, LLONG start_ms) { LLONG st, end, window, length; - LLONG l = start_ms + context->subs_delay; - // We have a windows from last_displayed_subs_ms to l - we need to see if it fits + // We have a windows from last_displayed_subs_ms to start_ms - we need to see if it fits - if (l < context->startcreditsnotbefore.time_in_ms) // Too early + if (start_ms < context->startcreditsnotbefore.time_in_ms) // Too early return; if (context->last_displayed_subs_ms+1 > context->startcreditsnotafter.time_in_ms) // Too late @@ -708,8 +707,8 @@ void try_to_add_start_credits(struct encoder_ctx *context,LLONG start_ms) st = context->startcreditsnotbefore.time_in_ms>(context->last_displayed_subs_ms+1) ? context->startcreditsnotbefore.time_in_ms : (context->last_displayed_subs_ms+1); // When would credits actually start - end = context->startcreditsnotafter.time_in_ms<(l-1) ? - context->startcreditsnotafter.time_in_ms : (l-1); + end = context->startcreditsnotafter.time_in_ms < start_ms - 1 ? + context->startcreditsnotafter.time_in_ms : start_ms - 1; window = end-st; // Allowable time in MS @@ -720,7 +719,7 @@ void try_to_add_start_credits(struct encoder_ctx *context,LLONG start_ms) window : context->startcreditsforatmost.time_in_ms; dbg_print(CCX_DMT_VERBOSE, "Last subs: %lld Current position: %lld\n", - context->last_displayed_subs_ms, l); + context->last_displayed_subs_ms, start_ms); dbg_print(CCX_DMT_VERBOSE, "Not before: %lld Not after: %lld\n", context->startcreditsnotbefore.time_in_ms, context->startcreditsnotafter.time_in_ms); @@ -1099,6 +1098,11 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) return wrote_something; } + sub->start_time += context->subs_delay; + sub->end_time += context->subs_delay; + if (sub->start_time < 0) + return 0; + // Write subtitles as they come if (sub->type == CC_608) { @@ -1109,9 +1113,11 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) // Determine context based on channel. This replaces the code that was above, as this was incomplete (for cases where -12 was used for example) out = get_output_ctx(context, data->my_field); + data->end_time += context->subs_delay; + data->start_time += context->subs_delay; + if (data->format == SFORMAT_XDS) { - data->end_time = data->end_time + context->subs_delay; xds_write_transcript_line_prefix(context, out, data->start_time, data->end_time, data->cur_xds_packet_class); if (data->xds_len > 0) { @@ -1126,7 +1132,6 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) continue; } - data->end_time = data->end_time + context->subs_delay; if (utc_refvalue != UINT64_MAX) { @@ -1315,7 +1320,6 @@ void write_cc_buffer_to_gui(struct eia608_screen *data, struct encoder_ctx *cont { unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; - LLONG ms_start; int with_data = 0; for (int i = 0; i<15; i++) @@ -1326,11 +1330,6 @@ void write_cc_buffer_to_gui(struct eia608_screen *data, struct encoder_ctx *cont if (!with_data) return; - ms_start = data->start_time; - - ms_start += context->subs_delay; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return; int time_reported = 0; for (int i = 0; i<15; i++) { @@ -1339,9 +1338,8 @@ void write_cc_buffer_to_gui(struct eia608_screen *data, struct encoder_ctx *cont fprintf(stderr, "###SUBTITLE#"); if (!time_reported) { - LLONG ms_end = data->end_time; - 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(data->start_time, &h1, &m1, &s1, &ms1); + millis_to_time(data->end_time - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. // Note, only MM:SS here as we need to save space in the preview window fprintf(stderr, "%02u:%02u#%02u:%02u#", h1 * 60 + m1, s1, h2 * 60 + m2, s2); diff --git a/src/lib_ccx/ccx_encoders_curl.c b/src/lib_ccx/ccx_encoders_curl.c index cb85e82d1..90dc27966 100644 --- a/src/lib_ccx/ccx_encoders_curl.c +++ b/src/lib_ccx/ccx_encoders_curl.c @@ -18,7 +18,6 @@ int write_cc_bitmap_as_libcurl(struct cc_subtitle *sub, struct encoder_ctx *cont int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; char timeline[128]; diff --git a/src/lib_ccx/ccx_encoders_g608.c b/src/lib_ccx/ccx_encoders_g608.c index 436c6256c..ed350cccf 100644 --- a/src/lib_ccx/ccx_encoders_g608.c +++ b/src/lib_ccx/ccx_encoders_g608.c @@ -8,18 +8,10 @@ int write_cc_buffer_as_g608(struct eia608_screen *data, struct encoder_ctx *cont int used; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; - LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = data->start_time; - ms_start+=context->subs_delay; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - - ms_end = data->end_time; - - 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 (data->start_time,&h1,&m1,&s1,&ms1); + millis_to_time (data->end_time - 1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. char timeline[128]; context->srt_counter++; sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf); diff --git a/src/lib_ccx/ccx_encoders_python.c b/src/lib_ccx/ccx_encoders_python.c index 196e61c90..c5a422247 100644 --- a/src/lib_ccx/ccx_encoders_python.c +++ b/src/lib_ccx/ccx_encoders_python.c @@ -63,19 +63,11 @@ int pass_cc_buffer_to_python(struct eia608_screen *data, struct encoder_ctx *con { unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; - LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = data->start_time; char *timeline; - ms_start+=context->subs_delay; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - - ms_end = data->end_time; - - 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 (data->start_time,&h1,&m1,&s1,&ms1); + millis_to_time (data->end_time-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. context->srt_counter++; Asprintf(&timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u%s", diff --git a/src/lib_ccx/ccx_encoders_sami.c b/src/lib_ccx/ccx_encoders_sami.c index 31783de4d..34d3f5232 100644 --- a/src/lib_ccx/ccx_encoders_sami.c +++ b/src/lib_ccx/ccx_encoders_sami.c @@ -119,11 +119,6 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; - - ms_start = sub->start_time; - ms_end = sub->end_time; - rect = sub->data; @@ -137,7 +132,7 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context { sprintf(buf, "

\r\n" - , (unsigned long long)ms_start); + , (unsigned long long) sub->start_time); write(context->out->fh, buf, strlen(buf)); for (int i = sub->nb_data - 1; i >= 0; i--) { @@ -162,7 +157,7 @@ int write_cc_bitmap_as_sami(struct cc_subtitle *sub, struct encoder_ctx *context { sprintf(buf, "

 

\r\n\r\n" - , (unsigned long long)ms_start); + , (unsigned long long) sub->start_time); write(context->out->fh, buf, strlen(buf)); } #endif @@ -201,20 +196,11 @@ int write_cc_subtitle_as_sami(struct cc_subtitle *sub, struct encoder_ctx *conte int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *context) { int used; - LLONG startms, endms; int wrote_something=0; char str[1024]; - startms = data->start_time; - - startms+=context->subs_delay; - if (startms<0) // Drop screens that because of subs_delay start too early - return 0; - - endms = data->end_time; - endms--; // To prevent overlapping with next line. sprintf (str,"

\r\n", - (unsigned long long)startms); + (unsigned long long)data->start_time); if (context->encoding != CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str); @@ -247,7 +233,7 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct encoder_ctx *cont write (context->out->fh, context->buffer, used); sprintf ((char *) str, "

 

\r\n\r\n", - (unsigned long long)endms); + (unsigned long long)data->end_time - 1); // - 1 to prevent overlap if (context->encoding!=CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str); diff --git a/src/lib_ccx/ccx_encoders_smptett.c b/src/lib_ccx/ccx_encoders_smptett.c index 0733719b4..f32603ad6 100644 --- a/src/lib_ccx/ccx_encoders_smptett.c +++ b/src/lib_ccx/ccx_encoders_smptett.c @@ -112,13 +112,9 @@ int write_cc_bitmap_as_smptett(struct cc_subtitle *sub, struct encoder_ctx *cont int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; //char timeline[128]; int i,len = 0; - ms_start = sub->start_time; - ms_end = sub->end_time; - if(sub->nb_data == 0 ) return 0; @@ -136,8 +132,8 @@ int write_cc_bitmap_as_smptett(struct cc_subtitle *sub, struct encoder_ctx *cont char *buf = (char *)context->buffer; unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; - 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(sub->start_time, &h1, &m1, &s1, &ms1); + millis_to_time(sub->end_time - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. sprintf((char *)context->buffer, "

\n", h1, m1, s1, ms1, h2, m2, s2, ms2); write(context->out->fh, buf, strlen(buf)); len = strlen(rect[i].ocr_text); @@ -195,19 +191,11 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct encoder_ctx *c int used; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; - LLONG endms; int wrote_something=0; - LLONG startms = data->start_time; char str[1024]; - startms+=context->subs_delay; - if (startms<0) // Drop screens that because of subs_delay start too early - return 0; - - endms = data->end_time; - endms--; // To prevent overlapping with next line. - millis_to_time (startms,&h1,&m1,&s1,&ms1); - millis_to_time (endms-1,&h2,&m2,&s2,&ms2); + millis_to_time (data->start_time,&h1,&m1,&s1,&ms1); + millis_to_time (data->end_time-1,&h2,&m2,&s2,&ms2); for (int row=0; row < 15; row++) { diff --git a/src/lib_ccx/ccx_encoders_spupng.c b/src/lib_ccx/ccx_encoders_spupng.c index 2fc039a8e..80b2b3a35 100644 --- a/src/lib_ccx/ccx_encoders_spupng.c +++ b/src/lib_ccx/ccx_encoders_spupng.c @@ -993,15 +993,6 @@ int eia608_to_str(struct encoder_ctx *context, struct eia608_screen *data, char int spupng_write_string(struct spupng_t *sp, char *string, LLONG start_time, LLONG end_time, struct encoder_ctx *context) { - LLONG ms_start = start_time + context->subs_delay; - if (ms_start < 0) - { - dbg_print(CCX_DMT_VERBOSE, "Negative start\n"); - return 0; - } - - LLONG ms_end = end_time + context->subs_delay; - inc_spupng_fileindex(sp); if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL) { @@ -1017,7 +1008,7 @@ int spupng_write_string(struct spupng_t *sp, char *string, LLONG start_time, LLO } //free(string_utf32); fclose(sp->fppng); - write_sputag_open(sp, ms_start, ms_end); + write_sputag_open(sp, start_time, end_time); write_spucomment(sp, string); write_sputag_close(sp); return 1; @@ -1045,14 +1036,6 @@ int spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data, int empty_buf = 1; char str[512] = ""; - // Check if it has negative start. - LLONG ms_start = data->start_time + context->subs_delay; - if (ms_start < 0) - { - dbg_print(CCX_DMT_VERBOSE, "Negative start\n"); - return 0; - } - // Check if it is blank page. for (row = 0; row < 15; row++) { diff --git a/src/lib_ccx/ccx_encoders_srt.c b/src/lib_ccx/ccx_encoders_srt.c index 5a171ea78..399f0bf3d 100644 --- a/src/lib_ccx/ccx_encoders_srt.c +++ b/src/lib_ccx/ccx_encoders_srt.c @@ -18,11 +18,8 @@ int write_stringz_as_srt(char *string, struct encoder_ctx *context, LLONG ms_sta if(!string || !string[0]) return 0; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - - 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_start,&h1,&m1,&s1,&ms1); + millis_to_time(ms_end-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. context->srt_counter++; sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf); used = encode_line(context, context->buffer,(unsigned char *) timeline); @@ -86,7 +83,6 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context) int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; char timeline[128]; @@ -95,13 +91,7 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context) int i = 0; char *str; - ms_start = sub->start_time + context->subs_delay; - ms_end = sub->end_time + context->subs_delay; - - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - - if(sub->nb_data == 0 ) + if(sub->nb_data == 0) return 0; if(sub->flags & SUB_EOD_MARKER) @@ -116,8 +106,8 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context) } else { if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { - 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(sub->start_time,&h1,&m1,&s1,&ms1); + millis_to_time(sub->end_time - 1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. context->srt_counter++; sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf); used = encode_line(context, context->buffer,(unsigned char *) timeline); @@ -158,7 +148,7 @@ int write_cc_subtitle_as_srt(struct cc_subtitle *sub,struct encoder_ctx *context { if(sub->type == CC_TEXT) { - ret = write_stringz_as_srt(sub->data, context, sub->start_time + context->subs_delay, sub->end_time + context->subs_delay); + ret = write_stringz_as_srt(sub->data, context, sub->start_time, sub->end_time); freep(&sub->data); sub->nb_data = 0; ret = 1; @@ -180,9 +170,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte int used; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; - LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = data->start_time; int prev_line_start=-1, prev_line_end=-1; // Column in which the previous line started and ended, for autodash int prev_line_center1=-1, prev_line_center2=-1; // Center column of previous line text @@ -198,14 +186,8 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte if (empty_buf) // Prevent writing empty screens. Not needed in .srt return 0; - ms_start+=context->subs_delay; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - - ms_end = data->end_time; - - 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 (data->start_time,&h1,&m1,&s1,&ms1); + millis_to_time (data->end_time - 1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. char timeline[128]; context->srt_counter++; sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf); diff --git a/src/lib_ccx/ccx_encoders_ssa.c b/src/lib_ccx/ccx_encoders_ssa.c index d07d6c376..104ec8ba3 100644 --- a/src/lib_ccx/ccx_encoders_ssa.c +++ b/src/lib_ccx/ccx_encoders_ssa.c @@ -77,7 +77,6 @@ int write_cc_bitmap_as_ssa(struct cc_subtitle *sub, struct encoder_ctx *context) int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; char timeline[128]; @@ -86,9 +85,6 @@ int write_cc_bitmap_as_ssa(struct cc_subtitle *sub, struct encoder_ctx *context) int i = 0; char *str; - ms_start = sub->start_time; - ms_end = sub->end_time; - if (sub->nb_data == 0) return 0; @@ -111,8 +107,8 @@ int write_cc_bitmap_as_ssa(struct cc_subtitle *sub, struct encoder_ctx *context) } if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { - 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(sub->start_time, &h1,&m1,&s1,&ms1); + millis_to_time(sub->end_time - 1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. sprintf (timeline, "Dialogue: 0,%02u:%02u:%02u.%01u,%02u:%02u:%02u.%02u,Default,,0000,0000,0000,,", h1,m1,s1,ms1/10, h2,m2,s2,ms2/10); @@ -166,9 +162,7 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte int used; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; - LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = data->start_time; int prev_line_start=-1, prev_line_end=-1; // Column in which the previous line started and ended, for autodash int prev_line_center1=-1, prev_line_center2=-1; // Center column of previous line text @@ -184,14 +178,8 @@ int write_cc_buffer_as_ssa(struct eia608_screen *data, struct encoder_ctx *conte if (empty_buf) return 0; - ms_start+=context->subs_delay; - if (ms_start<0) - return 0; - - ms_end = data->end_time; - - 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 (data->start_time,&h1,&m1,&s1,&ms1); + millis_to_time (data->end_time - 1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. char timeline[128]; sprintf (timeline, "Dialogue: 0,%02u:%02u:%02u.%01u,%02u:%02u:%02u.%02u,Default,,0000,0000,0000,,", h1, m1, s1, ms1 / 10, h2, m2, s2, ms2 / 10); diff --git a/src/lib_ccx/ccx_encoders_transcript.c b/src/lib_ccx/ccx_encoders_transcript.c index 6c9d5727a..756f09c81 100644 --- a/src/lib_ccx/ccx_encoders_transcript.c +++ b/src/lib_ccx/ccx_encoders_transcript.c @@ -19,11 +19,6 @@ int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *c #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG start_time, end_time; - - start_time = sub->start_time; - end_time = sub->end_time; - if (sub->nb_data == 0) return ret; rect = sub->data; @@ -43,13 +38,13 @@ int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *c char buf1[80]; if (context->transcript_settings->relativeTimestamp) { - millis_to_date(start_time + context->subs_delay, buf1, context->date_format, context->millis_separator); + millis_to_date(sub->start_time, buf1, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf1); } else { - time_t start_time_int = (start_time + context->subs_delay) / 1000; - int start_time_dec = (start_time + context->subs_delay) % 1000; + time_t start_time_int = sub->start_time / 1000; + int start_time_dec = sub->start_time % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf1, context->millis_separator, start_time_dec); @@ -61,13 +56,13 @@ int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *c char buf2[80]; if (context->transcript_settings->relativeTimestamp) { - millis_to_date(end_time + context->subs_delay, buf2, context->date_format, context->millis_separator); + millis_to_date(sub->end_time, buf2, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf2); } else { - time_t end_time_int = (end_time + context->subs_delay) / 1000; - int end_time_dec = (end_time + context->subs_delay) % 1000; + time_t end_time_int = sub->end_time / 1000; + int end_time_dec = sub->end_time % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf2, context->millis_separator, end_time_dec); @@ -164,13 +159,13 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx char buf[80]; if (context->transcript_settings->relativeTimestamp) { - millis_to_date(start_time + context->subs_delay, buf, context->date_format, context->millis_separator); + millis_to_date(start_time, buf, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf); } else { - time_t start_time_int = (start_time + context->subs_delay) / 1000; - int start_time_dec = (start_time + context->subs_delay) % 1000; + time_t start_time_int = start_time / 1000; + int start_time_dec = start_time % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf, context->millis_separator, start_time_dec); @@ -182,13 +177,13 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx char buf[80]; if (context->transcript_settings->relativeTimestamp) { - millis_to_date(end_time + context->subs_delay, buf, context->date_format, context->millis_separator); + millis_to_date(end_time, buf, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf); } else { - time_t end_time_int = (end_time + context->subs_delay) / 1000; - int end_time_dec = (end_time + context->subs_delay) % 1000; + time_t end_time_int = end_time / 1000; + int end_time_dec = end_time % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf, context->millis_separator, end_time_dec); @@ -244,8 +239,6 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx *context, int line_number) { int ret = 0; - LLONG start_time = data->start_time; - LLONG end_time = data->end_time; correct_spelling_and_censor_words_608(context, line_number, data); @@ -271,12 +264,12 @@ void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx if (context->transcript_settings->showStartTime){ char buf1[80]; if (context->transcript_settings->relativeTimestamp){ - millis_to_date(start_time + context->subs_delay, buf1, context->date_format, context->millis_separator); + millis_to_date(data->start_time, buf1, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf1); } else { - time_t start_time_int = (start_time + context->subs_delay) / 1000; - int start_time_dec = (start_time + context->subs_delay) % 1000; + time_t start_time_int = data->start_time / 1000; + int start_time_dec = data->start_time % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf1, context->millis_separator, start_time_dec); @@ -286,12 +279,12 @@ void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx if (context->transcript_settings->showEndTime){ char buf2[80]; if (context->transcript_settings->relativeTimestamp){ - millis_to_date(end_time, buf2, context->date_format, context->millis_separator); + millis_to_date(data->end_time, buf2, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf2); } else { - time_t end_time_int = end_time / 1000; - int end_time_dec = end_time % 1000; + time_t end_time_int = data->end_time / 1000; + int end_time_dec = data->end_time % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf2, context->millis_separator, end_time_dec); diff --git a/src/lib_ccx/ccx_encoders_webvtt.c b/src/lib_ccx/ccx_encoders_webvtt.c index f1ac85945..1fb21457b 100644 --- a/src/lib_ccx/ccx_encoders_webvtt.c +++ b/src/lib_ccx/ccx_encoders_webvtt.c @@ -263,7 +263,6 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; - LLONG ms_start, ms_end; unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; char timeline[128]; @@ -272,9 +271,6 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte int i = 0; char *str; - ms_start = sub->start_time; - ms_end = sub->end_time; - if (sub->nb_data == 0) return 0; @@ -288,8 +284,8 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte { if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { - 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(sub->start_time, &h1, &m1, &s1, &ms1); + millis_to_time(sub->end_time - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. context->srt_counter++; // Not needed for WebVTT but let's keep it around for now sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u%s", h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf); @@ -402,9 +398,7 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co int written; unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; - LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = data->start_time; int empty_buf = 1; for (int i = 0; i<15; i++) @@ -418,16 +412,10 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co if (empty_buf) // Prevent writing empty screens. Not needed in .vtt return 0; - ms_start += context->subs_delay; - if (ms_start<0) // Drop screens that because of subs_delay start too early - return 0; - write_webvtt_header(context); - ms_end = data->end_time; - - 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(data->start_time, &h1, &m1, &s1, &ms1); + millis_to_time(data->end_time - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. for (int i = 0; i<15; i++) { diff --git a/src/lib_ccx/ccx_encoders_xds.c b/src/lib_ccx/ccx_encoders_xds.c index 18c3b6d69..2e930b869 100644 --- a/src/lib_ccx/ccx_encoders_xds.c +++ b/src/lib_ccx/ccx_encoders_xds.c @@ -35,20 +35,20 @@ void xds_write_transcript_line_prefix (struct encoder_ctx *context, struct ccx_s { if (utc_refvalue == UINT64_MAX) { - millis_to_time(start_time + context->subs_delay, &h1, &m1, &s1, &ms1); + millis_to_time(start_time, &h1, &m1, &s1, &ms1); fdprintf(wb->fh, "%02u:%02u:%02u%c%03u|", h1, m1, s1, context->millis_separator, ms1); } else { - fdprintf(wb->fh, "%lld%c%03d|", (start_time + context->subs_delay) / 1000, - context->millis_separator, (start_time + context->subs_delay) % 1000); + fdprintf(wb->fh, "%lld%c%03d|", start_time / 1000, + context->millis_separator, start_time % 1000); } } else { - millis_to_time(start_time + context->subs_delay, &h1, &m1, &s1, &ms1); - time_t start_time_int = (start_time + context->subs_delay) / 1000; - int start_time_dec = (start_time + context->subs_delay) % 1000; + millis_to_time(start_time, &h1, &m1, &s1, &ms1); + time_t start_time_int = start_time / 1000; + int start_time_dec = start_time % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S", start_time_struct); fdprintf(wb->fh, "%s%c%03d|", buffer, context->millis_separator, start_time_dec);