Commit 87f90be4 authored by Yayoi's avatar Yayoi Committed by Clément Bœsch

avcodec/samidec: use ff_htmlmarkup_to_ass()

Signed-off-by: 's avatarClément Bœsch <u@pkh.me>
parent 1bb8a53f
......@@ -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
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment