[FFmpeg-devel] [PATCH] avcodec/samidec: process more of the SAMI tags

Won-woo Choi chwo9843 at gmail.com
Sun Mar 15 09:28:15 CET 2015


Made some changes to samidec so that it can process SAMI tags.
Processes <B> and <FONT>(font face, color).
---
 libavcodec/samidec.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c
index 47850e2..b47204d 100644
--- a/libavcodec/samidec.c
+++ b/libavcodec/samidec.c
@@ -25,6 +25,7 @@
  */
 
 #include "ass.h"
+#include "libavformat/subtitles.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 
@@ -77,13 +78,45 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
             goto end;
         }
 
-        /* extract the text, stripping most of the tags */
+        /* extract the text, processing some of the tags */
         while (*p) {
+            int bold = 0;
             if (*p == '<') {
-                if (!av_strncasecmp(p, "<P", 2) && (p[2] == '>' || av_isspace(p[2])))
+                if ( !av_strncasecmp(p, "<P", 2) &&
+                     (p[2] == '>' || av_isspace(p[2])) )
                     break;
+                if ( !av_strncasecmp(p, "<B", 2) &&
+                     (p[2] == '>' || av_isspace(p[2])) ) {
+                    bold = 1;
+                    av_bprintf(dst, "{\\b1}");
+                }
+                if (!av_strncasecmp(p, "</B>", 4)) {
+                    bold = 0;
+                    av_bprintf(dst, "{\\b0}");
+                }
                 if (!av_strncasecmp(p, "<BR", 3))
                     av_bprintf(dst, "\\N");
+                if (!av_strncasecmp(p, "<FONT", 5)) {
+                    const char *p_color = ff_smil_get_attr_ptr(p, "Color");
+                    const char *p_face = ff_smil_get_attr_ptr(p, "Face");
+                    const char *p_face_end = p_face;
+
+                    if (p_color) {
+                        /* ASS color code order is BGR, opposite to SAMI */
+                        av_bprintf(dst, "{\\c&H%.2s%.2s%.2s&}",
+                                   p_color+4, p_color+2, p_color);
+                    }
+                    if (p_face) {
+                        while (*p_face_end != '\"' && *p_face_end != ' ')
+                            p_face_end++;
+                        av_bprintf(dst, "{\\fn%.*s}",
+                                   (int)(p_face_end - p_face), p_face);
+                    }
+                }
+                if (!av_strncasecmp(p, "</FONT>", 7)) {
+                    av_bprintf(dst, "{\\r}");
+                    if (bold) av_bprintf(dst, "{\\b1}");
+                }
                 p++;
                 while (*p && *p != '>')
                     p++;
-- 
2.3.2



More information about the ffmpeg-devel mailing list