[FFmpeg-devel] [PATCH] movtextdec: Use default style information from movtext header
Philip Langdale
philipl at overt.org
Wed Aug 12 23:44:20 CEST 2015
On Wed, 12 Aug 2015 18:24:32 +0530
Niklesh Lalwani <niklesh.lalwani at iitb.ac.in> wrote:
> From: Niklesh <niklesh.lalwani at iitb.ac.in>
>
> As suggested, posting the combined patch with the fate changes.
> The patch sets the default style in ASS from the default style
> information present in the movtext header.
>
> Signed-off-by: Niklesh <niklesh.lalwani at iitb.ac.in>
> ---
> libavcodec/movtextdec.c | 82
> +++++++++++++++++++++++++++++++++++++++++---
> tests/ref/fate/sub-movtext | 2 +- tests/ref/fate/sub-subripenc |
> 10 +++--- 3 files changed, 84 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index fc6993e..6d7885b 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -37,6 +37,27 @@
> #define HLIT_BOX (1<<1)
> #define HCLR_BOX (1<<2)
>
> +#define BOTTOM_LEFT 1
> +#define BOTTOM_CENTER 2
> +#define BOTTOM_RIGHT 3
> +#define MIDDLE_LEFT 4
> +#define MIDDLE_CENTER 5
> +#define MIDDLE_RIGHT 6
> +#define TOP_LEFT 7
> +#define TOP_CENTER 8
> +#define TOP_RIGHT 9
> +
> +typedef struct {
> + char *font;
> + int fontsize;
> + int color;
> + int back_color;
> + int bold;
> + int italic;
> + int underline;
> + int alignment;
> +} MovTextDefault;
> +
> typedef struct {
> uint16_t fontID;
> char *font;
> @@ -66,6 +87,7 @@ typedef struct {
> HilightcolorBox c;
> FontRecord **ftab;
> FontRecord *ftab_temp;
> + MovTextDefault d;
> uint8_t box_flags;
> uint16_t style_entries, ftab_entries;
> uint64_t tracksize;
> @@ -106,6 +128,9 @@ static int mov_text_tx3g(AVCodecContext *avctx,
> MovTextContext *m) {
> char *tx3g_ptr = avctx->extradata;
> int i, box_size, font_length;
> + int8_t v_align, h_align;
> + int style_fontID;
> + StyleBox s_default;
>
> m->count_f = 0;
> m->ftab_entries = 0;
> @@ -116,13 +141,52 @@ static int mov_text_tx3g(AVCodecContext *avctx,
> MovTextContext *m) // Display Flags
> tx3g_ptr += 4;
> // Alignment
> - tx3g_ptr += 2;
> + h_align = *tx3g_ptr++;
> + v_align = *tx3g_ptr++;
> + if (h_align == 0) {
> + if (v_align == 0)
> + m->d.alignment = TOP_LEFT;
> + if (v_align == 1)
> + m->d.alignment = MIDDLE_LEFT;
> + if (v_align == -1)
> + m->d.alignment = BOTTOM_LEFT;
> + }
> + if (h_align == 1) {
> + if (v_align == 0)
> + m->d.alignment = TOP_CENTER;
> + if (v_align == 1)
> + m->d.alignment = MIDDLE_CENTER;
> + if (v_align == -1)
> + m->d.alignment = BOTTOM_CENTER;
> + }
> + if (h_align == -1) {
> + if (v_align == 0)
> + m->d.alignment = TOP_RIGHT;
> + if (v_align == 1)
> + m->d.alignment = MIDDLE_RIGHT;
> + if (v_align == -1)
> + m->d.alignment = BOTTOM_RIGHT;
> + }
> // Background Color
> + m->d.back_color = AV_RB24(tx3g_ptr);
> tx3g_ptr += 4;
> // BoxRecord
> tx3g_ptr += 8;
> // StyleRecord
> - tx3g_ptr += 12;
> + tx3g_ptr += 4;
> + // fontID
> + style_fontID = AV_RB16(tx3g_ptr);
> + tx3g_ptr += 2;
> + // face-style-flags
> + s_default.style_flag = *tx3g_ptr++;
> + m->d.bold = s_default.style_flag & STYLE_FLAG_BOLD;
> + m->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC;
> + m->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE;
> + // fontsize
> + m->d.fontsize = *tx3g_ptr++;
> + // Primary color
> + m->d.color = AV_RB24(tx3g_ptr);
> + tx3g_ptr += 4;
> // FontRecord
> // FontRecord Size
> tx3g_ptr += 4;
> @@ -169,6 +233,10 @@ static int mov_text_tx3g(AVCodecContext *avctx,
> MovTextContext *m) }
> tx3g_ptr = tx3g_ptr + font_length;
> }
> + for (i = 0; i < m->ftab_entries; i++) {
> + if (style_fontID == m->ftab[i]->fontID)
> + m->d.font = m->ftab[i]->font;
> + }
> return 0;
> }
>
> @@ -312,9 +380,15 @@ static int mov_text_init(AVCodecContext *avctx) {
> * it's very common to find files where the default style is
> broken
> * and respecting it results in a worse experience than ignoring
> it. */
> + int ret;
> MovTextContext *m = avctx->priv_data;
> - mov_text_tx3g(avctx, m);
> - return ff_ass_subtitle_header_default(avctx);
> + ret = mov_text_tx3g(avctx, m);
> + if (ret == 0) {
> + return ff_ass_subtitle_header(avctx, m->d.font,
> m->d.fontsize, m->d.color,
> + m->d.back_color, m->d.bold,
> m->d.italic,
> + m->d.underline, m->d.alignment);
> + } else
> + return ff_ass_subtitle_header_default(avctx);
> }
>
> static int mov_text_decode_frame(AVCodecContext *avctx,
> diff --git a/tests/ref/fate/sub-movtext b/tests/ref/fate/sub-movtext
> index 6a90e96..94ed22d 100644
> --- a/tests/ref/fate/sub-movtext
> +++ b/tests/ref/fate/sub-movtext
> @@ -6,7 +6,7 @@ PlayResY: 288
>
> [V4+ Styles]
> Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour,
> OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut,
> ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow,
> Alignment, MarginL, MarginR, MarginV, Encoding -Style:
> Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
> +Style:
> Default,Serif,18,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
> [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR,
> MarginV, Effect, Text diff --git a/tests/ref/fate/sub-subripenc
> b/tests/ref/fate/sub-subripenc index 1f1e031..7f35ae9 100644 ---
> a/tests/ref/fate/sub-subripenc +++ b/tests/ref/fate/sub-subripenc @@
> -1,14 +1,14 @@ 1
> 00:00:00,970 --> 00:00:02,540
> -- Test 1.
> -- Test 2.
> +<font face="Serif" size="18">- Test 1.
> +- Test 2.</font>
>
> 2
> 00:00:03,050 --> 00:00:04,740
> -Test 3.
> +<font face="Serif" size="18">Test 3.</font>
>
> 3
> 00:00:05,850 --> 00:00:08,140
> -- Test 4.
> -- Test 5.
> +<font face="Serif" size="18">- Test 4.
> +- Test 5.</font>
>
Pushed. Thanks.
--phil
More information about the ffmpeg-devel
mailing list