diff options
author | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2016-01-18 00:36:44 +0100 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2016-01-18 00:36:44 +0100 |
commit | 9bc281beae6dbf5d5f03cae8865b377f3a61f4ff (patch) | |
tree | 61b4f523888cd2a2be0ac7a203d5e50df96cb684 /libavformat/icodec.c | |
parent | f59b727e2f982a22c4459c67b2f5f7f42c86d3d0 (diff) | |
download | ffmpeg-9bc281beae6dbf5d5f03cae8865b377f3a61f4ff.tar.gz |
lavf/icodec: Improve autodetection.
Avoids misdetection of MPEG (B-)frames.
Reviewed-by: Michael Bradshaw
Diffstat (limited to 'libavformat/icodec.c')
-rw-r--r-- | libavformat/icodec.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/libavformat/icodec.c b/libavformat/icodec.c index 22e209903b..6ddb901b7e 100644 --- a/libavformat/icodec.c +++ b/libavformat/icodec.c @@ -27,6 +27,7 @@ #include "libavutil/intreadwrite.h" #include "libavcodec/bytestream.h" #include "libavcodec/bmp.h" +#include "libavcodec/png.h" #include "avformat.h" #include "internal.h" @@ -44,9 +45,30 @@ typedef struct { static int probe(AVProbeData *p) { - if (AV_RL16(p->buf) == 0 && AV_RL16(p->buf + 2) == 1 && AV_RL16(p->buf + 4)) - return AVPROBE_SCORE_MAX / 4; - return 0; + unsigned i, frames = AV_RL16(p->buf + 4); + + if (AV_RL16(p->buf) || AV_RL16(p->buf + 2) != 1 || !frames) + return 0; + for (i = 0; i < frames; i++) { + unsigned offset; + if (AV_RL16(p->buf + 10 + i * 16) & ~1) + return FFMIN(i, AVPROBE_SCORE_MAX / 4); + if (p->buf[13 + i * 16]) + return FFMIN(i, AVPROBE_SCORE_MAX / 4); + if (AV_RL32(p->buf + 14 + i * 16) < 40) + return FFMIN(i, AVPROBE_SCORE_MAX / 4); + offset = AV_RL32(p->buf + 18 + i * 16); + if (offset < 22) + return FFMIN(i, AVPROBE_SCORE_MAX / 4); + if (offset + 8 > p->buf_size) + return AVPROBE_SCORE_MAX / 4 + FFMIN(i, 1); + if (p->buf[offset] != 40 && AV_RB64(p->buf + offset) != PNGSIG) + return FFMIN(i, AVPROBE_SCORE_MAX / 4); + if (i * 16 + 6 > p->buf_size) + return AVPROBE_SCORE_MAX / 4 + FFMIN(i, 1); + } + + return AVPROBE_SCORE_MAX / 2 + 1; } static int read_header(AVFormatContext *s) |