diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index e3c155fdd1..37372b29cd 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -100,20 +100,33 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf,
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
for (; dialog && num--; dialog++) {
- int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
- dialog->text);
- int log_level = (ret != AVERROR_INVALIDDATA ||
- avctx->err_recognition & AV_EF_EXPLODE) ?
- AV_LOG_ERROR : AV_LOG_WARNING;
-
- if (ret < 0) {
- av_log(avctx, log_level,
- "Splitting received ASS dialog failed: %s\n",
- av_err2str(ret));
-
- if (log_level == AV_LOG_ERROR)
- return ret;
+ if (dialog->style) {
+ av_bprintf(&s->buffer, "buffer, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+ av_bprintf(&s->buffer, "\">");
}
+
+ {
+ int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
+ dialog->text);
+ int log_level = (ret != AVERROR_INVALIDDATA ||
+ avctx->err_recognition & AV_EF_EXPLODE) ?
+ AV_LOG_ERROR : AV_LOG_WARNING;
+
+ if (ret < 0) {
+ av_log(avctx, log_level,
+ "Splitting received ASS dialog failed: %s\n",
+ av_err2str(ret));
+
+ if (log_level == AV_LOG_ERROR)
+ return ret;
+ }
+ }
+
+ if (dialog->style)
+ av_bprintf(&s->buffer, "");
}
} else {
#endif
@@ -121,6 +134,14 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf,
if (!dialog)
return AVERROR(ENOMEM);
+ if (dialog->style) {
+ av_bprintf(&s->buffer, "buffer, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+ av_bprintf(&s->buffer, "\">");
+ }
+
{
int ret = ff_ass_split_override_codes(&ttml_callbacks, s,
dialog->text);
@@ -140,6 +161,9 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf,
}
}
+ if (dialog->style)
+ av_bprintf(&s->buffer, "");
+
ff_ass_free_dialog(&dialog);
}
#if FF_API_ASS_TIMING
@@ -173,17 +197,171 @@ static av_cold int ttml_encode_close(AVCodecContext *avctx)
return 0;
}
+static const char *ttml_get_display_alignment(int alignment)
+{
+ switch (alignment) {
+ case 1:
+ case 2:
+ case 3:
+ return "after";
+ case 4:
+ case 5:
+ case 6:
+ return "center";
+ case 7:
+ case 8:
+ case 9:
+ return "before";
+ default:
+ return NULL;
+ }
+}
+
+static const char *ttml_get_text_alignment(int alignment)
+{
+ switch (alignment) {
+ case 1:
+ case 4:
+ case 7:
+ return "left";
+ case 2:
+ case 5:
+ case 8:
+ return "center";
+ case 3:
+ case 6:
+ case 9:
+ return "right";
+ default:
+ return NULL;
+ }
+}
+
+static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf,
+ ASSStyle style)
+{
+ const char *display_alignment = NULL;
+ const char *text_alignment = NULL;
+
+ if (!style.name) {
+ av_log(avctx, AV_LOG_ERROR, "Subtitle style name not set!\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (style.font_size < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid font size for TTML: %d!\n",
+ style.font_size);
+ return AVERROR_INVALIDDATA;
+ }
+
+ display_alignment = ttml_get_display_alignment(style.alignment);
+ text_alignment = ttml_get_text_alignment(style.alignment);
+ if (!display_alignment || !text_alignment) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Failed to convert ASS style alignment %d of style %s to "
+ "TTML display and text alignment!\n",
+ style.alignment,
+ style.name);
+ return AVERROR_INVALIDDATA;
+ }
+
+ av_bprintf(buf, "
Don't show this text it may be used to insert hidden data
+ end="00:00:00.000">Don't show this text it may be used to insert hidden dataSubRip subtitles capability tester 1.3o by ale5000
Use VLC 1.1 or higher as reference for most things and MPC Home Cinema for others
This text should be blue
This text should be red
This text should be black
If you see this with the normal font, the player don't (fully) support font face
Hidden
+ end="00:00:04.500">HiddenThis text should be small
This text should be normal
This text should be big
This should be an E with an accent: È
日本語
This text should be bold, italics and underline
This text should be small and green
This text should be small and red
This text should be big and brown
This line should be bold
This line should be italics
This line should be underline
This line should be strikethrough
Both lines
should be underline
>
It would be a good thing to
hide invalid html tags that are closed and show the text in them
but show un-closed invalid html tags
Show not opened tags
<
and also
hide invalid html tags with parameters that are closed and show the text in them
but show un-closed invalid html tags
This text should be showed underlined without problems also: 2<3,5>1,4<6
This shouldn't be underlined
This text should be in the normal position...
+ end="00:00:21.500">This text should be in the normal position...This text should NOT be in the normal position
+ end="00:00:22.500">This text should NOT be in the normal positionImplementation is the same of the ASS tag
This text should be at the
top and horizontally centered
This text should be at the
middle and horizontally centered
This text should be at the
bottom and horizontally centered
This text should be at the
top and horizontally at the left
This text should be at the
middle and horizontally at the left
(The second position must be ignored)
This text should be at the
bottom and horizontally at the left
This text should be at the
top and horizontally at the right
This text should be at the
middle and horizontally at the right
This text should be at the
bottom and horizontally at the right
This could be the most difficult thing to implement
+ end="00:00:31.500">This could be the most difficult thing to implementFirst text
+ end="00:00:50.500">First textSecond, it shouldn't overlap first
+ end="00:00:35.500">Second, it shouldn't overlap firstThird, it should replace second
+ end="00:00:37.500">Third, it should replace secondFourth, it shouldn't overlap first and third
+ end="00:00:50.500">Fourth, it shouldn't overlap first and thirdFifth, it should replace third
+ end="00:00:45.500">Fifth, it should replace thirdSixth, it shouldn't be
showed overlapped
TEXT 1 (bottom)
+ end="00:00:52.500">TEXT 1 (bottom)text 2
+ end="00:00:52.500">text 2Hide these tags:
also hide these tags:
but show this: {normal text}
\ N is a forced line break
\ h is a hard space
Normal spaces at the start and at the end of the line are trimmed while hard spaces are not trimmed.
The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
\h\h\h\h\hA (05 hard spaces followed by a letter)
A (Normal spaces followed by a letter)
A (No hard spaces followed by a letter)
\h\h\h\h\hA (05 hard spaces followed by a letter)
A (Normal spaces followed by a letter)
A (No hard spaces followed by a letter)
Show this: \TEST and this: \-)
A letter followed by 05 hard spaces: A\h\h\h\h\h
A letter followed by normal spaces: A
A letter followed by no hard spaces: A
05 hard spaces between letters: A\h\h\h\h\hA
5 normal spaces between letters: A A
^--Forced line break
Both line should be strikethrough,
yes.
Correctly closed tags
should be hidden.
It shouldn't be strikethrough,
not opened tag showed as text.
Not opened tag showed as text.
Three lines should be strikethrough,
yes.
Not closed tags showed as text
Both line should be strikethrough but
the wrong closing tag should be showed