[FFmpeg-devel] [PATCH 1/4] realtextdec: set subtitle fields for text without time tags as well

Marton Balint cus at passwd.hu
Sun Nov 17 15:14:59 CET 2013


This way position, and default duration is set for text coming immediately
after the window tag.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/realtextdec.c   | 9 ++++++---
 tests/ref/fate/sub-realtext | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/realtextdec.c b/libavformat/realtextdec.c
index 5e4981a..c7d6842 100644
--- a/libavformat/realtextdec.c
+++ b/libavformat/realtextdec.c
@@ -63,6 +63,7 @@ static int realtext_read_header(AVFormatContext *s)
     AVBPrint buf;
     char c = 0;
     int res = 0, duration = read_ts("60"); // default duration is 60 seconds
+    int first = 0;
 
     if (!st)
         return AVERROR(ENOMEM);
@@ -92,6 +93,7 @@ static int realtext_read_header(AVFormatContext *s)
                 goto end;
             }
             st->codec->extradata_size = buf.len + 1;
+            first = 1;
         } else {
             /* if we just read a <time> tag, introduce a new event, otherwise merge
              * with the previous one */
@@ -101,14 +103,15 @@ static int realtext_read_header(AVFormatContext *s)
                 res = AVERROR(ENOMEM);
                 goto end;
             }
-            if (!merge) {
-                const char *begin = ff_smil_get_attr_ptr(buf.str, "begin");
-                const char *end   = ff_smil_get_attr_ptr(buf.str, "end");
+            if (!merge || first) {
+                const char *begin = !merge ? ff_smil_get_attr_ptr(buf.str, "begin") : NULL;
+                const char *end   = !merge ? ff_smil_get_attr_ptr(buf.str, "end") : NULL;
 
                 sub->pos      = pos;
                 sub->pts      = begin ? read_ts(begin) : 0;
                 sub->duration = end ? (read_ts(end) - sub->pts) : duration;
             }
+            first = 0;
         }
         av_bprint_clear(&buf);
     }
diff --git a/tests/ref/fate/sub-realtext b/tests/ref/fate/sub-realtext
index 42ac3bb..aa42299 100644
--- a/tests/ref/fate/sub-realtext
+++ b/tests/ref/fate/sub-realtext
@@ -1 +1 @@
-5366f62be001f6fd4a7f48893828bf51
+eababfee1aefc3f0e16a3d7b71a3d1e8
-- 
1.8.4



More information about the ffmpeg-devel mailing list