int write_cc_subtitle_as_srt(struct cc_subtitle *sub,struct encoder_ctx *context) { int ret = 0; struct cc_subtitle *osub = sub; struct cc_subtitle *lsub = sub; while(sub) { if(sub->type == CC_TEXT) { ret = write_stringz_as_srt(sub->data, context, sub->start_time, sub->end_time); freep(&sub->data); sub->nb_data = 0; } lsub = sub; sub = sub->next; } while(lsub != osub) { sub = lsub->prev; freep(&lsub); lsub = sub; } return ret; }
void try_to_add_end_credits(struct encoder_ctx *context, struct ccx_s_write *out) { LLONG window, length, st, end; if (out->fh == -1) return; window=get_fts()-context->last_displayed_subs_ms-1; if (window < context->endcreditsforatleast.time_in_ms) // Won't happen, window is too short return; length=context->endcreditsforatmost.time_in_ms > window ? window : context->endcreditsforatmost.time_in_ms; st=get_fts()-length-1; end=get_fts(); switch (context->write_format) { case CCX_OF_SRT: write_stringz_as_srt(context->end_credits_text, context, st, end); break; case CCX_OF_WEBVTT: write_stringz_as_webvtt(context->end_credits_text, context, st, end); break; case CCX_OF_SAMI: write_stringz_as_sami(context->end_credits_text, context, st, end); break; case CCX_OF_SMPTETT: write_stringz_as_smptett(context->end_credits_text, context, st, end); break ; default: // Do nothing for the rest break; } }
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 if (l<ccx_options.startcreditsnotbefore.time_in_ms) // Too early return; if (context->last_displayed_subs_ms+1 > ccx_options.startcreditsnotafter.time_in_ms) // Too late return; st = ccx_options.startcreditsnotbefore.time_in_ms>(context->last_displayed_subs_ms+1) ? ccx_options.startcreditsnotbefore.time_in_ms : (context->last_displayed_subs_ms+1); // When would credits actually start end = ccx_options.startcreditsnotafter.time_in_ms<(l-1) ? ccx_options.startcreditsnotafter.time_in_ms : (l-1); window = end-st; // Allowable time in MS if (ccx_options.startcreditsforatleast.time_in_ms>window) // Window is too short return; length=ccx_options.startcreditsforatmost.time_in_ms > window ? window : ccx_options.startcreditsforatmost.time_in_ms; dbg_print(CCX_DMT_VERBOSE, "Last subs: %lld Current position: %lld\n", context->last_displayed_subs_ms, l); dbg_print(CCX_DMT_VERBOSE, "Not before: %lld Not after: %lld\n", ccx_options.startcreditsnotbefore.time_in_ms, ccx_options.startcreditsnotafter.time_in_ms); dbg_print(CCX_DMT_VERBOSE, "Start of window: %lld End of window: %lld\n",st,end); if (window>length+2) { // Center in time window LLONG pad=window-length; st+=(pad/2); } end=st+length; switch (ccx_options.write_format) { case CCX_OF_SRT: write_stringz_as_srt(ccx_options.start_credits_text,context,st,end); break; case CCX_OF_SAMI: write_stringz_as_sami(ccx_options.start_credits_text, context, st, end); break; case CCX_OF_SMPTETT: write_stringz_as_smptett(ccx_options.start_credits_text, context, st, end); break; default: // Do nothing for the rest break; } context->startcredits_displayed=1; return; }