avcodec/samidec: use ff_htmlmarkup_to_ass()

Signed-off-by: Clément Bœsch <u@pkh.me>
pull/148/head
Yayoi 9 years ago committed by Clément Bœsch
parent 1bb8a53f08
commit 87f90be4f2
  1. 2
      libavcodec/Makefile
  2. 23
      libavcodec/samidec.c
  3. 18
      tests/ref/fate/sub-sami
  4. 32
      tests/ref/fate/sub-sami2

@ -449,7 +449,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

@ -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,7 +89,8 @@ 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 != '>')
@ -103,9 +111,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 +147,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 +158,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;
}

@ -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, 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

@ -12,26 +12,26 @@ Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.51,0:00:01.51,Default,,0,0,0,,by Psyence Fictionist\Npsyencefictionist@gmail.com
Dialogue: 0,0:00:01.51,0:00:08.61,Default,,0,0,0,,Sync by: honeybunny and Kerensky\Nwww.Addic7ed.com
Dialogue: 0,0:00:10.11,0:00:10.11,Default,,0,0,0,,\N사랑과 배신\N탐욕과 살육의 이야기죠
Dialogue: 0,0:00:10.11,0:00:13.98,Default,,0,0,0,,\NThere is love and betrayal,\Ngreed and murder.
Dialogue: 0,0:00:17.67,0:00:17.67,Default,,0,0,0,,\N선악의 정의에 대해서\N대립하는 가치관을 가진
Dialogue: 0,0:00:17.67,0:00:21.72,Default,,0,0,0,,\NIt's set in this interesting\N world of contrasting ideology
Dialogue: 0,0:00:21.84,0:00:21.84,Default,,0,0,0,,\N매력적인 세계에서\N이 모든 것이 펼쳐집니다
Dialogue: 0,0:00:21.84,0:00:23.58,Default,,0,0,0,,\Nof what's right and wrong.
Dialogue: 0,0:00:23.69,0:00:23.69,Default,,0,0,0,,\N이 주제를 심오한 철학으로\N담아내고 있어요
Dialogue: 0,0:00:23.69,0:00:25.67,Default,,0,0,0,,\NIt has a great philosophy about it.
Dialogue: 0,0:00:40.22,0:00:40.22,Default,,0,0,0,,\N"왕좌의 게임"은 웨스테로스라는 가상왕국의\N권력 분쟁 이야기입니다
Dialogue: 0,0:00:40.22,0:00:47.94,Default,,0,0,0,,\N"Game of Thrones" is about power struggles\Nin a fantasy kingdom, called Westeros.
Dialogue: 0,0:00:10.11,0:00:10.11,Default,,0,0,0,,\N{\b1}사랑과 배신\N탐욕과 살육의 이야기죠{\b0}
Dialogue: 0,0:00:10.11,0:00:13.98,Default,,0,0,0,,\N{\c&H800080&}The{\c}{\c&HCBC0FF&}re{\c} {\c&HFF&}is{\c} {\c&HA5FF&}lo{\c}{\c&HFFFF&}ve{\c} {\c&H8000&}and{\c}{\c&HFFFF00&} bet{\c}{\c&HFF0000&}rayal{\c},\N{\b1}{\c&H808080&}g{\c}r{\c&H808080&}e{\c}e{\c&H808080&}d{\c} and {\c&HFF&}m{\c}{\c&H808080&}u{\c}{\c&HFF&}rder{\c}{\b0}.
Dialogue: 0,0:00:17.67,0:00:17.67,Default,,0,0,0,,\N{\c&HFFFF&}선악의 정의에 대해서\N대립하는 가치관을 가진{\c}
Dialogue: 0,0:00:17.67,0:00:21.72,Default,,0,0,0,,\N{\c&HCBC0FF&}{\fs6}It's{\fs} {\fs8}set{\fs}{\fs10} in {\fs}{\fs12}this{\fs}{\fs14} intere{\fs}{\fs14}sting{\fs}\N{\fs16} world{\fs}{\fs18} of{\fs} {\fs20}cont{\fs}{\fs22}rasting{\fs}{\fs24} ideology{\fs}{\c}
Dialogue: 0,0:00:21.84,0:00:21.84,Default,,0,0,0,,\N{\u1}매력적인 세계에서\N이 모든 것이 펼쳐집니다{\u1}
Dialogue: 0,0:00:21.84,0:00:23.58,Default,,0,0,0,,\N{\i1}{\c&H9966CC&}of{\c}{\c&HC2A3E0&} what's{\c} {\c&HE0D1F0&}right{\c} {\c&HFCFAFE&}and{\c} wrong.{\i0}
Dialogue: 0,0:00:23.69,0:00:23.69,Default,,0,0,0,,\N{\i1}이 주제를 심오한 철학으로\N담아내고 있어요{\i0}
Dialogue: 0,0:00:23.69,0:00:25.67,Default,,0,0,0,,\N{\fs20}{\c&HFF0000&}{\s1}It{\s0}{\c}{\fs} has {\fs15}{\c&HFFFF00&}a{\c}{\fs} great {\fs16}{\c&HFFCC00&}philosophy{\c}{\fs} about it.
Dialogue: 0,0:00:40.22,0:00:40.22,Default,,0,0,0,,\N{\s1}"왕좌의 게임"은 웨스테로스라는 가상왕국의\N권력 분쟁 이야기입니다{\s0}
Dialogue: 0,0:00:40.22,0:00:47.94,Default,,0,0,0,,\N{\c&HA5FF&}{\fs26}"Game of Thrones"{\fs}{\c} {\c&H2A2AA5&}{\b1}is{\b0}{\c}{\c&HFFFF&}{\fs24}{\i1} about{\i0}{\fs}{\c} {\c&H336699&}{\fs14}power{\fs}{\c}{\c&HFF&} struggles{\c}\N{\c&HA5FF&}{\fs8}in a fantasy{\fs}{\c&HCBC0FF&} kingdom{\c&HA5FF&}, called {\fs6}Westeros.{\fs}{\c}
Dialogue: 0,0:00:48.06,0:00:48.06,Default,,0,0,0,,\N철의 왕좌를 둘러싼\N권력 분쟁이죠
Dialogue: 0,0:00:48.06,0:00:50.76,Default,,0,0,0,,\NAnd it's a power struggle\Nfor the Iron Throne,
Dialogue: 0,0:00:50.88,0:00:50.88,Default,,0,0,0,,\N왕국의 권력 정점이라고\N할 수 있는 자리에요
Dialogue: 0,0:00:48.06,0:00:50.76,Default,,0,0,0,,\N{\c&H8000&}And it's a power struggle\Nfor the Iron Throne,{\c}
Dialogue: 0,0:00:50.88,0:00:50.88,Default,,0,0,0,,\N{\fs20}왕국의 권력 정점이라고\N할 수 있는 자리에요{\fs}
Dialogue: 0,0:00:50.88,0:00:53.13,Default,,0,0,0,,\Nwhich is the seat of power\Nin this kingdom.
Dialogue: 0,0:00:53.25,0:00:53.25,Default,,0,0,0,,\N전운이 감도네, 네드
Dialogue: 0,0:00:53.25,0:00:55.07,Default,,0,0,0,,\NThere's a war coming, Ned.
Dialogue: 0,0:00:56.01,0:00:56.01,Default,,0,0,0,, \N언제 누구와 싸우게 될지는 몰라\N하지만 분명 전쟁이 일어날걸세
Dialogue: 0,0:00:56.01,0:01:00.09,Default,,0,0,0,,\NI don't know when, I don't know who\Nwould be fighting, but it's coming.
Dialogue: 0,0:01:01.10,0:01:01.10,Default,,0,0,0,,\N이야기의 핵심은 두 주요 가문의\N권력을 둘러싼 갈등입니다
Dialogue: 0,0:01:01.10,0:01:07.04,Default,,0,0,0,,\NAt the core of it there's a conflict for\Npower between two great houses initially.
Dialogue: 0,0:01:01.10,0:01:07.04,Default,,0,0,0,,\N{\i1}At the core of it there's a conflict for\Npower between two great houses initially.{\i0}
Dialogue: 0,0:01:07.16,0:01:07.16,Default,,0,0,0,,\N스타크 가문과 라니스터 가문이죠
Dialogue: 0,0:01:07.16,0:01:10.04,Default,,0,0,0,,\NHouse Stark and House Lannister.
Dialogue: 0,0:01:10.16,0:01:10.16,Default,,0,0,0,,\N그 외에 여러 가문이\N서로 경쟁합니다
@ -47,11 +47,11 @@ Dialogue: 0,0:01:21.78,0:01:24.59,Default,,0,0,0,,\NYou see characters come into
Dialogue: 0,0:01:24.71,0:01:24.71,Default,,0,0,0,,\N그렇게 등장인물들은\N대의를 보는 시야를 잃어가고
Dialogue: 0,0:01:24.71,0:01:28.86,Default,,0,0,0,,\NIn a way it's about how people\Nforget to see the bigger picture,
Dialogue: 0,0:01:28.98,0:01:28.98,Default,,0,0,0,,\N사리사욕을 쫒는데 정신이 팔려\N공공의 위협을 외면하게 되죠
Dialogue: 0,0:01:28.98,0:01:33.89,Default,,0,0,0,,\Nthis common threat, that everybody\Nkind of ignores, because they're too busy
Dialogue: 0,0:01:28.98,0:01:33.89,Default,,0,0,0,,\N{\u1}this common threat, that everybody\Nkind of ignores, because they're too busy{\u0}
Dialogue: 0,0:01:34.01,0:01:35.24,Default,,0,0,0,,\Npursuing their own interests.
Dialogue: 0,0:01:35.36,0:01:35.36,Default,,0,0,0,,\N한편, 일곱 왕국의 밖에서는\N두 개의 거대한 위협이 부상합니다
Dialogue: 0,0:01:35.36,0:01:40.23,Default,,0,0,0,,\NAnd meanwhile, outside the Seven\NKingdoms, two great threats arising.
Dialogue: 0,0:01:40.35,0:01:40.35,Default,,0,0,0,,\N하나는 바다 건너\N타가리엔 일족 유배자들이며
Dialogue: 0,0:01:35.36,0:01:40.23,Default,,0,0,0,,\N{\fs30}And meanwhile, outside the Seven\NKingdoms, two great threats arising.{\fs}
Dialogue: 0,0:01:40.35,0:01:40.35,Default,,0,0,0,,\N<sup>하나는 바다 건너\N타가리엔 일족 유배자들이며</sub>
Dialogue: 0,0:01:40.35,0:01:44.06,Default,,0,0,0,,\NOne across the sea, in the exile\NTargaryen siblings,
Dialogue: 0,0:01:44.17,0:01:44.17,Default,,0,0,0,,\N또 하나는 일곱 왕국의\N국경이 자리잡은
Dialogue: 0,0:01:44.17,0:01:47.39,Default,,0,0,0,,\Nand another far to the north,\Nbeyond the Wall,

Loading…
Cancel
Save