Commit 9ae83ece authored by Clément Bœsch's avatar Clément Bœsch

avformat/srtdec: simpler and more lenient probing

Fixes Ticket #3935.
parent 7dd2005e
...@@ -31,23 +31,28 @@ typedef struct { ...@@ -31,23 +31,28 @@ typedef struct {
static int srt_probe(AVProbeData *p) static int srt_probe(AVProbeData *p)
{ {
int i, v, num = 0; int v;
char buf[64], *pbuf;
FFTextReader tr; FFTextReader tr;
ff_text_init_buf(&tr, p->buf, p->buf_size); ff_text_init_buf(&tr, p->buf, p->buf_size);
while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n') while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n')
ff_text_r8(&tr); ff_text_r8(&tr);
for (i=0; i<2; i++) {
char buf[128]; /* Check if the first non-empty line is a number. We do not check what the
if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0) * number is because in practice it can be anything. */
break; if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0 ||
if ((num == i || num + 1 == i) strtol(buf, &pbuf, 10) < 0 || *pbuf)
&& buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ") return 0;
&& sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
return AVPROBE_SCORE_MAX; /* Check if the next line matches a SRT timestamp */
num = atoi(buf); 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; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment