]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/sccdec.c
avformat/audiointerleave: only keep the retime functionality of the audio interleaver
[ffmpeg] / libavformat / sccdec.c
index 89d21b9c1fb25a1cc8be842a2d3d41a53c22abf1..b9042b39ac934ca571621ccaff973c6746957999 100644 (file)
@@ -22,6 +22,7 @@
 #include "avformat.h"
 #include "internal.h"
 #include "subtitles.h"
+#include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
 
@@ -29,7 +30,7 @@ typedef struct SCCContext {
     FFDemuxSubtitlesQueue q;
 } SCCContext;
 
-static int scc_probe(AVProbeData *p)
+static int scc_probe(const AVProbeData *p)
 {
     char buf[18];
     FFTextReader tr;
@@ -63,6 +64,7 @@ static int scc_read_header(AVFormatContext *s)
     SCCContext *scc = s->priv_data;
     AVStream *st = avformat_new_stream(s, NULL);
     char line[4096], line2[4096];
+    int64_t ts_start, ts_end;
     int count = 0, ret = 0;
     ptrdiff_t len2, len;
     uint8_t out[4096];
@@ -77,14 +79,14 @@ static int scc_read_header(AVFormatContext *s)
     st->codecpar->codec_id   = AV_CODEC_ID_EIA_608;
 
     while (!ff_text_eof(&tr)) {
-        const int64_t pos = ff_text_pos(&tr);
+        int64_t current_pos, next_pos;
         char *saveptr = NULL, *lline;
         int hh1, mm1, ss1, fs1, i;
         int hh2, mm2, ss2, fs2;
-        int64_t ts_start, ts_end;
         AVPacket *sub;
 
         if (count == 0) {
+            current_pos = ff_text_pos(&tr);
             while (!ff_text_eof(&tr)) {
                 len = ff_subtitles_read_line(&tr, line, sizeof(line));
                 if (len > 13)
@@ -94,22 +96,24 @@ static int scc_read_header(AVFormatContext *s)
 
         if (!strncmp(line, "Scenarist_SCC V1.0", 18))
             continue;
-        if (sscanf(line, "%d:%d:%d%*[:;]%d", &hh1, &mm1, &ss1, &fs1) != 4)
+        if (av_sscanf(line, "%d:%d:%d%*[:;]%d", &hh1, &mm1, &ss1, &fs1) != 4)
             continue;
 
         ts_start = (hh1 * 3600LL + mm1 * 60LL + ss1) * 1000LL + fs1 * 33;
 
+        next_pos = ff_text_pos(&tr);
         while (!ff_text_eof(&tr)) {
             len2 = ff_subtitles_read_line(&tr, line2, sizeof(line2));
             if (len2 > 13)
                 break;
         }
-        if (sscanf(line2, "%d:%d:%d%*[:;]%d", &hh2, &mm2, &ss2, &fs2) != 4)
+        if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh2, &mm2, &ss2, &fs2) != 4)
             continue;
 
         ts_end = (hh2 * 3600LL + mm2 * 60LL + ss2) * 1000LL + fs2 * 33;
         count++;
 
+try_again:
         lline = (char *)&line;
         lline += 12;
 
@@ -120,7 +124,7 @@ static int scc_read_header(AVFormatContext *s)
             if (!ptr)
                 break;
 
-            if (sscanf(ptr, "%c%c%c%c", &c1, &c2, &c3, &c4) != 4)
+            if (av_sscanf(ptr, "%c%c%c%c", &c1, &c2, &c3, &c4) != 4)
                 break;
 
             lline = NULL;
@@ -134,11 +138,18 @@ static int scc_read_header(AVFormatContext *s)
         if (!sub)
             return AVERROR(ENOMEM);
 
-        sub->pos = pos;
+        sub->pos = current_pos;
         sub->pts = ts_start;
-        sub->duration = FFMAX(1200, ts_end - ts_start);
+        sub->duration = ts_end - ts_start;
         memmove(line, line2, sizeof(line));
-        FFSWAP(ptrdiff_t, len, len2);
+        current_pos = next_pos;
+        line2[0] = 0;
+    }
+
+    if (line[0]) {
+        ts_start = ts_end;
+        ts_end += 1200;
+        goto try_again;
     }
 
     ff_subtitles_queue_finalize(s, &scc->q);