[FFmpeg-cvslog] Autodetect jpg images.

Carl Eugen Hoyos git at videolan.org
Fri Sep 26 00:16:49 CEST 2014


ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos at ag.or.at> | Thu Sep 25 23:02:06 2014 +0200| [88c937fdc8a8c887ca482aa26a9d6862e72d0dd3] | committer: Carl Eugen Hoyos

Autodetect jpg images.

Based on 2d3842f5 by Michael Niedermayer.

Fixes ticket #2541.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=88c937fdc8a8c887ca482aa26a9d6862e72d0dd3
---

 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    1 +
 libavformat/img2dec.c    |   52 ++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/version.h    |    2 +-
 4 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index d3bf48f..9f81320 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -194,6 +194,7 @@ OBJS-$(CONFIG_IMAGE_BMP_PIPE_DEMUXER)     += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_DPX_PIPE_DEMUXER)     += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_EXR_PIPE_DEMUXER)     += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER)     += img2dec.o img2.o
+OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER)    += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER)  += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_PICTOR_PIPE_DEMUXER)  += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_PNG_PIPE_DEMUXER)     += img2dec.o img2.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 8f70c4b..9a71f26 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -325,6 +325,7 @@ void av_register_all(void)
     REGISTER_DEMUXER (IMAGE_DPX_PIPE,        image_dpx_pipe);
     REGISTER_DEMUXER (IMAGE_EXR_PIPE,        image_exr_pipe);
     REGISTER_DEMUXER (IMAGE_J2K_PIPE,        image_j2k_pipe);
+    REGISTER_DEMUXER (IMAGE_JPEG_PIPE,       image_jpeg_pipe);
     REGISTER_DEMUXER (IMAGE_JPEGLS_PIPE,     image_jpegls_pipe);
     REGISTER_DEMUXER (IMAGE_PICTOR_PIPE,     image_pictor_pipe);
     REGISTER_DEMUXER (IMAGE_PNG_PIPE,        image_png_pipe);
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 70bef9d..16bd699 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -620,6 +620,57 @@ static int j2k_probe(AVProbeData *p)
     return 0;
 }
 
+static int jpeg_probe(AVProbeData *p)
+{
+    const uint8_t *b = p->buf;
+    int i, state = 0xD8;
+
+    if (AV_RB16(b) != 0xFFD8 ||
+        AV_RB32(b) == 0xFFD8FFF7)
+    return 0;
+
+    b += 2;
+    for (i = 0; i < p->buf_size - 2; i++) {
+        int c;
+        if (b[i] != 0xFF)
+            continue;
+        c = b[i + 1];
+        switch (c) {
+        case 0xD8:
+            return 0;
+        case 0xC0:
+        case 0xC1:
+        case 0xC2:
+        case 0xC3:
+        case 0xC5:
+        case 0xC6:
+        case 0xC7:
+            if (state != 0xD8)
+                return 0;
+            state = 0xC0;
+            break;
+        case 0xDA:
+            if (state != 0xC0)
+                return 0;
+            state = 0xDA;
+            break;
+        case 0xD9:
+            if (state != 0xDA)
+                return 0;
+            state = 0xD9;
+            break;
+        default:
+            if (  (c >= 0x02 && c <= 0xBF)
+                || c == 0xC8)
+                return 0;
+        }
+    }
+
+    if (state == 0xD9)
+        return AVPROBE_SCORE_EXTENSION + 1;
+    return AVPROBE_SCORE_EXTENSION / 8;
+}
+
 static int jpegls_probe(AVProbeData *p)
 {
     const uint8_t *b = p->buf;
@@ -711,6 +762,7 @@ IMAGEAUTO_DEMUXER(bmp,     AV_CODEC_ID_BMP)
 IMAGEAUTO_DEMUXER(dpx,     AV_CODEC_ID_DPX)
 IMAGEAUTO_DEMUXER(exr,     AV_CODEC_ID_EXR)
 IMAGEAUTO_DEMUXER(j2k,     AV_CODEC_ID_JPEG2000)
+IMAGEAUTO_DEMUXER(jpeg,    AV_CODEC_ID_MJPEG)
 IMAGEAUTO_DEMUXER(jpegls,  AV_CODEC_ID_JPEGLS)
 IMAGEAUTO_DEMUXER(pictor,  AV_CODEC_ID_PICTOR)
 IMAGEAUTO_DEMUXER(png,     AV_CODEC_ID_PNG)
diff --git a/libavformat/version.h b/libavformat/version.h
index b1dde2c..cb2d029 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 56
-#define LIBAVFORMAT_VERSION_MINOR  5
+#define LIBAVFORMAT_VERSION_MINOR  6
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list