--- libavcodec/Makefile | 2 +- libavcodec/samidec.c | 38 ++++++++++++++++++++++++++------------ tests/ref/fate/sub-sami | 18 +++++++++--------- 3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index d1ffb12..1045d7a 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -450,7 +450,7 @@ OBJS-$(CONFIG_RV20_DECODER) += rv10.o OBJS-$(CONFIG_RV20_ENCODER) += rv20enc.o OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv40dsp.o -OBJS-$(CONFIG_SAMI_DECODER) += samidec.o ass.o +OBJS-$(CONFIG_SAMI_DECODER) += samidec.o ass.o htmlsubtitles.o OBJS-$(CONFIG_S302M_DECODER) += s302m.o OBJS-$(CONFIG_S302M_ENCODER) += s302menc.o OBJS-$(CONFIG_SANM_DECODER) += sanm.o diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c index 47850e2..50fde4f 100644 --- a/libavcodec/samidec.c +++ b/libavcodec/samidec.c @@ -27,10 +27,13 @@ #include "ass.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" +#include "htmlsubtitles.h" typedef struct { AVBPrint source; AVBPrint content; + AVBPrint encoded_source; + AVBPrint encoded_content; AVBPrint full; } SAMIContext; @@ -41,8 +44,12 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) char *tag = NULL; char *dupsrc = av_strdup(src); char *p = dupsrc; + AVBPrint *dst_content = &sami->encoded_content; + AVBPrint *dst_source = &sami->encoded_source; + av_bprint_clear(&sami->encoded_content); av_bprint_clear(&sami->content); + av_bprint_clear(&sami->encoded_source); for (;;) { char *saveptr = NULL; int prev_chr_is_space = 0; @@ -82,18 +89,18 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) if (*p == '<') { if (!av_strncasecmp(p, "<P", 2) && (p[2] == '>' || av_isspace(p[2]))) break; - if (!av_strncasecmp(p, "<BR", 3)) + } + if (!av_strncasecmp(p, "<BR", 3)) { av_bprintf(dst, "\\N"); - p++; - while (*p && *p != '>') - p++; - if (!*p) - break; - if (*p == '>') + p += 3; + while (*p && *p != '>') + p++; p++; - continue; } - if (!av_isspace(*p)) + if (*p == '\n') { + av_bprintf(dst, "\\N"); + } + else if (!av_isspace(*p)) av_bprint_chars(dst, *p, 1); else if (!prev_chr_is_space) av_bprint_chars(dst, ' ', 1); @@ -103,9 +110,12 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) } av_bprint_clear(&sami->full); - if (sami->source.len) - av_bprintf(&sami->full, "{\\i1}%s{\\i0}\\N", sami->source.str); - av_bprintf(&sami->full, "%s", sami->content.str); + if (sami->source.len) { + ff_htmlmarkup_to_ass(avctx, dst_source, sami->source.str); + av_bprintf(&sami->full, "{\\i1}%s{\\i0}\\N", sami->encoded_source.str); + } + ff_htmlmarkup_to_ass(avctx, dst_content, sami->content.str); + av_bprintf(&sami->full, "%s", sami->encoded_content.str); end: av_free(dupsrc); @@ -136,6 +146,8 @@ static av_cold int sami_init(AVCodecContext *avctx) SAMIContext *sami = avctx->priv_data; av_bprint_init(&sami->source, 0, 2048); av_bprint_init(&sami->content, 0, 2048); + av_bprint_init(&sami->encoded_source, 0, 2048); + av_bprint_init(&sami->encoded_content, 0, 2048); av_bprint_init(&sami->full, 0, 2048); return ff_ass_subtitle_header_default(avctx); } @@ -145,6 +157,8 @@ static av_cold int sami_close(AVCodecContext *avctx) SAMIContext *sami = avctx->priv_data; av_bprint_finalize(&sami->source, NULL); av_bprint_finalize(&sami->content, NULL); + av_bprint_finalize(&sami->encoded_source, NULL); + av_bprint_finalize(&sami->encoded_content, NULL); av_bprint_finalize(&sami->full, NULL); return 0; } diff --git a/tests/ref/fate/sub-sami b/tests/ref/fate/sub-sami index caa85a2..9eabbd7 100644 --- a/tests/ref/fate/sub-sami +++ b/tests/ref/fate/sub-sami @@ -10,12 +10,12 @@ Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text -Dialogue: 0,0:00:00.00,0:00:00.01,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\N -Dialogue: 0,0:00:00.01,0:00:08.80,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\NLet the word go forth, from this time and place to friend and foe alike that the torch -Dialogue: 0,0:00:08.80,0:00:19.50,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\Nhas been passed to a new generation of Americans, born in this century, tempered by war, -Dialogue: 0,0:00:19.50,0:00:28.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\Ndisciplined by a hard and bitter peace, proud of our ancient heritage, and unwilling to witness -Dialogue: 0,0:00:28.00,0:00:38.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\Nor permit the slow undoing of those human rights to which this nation has always -Dialogue: 0,0:00:38.00,0:00:46.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\Nbeen committed and to which we are committed today at home and around the world. -Dialogue: 0,0:00:46.00,0:01:01.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\NLet every nation know, whether it wishes us well or ill, that we shall pay any price, bear any burden, -Dialogue: 0,0:01:01.00,0:01:13.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy {\i0}\Nmeet any hardship, support any friend, oppose any foe, to ensure the survival and success of liberty. -Dialogue: 0,0:01:13.00,9:59:59.99,Default,,0,0,0,,{\i1}End of: {\i0}\NPresident John F. Kennedy Speech +Dialogue: 0,0:00:00.00,0:00:00.01,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\N +Dialogue: 0,0:00:00.01,0:00:08.80,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\NLet the word go forth,\Nfrom this time and place to friend and foe\Nalike that the torch +Dialogue: 0,0:00:08.80,0:00:19.50,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\Nhas been passed to a new generation of Americans,\Nborn in this century, tempered by war, +Dialogue: 0,0:00:19.50,0:00:28.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\Ndisciplined by a hard and bitter peace,\Nproud of our ancient heritage, and unwilling to witness +Dialogue: 0,0:00:28.00,0:00:38.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\Nor permit the slow undoing of those human rights\Nto which this nation has always +Dialogue: 0,0:00:38.00,0:00:46.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\Nbeen committed and to which we are\Ncommitted today at home and around the world. +Dialogue: 0,0:00:46.00,0:01:01.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\NLet every nation know,\Nwhether it wishes us well or ill,\Nthat we shall pay any price, bear any burden, +Dialogue: 0,0:01:01.00,0:01:13.00,Default,,0,0,0,,{\i1}Pres. John F. Kennedy{\i0}\Nmeet any hardship, support any friend,\Noppose any foe, to ensure the survival and\Nsuccess of liberty. +Dialogue: 0,0:01:13.00,9:59:59.99,Default,,0,0,0,,{\i1}End of:{\i0}\NPresident John F. Kennedy Speech -- 1.8.5.2 (Apple Git-48) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel