[FFmpeg-cvslog] movtextdec: Add support for automatic text wrapping

Niklesh git at videolan.org
Sat Aug 15 04:36:03 CEST 2015


ffmpeg | branch: master | Niklesh <niklesh.lalwani at iitb.ac.in> | Fri Aug 14 20:37:51 2015 +0530| [a604289b85709850cb5ef2fe1567456fb6825ce2] | committer: Philip Langdale

movtextdec: Add support for automatic text wrapping

The value of wrap_flag in the Text Wrap Box specifies if the text is to
be wrapped or not. Uses 'end of line wrap' amongst the wrap styles
supported by ASS if the text is to be wrapped, i.e; fill as much text
in a line as possible, then break to next line.

The 3GPP spec has no provision for smart wrapping.

Signed-off-by: Niklesh <niklesh.lalwani at iitb.ac.in>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a604289b85709850cb5ef2fe1567456fb6825ce2
---

 libavcodec/movtextdec.c |   25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 6d7885b..8f1015a 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -36,6 +36,7 @@
 #define STYL_BOX   (1<<0)
 #define HLIT_BOX   (1<<1)
 #define HCLR_BOX   (1<<2)
+#define TWRP_BOX   (1<<3)
 
 #define BOTTOM_LEFT     1
 #define BOTTOM_CENTER   2
@@ -81,12 +82,17 @@ typedef struct {
 } HilightcolorBox;
 
 typedef struct {
+    uint8_t wrap_flag;
+} TextWrapBox;
+
+typedef struct {
     StyleBox **s;
     StyleBox *s_temp;
     HighlightBox h;
     HilightcolorBox c;
     FontRecord **ftab;
     FontRecord *ftab_temp;
+    TextWrapBox w;
     MovTextDefault d;
     uint8_t box_flags;
     uint16_t style_entries, ftab_entries;
@@ -240,6 +246,13 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
     return 0;
 }
 
+static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
+{
+    m->box_flags |= TWRP_BOX;
+    m->w.wrap_flag = *tsmb++;
+    return 0;
+}
+
 static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
 {
     m->box_flags |= HLIT_BOX;
@@ -298,7 +311,8 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
 static const Box box_types[] = {
     { MKBETAG('s','t','y','l'), 2, decode_styl },
     { MKBETAG('h','l','i','t'), 4, decode_hlit },
-    { MKBETAG('h','c','l','r'), 4, decode_hclr }
+    { MKBETAG('h','c','l','r'), 4, decode_hclr },
+    { MKBETAG('t','w','r','p'), 1, decode_twrp }
 };
 
 const static size_t box_count = FF_ARRAY_ELEMS(box_types);
@@ -309,6 +323,15 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
     int i = 0;
     int j = 0;
     int text_pos = 0;
+
+    if (text < text_end && m->box_flags & TWRP_BOX) {
+        if (m->w.wrap_flag == 1) {
+            av_bprintf(buf, "{\\q1}"); /* End of line wrap */
+        } else {
+            av_bprintf(buf, "{\\q2}"); /* No wrap */
+        }
+    }
+
     while (text < text_end) {
         if (m->box_flags & STYL_BOX) {
             for (i = 0; i < m->style_entries; i++) {



More information about the ffmpeg-cvslog mailing list