[FFmpeg-devel] [PATCH 1/2] lavc/samidec: support multiple paragraphs in a packet

Rodger Combs rodger.combs at gmail.com
Sun Oct 11 06:05:49 CEST 2015


---
 libavcodec/samidec.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c
index 95f35ab..8dd2749 100644
--- a/libavcodec/samidec.c
+++ b/libavcodec/samidec.c
@@ -46,6 +46,7 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
     char *p = dupsrc;
     AVBPrint *dst_content = &sami->encoded_content;
     AVBPrint *dst_source = &sami->encoded_source;
+    int got_content = 0;
 
     av_bprint_clear(&sami->encoded_content);
     av_bprint_clear(&sami->content);
@@ -76,17 +77,18 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
             av_bprint_clear(dst);
         }
 
-        /* if empty event -> skip subtitle */
-        while (av_isspace(*p))
+        while (av_isspace(*p) || (!strncmp(p, " ", 6) && (p += 5)))
             p++;
-        if (!strncmp(p, " ", 6)) {
-            ret = -1;
-            goto end;
-        }
 
         /* extract the text, stripping most of the tags */
         while (*p) {
             if (*p == '<') {
+                if (!av_strncasecmp(p, "</P>", 4)) {
+                    p += 4;
+                    while (av_isspace(*p))
+                        p++;
+                    continue;
+                }
                 if (!av_strncasecmp(p, "<P", 2) && (p[2] == '>' || av_isspace(p[2])))
                     break;
             }
@@ -107,9 +109,15 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
                 av_bprint_chars(dst, ' ', 1);
             prev_chr_is_space = av_isspace(*p);
             p++;
+            got_content = 1;
         }
     }
 
+    if (!got_content) {
+        ret = -1;
+        goto end;
+    }
+
     av_bprint_clear(&sami->full);
     if (sami->source.len) {
         ff_htmlmarkup_to_ass(avctx, dst_source, sami->source.str);
-- 
2.6.0



More information about the ffmpeg-devel mailing list