diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index f9249e45fe..1161dd69af 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -435,11 +435,24 @@ static void roll_up(CCaptionSubContext *ctx) static int capture_screen(CCaptionSubContext *ctx) { - int i; + int i, j, tab = 0; struct Screen *screen = ctx->screen + ctx->active_screen; enum cc_font prev_font = CCFONT_REGULAR; av_bprint_clear(&ctx->buffer); + for (i = 0; screen->row_used && i < SCREEN_ROWS; i++) + { + if (CHECK_FLAG(screen->row_used, i)) { + const char *row = screen->characters[i]; + const char *charset = screen->charsets[i]; + j = 0; + while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN) + j++; + if (!tab || j < tab) + tab = j; + } + } + for (i = 0; screen->row_used && i < SCREEN_ROWS; i++) { if (CHECK_FLAG(screen->row_used, i)) { @@ -447,12 +460,17 @@ static int capture_screen(CCaptionSubContext *ctx) const char *font = screen->fonts[i]; const char *charset = screen->charsets[i]; const char *override; - int j = 0; + int x, y, seen_char = 0; + j = 0; /* skip leading space */ - while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN) + while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN && j < tab) j++; + x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j); + y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i); + av_bprintf(&ctx->buffer, "{\\an7}{\\pos(%d,%d)}", x, y); + for (; j < SCREEN_COLUMNS; j++) { const char *e_tag = "", *s_tag = ""; @@ -487,9 +505,14 @@ static int capture_screen(CCaptionSubContext *ctx) override = charset_overrides[(int)charset[j]][(int)row[j]]; if (override) { av_bprintf(&ctx->buffer, "%s%s%s", e_tag, s_tag, override); + seen_char = 1; + } else if (row[j] == ' ' && !seen_char) { + av_bprintf(&ctx->buffer, "%s%s\\h", e_tag, s_tag); } else { av_bprintf(&ctx->buffer, "%s%s%c", e_tag, s_tag, row[j]); + seen_char = 1; } + } av_bprintf(&ctx->buffer, "\\N"); } diff --git a/tests/ref/fate/sub-cc b/tests/ref/fate/sub-cc index 0d5bc77611..4cc02d1d17 100644 --- a/tests/ref/fate/sub-cc +++ b/tests/ref/fate/sub-cc @@ -10,5 +10,5 @@ Style: Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,3,1,0, [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text -Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} ) -Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our number one +Dialogue: 0,0:00:12.36,0:00:40.83,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio chatter{\i0} ) +Dialogue: 0,0:00:40.83,0:00:59.07,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number one diff --git a/tests/ref/fate/sub-cc-realtime b/tests/ref/fate/sub-cc-realtime index c9e6b6c661..be800a4d29 100644 --- a/tests/ref/fate/sub-cc-realtime +++ b/tests/ref/fate/sub-cc-realtime @@ -10,33 +10,33 @@ Style: Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,3,1,0, [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text -Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,( -Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,({\i1} in -Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,({\i1} inau -Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,({\i1} inaudi -Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,({\i1} inaudibl -Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,({\i1} inaudible -Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,({\i1} inaudible ra -Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radi -Dialogue: 0,0:00:18.59,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio -Dialogue: 0,0:00:19.03,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio ch -Dialogue: 0,0:00:19.48,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chat -Dialogue: 0,0:00:19.92,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatte -Dialogue: 0,0:00:20.36,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter -Dialogue: 0,0:00:21.70,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} ) -Dialogue: 0,0:00:42.61,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> -Dialogue: 0,0:00:43.05,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> S -Dialogue: 0,0:00:43.50,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Saf -Dialogue: 0,0:00:43.94,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safet -Dialogue: 0,0:00:44.39,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety -Dialogue: 0,0:00:44.83,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety re -Dialogue: 0,0:00:45.28,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety rema -Dialogue: 0,0:00:45.72,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remain -Dialogue: 0,0:00:46.17,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains -Dialogue: 0,0:00:46.61,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains ou -Dialogue: 0,0:00:47.06,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our -Dialogue: 0,0:00:47.50,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our nu -Dialogue: 0,0:00:47.95,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our numb -Dialogue: 0,0:00:48.39,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our number -Dialogue: 0,0:00:48.84,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our number o -Dialogue: 0,0:00:49.28,9:59:59.99,Default,,0,0,0,,({\i1} inaudible radio chatter{\i0} )\N>> Safety remains our number one +Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}( +Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} in +Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inau +Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudi +Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudibl +Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible +Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible ra +Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radi +Dialogue: 0,0:00:18.59,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio +Dialogue: 0,0:00:19.03,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio ch +Dialogue: 0,0:00:19.48,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio chat +Dialogue: 0,0:00:19.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio chatte +Dialogue: 0,0:00:20.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio chatter +Dialogue: 0,0:00:21.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} inaudible radio chatter{\i0} ) +Dialogue: 0,0:00:42.61,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> +Dialogue: 0,0:00:43.05,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> S +Dialogue: 0,0:00:43.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Saf +Dialogue: 0,0:00:43.94,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safet +Dialogue: 0,0:00:44.39,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety +Dialogue: 0,0:00:44.83,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety re +Dialogue: 0,0:00:45.28,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety rema +Dialogue: 0,0:00:45.72,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remain +Dialogue: 0,0:00:46.17,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains +Dialogue: 0,0:00:46.61,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains ou +Dialogue: 0,0:00:47.06,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our +Dialogue: 0,0:00:47.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our nu +Dialogue: 0,0:00:47.95,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our numb +Dialogue: 0,0:00:48.39,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number +Dialogue: 0,0:00:48.84,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number o +Dialogue: 0,0:00:49.28,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number one