X-Git-Url: https://git.piment-noir.org/?p=deb_ffmpeg.git;a=blobdiff_plain;f=ffmpeg%2Flibavformat%2Fsrtdec.c;h=b35e50fc367bf304fafad061e9196fabbbf3a9a2;hp=f5f3933916199a0925f6da98abf3728133eb2790;hb=f6fa7814ccfe3e76514b36cf04f5cd3cb657c8cf;hpb=2ba45a602cbfa7b771effba9b11bb4245c21bc00 diff --git a/ffmpeg/libavformat/srtdec.c b/ffmpeg/libavformat/srtdec.c index f5f3933..b35e50f 100644 --- a/ffmpeg/libavformat/srtdec.c +++ b/ffmpeg/libavformat/srtdec.c @@ -31,23 +31,28 @@ typedef struct { static int srt_probe(AVProbeData *p) { - int i, v, num = 0; + int v; + char buf[64], *pbuf; FFTextReader tr; ff_text_init_buf(&tr, p->buf, p->buf_size); while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n') ff_text_r8(&tr); - for (i=0; i<2; i++) { - char buf[128]; - if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0) - break; - if ((num == i || num + 1 == i) - && buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ") - && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1) - return AVPROBE_SCORE_MAX; - num = atoi(buf); - } + + /* Check if the first non-empty line is a number. We do not check what the + * number is because in practice it can be anything. */ + if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0 || + strtol(buf, &pbuf, 10) < 0 || *pbuf) + return 0; + + /* Check if the next line matches a SRT timestamp */ + if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0) + return 0; + if (buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ") + && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1) + return AVPROBE_SCORE_MAX; + return 0; } @@ -82,7 +87,7 @@ static int srt_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); int res = 0; FFTextReader tr; - ff_text_init_avio(&tr, s->pb); + ff_text_init_avio(s, &tr, s->pb); if (!st) return AVERROR(ENOMEM);