[FFmpeg-devel] [PATCH] avformat/sccdec: split line with multiple subs

Paul B Mahol onemda at gmail.com
Fri Jun 12 21:04:52 EEST 2020


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/sccdec.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/libavformat/sccdec.c b/libavformat/sccdec.c
index b9042b39ac..bf0e6c2688 100644
--- a/libavformat/sccdec.c
+++ b/libavformat/sccdec.c
@@ -83,6 +83,7 @@ static int scc_read_header(AVFormatContext *s)
         char *saveptr = NULL, *lline;
         int hh1, mm1, ss1, fs1, i;
         int hh2, mm2, ss2, fs2;
+        int po1, po2, ppo1, ppo2;
         AVPacket *sub;
 
         if (count == 0) {
@@ -117,21 +118,51 @@ try_again:
         lline = (char *)&line;
         lline += 12;
 
+        po1 = -1, po2 = -1, ppo1 = -1, ppo2 = -1;
         for (i = 0; i < 4095; i += 3) {
             char *ptr = av_strtok(lline, " ", &saveptr);
             char c1, c2, c3, c4;
+            uint8_t o1, o2;
 
             if (!ptr)
                 break;
 
             if (av_sscanf(ptr, "%c%c%c%c", &c1, &c2, &c3, &c4) != 4)
                 break;
+            o1 = convert(c2) | (convert(c1) << 4);
+            o2 = convert(c4) | (convert(c3) << 4);
+
+            if (o1 == 0x94 && o2 == 0x2f &&
+                po1 == 0x94 && po2 == 0x2c &&
+                ppo1 == 0x94 && ppo2 == 0x20) {
+                int64_t duration;
+
+                out[i] = 0;
+                duration = i * 11;
+
+                sub = ff_subtitles_queue_insert(&scc->q, out, i, 0);
+                if (!sub)
+                    return AVERROR(ENOMEM);
+
+                sub->pos = current_pos + i;
+                sub->pts = ts_start;
+                sub->duration = duration;
+
+                ts_start += duration;
+                i = 0;
+            }
 
             lline = NULL;
             out[i+0] = 0xfc;
-            out[i+1] = convert(c2) | (convert(c1) << 4);
-            out[i+2] = convert(c4) | (convert(c3) << 4);
+            out[i+1] = o1;
+            out[i+2] = o2;
+
+            ppo1 = po1;
+            ppo2 = po2;
+            po1 = o1;
+            po2 = o2;
         }
+
         out[i] = 0;
 
         sub = ff_subtitles_queue_insert(&scc->q, out, i, 0);
-- 
2.17.1



More information about the ffmpeg-devel mailing list