[FFmpeg-devel] [PATCH 5/5] avformat/img2dec: Use avformat probing interface to identify format if it has not been otherwise identified

Michael Niedermayer michaelni at gmx.at
Fri Mar 28 17:30:50 CET 2014


This is used only for distinguishing .pix formats for now.
Which is the only case that has image2 demuxers currently

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/img2dec.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 5163e69..31248d7 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -320,6 +320,8 @@ static int img_read_header(AVFormatContext *s1)
         st->codec->codec_id   = ff_guess_image2_codec(s->path);
         if (st->codec->codec_id == AV_CODEC_ID_LJPEG)
             st->codec->codec_id = AV_CODEC_ID_MJPEG;
+        if (st->codec->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX
+            st->codec->codec_id = AV_CODEC_ID_NONE;
     }
     if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
         pix_fmt != AV_PIX_FMT_NONE)
@@ -371,6 +373,25 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
             filename[strlen(filename) - 1] = 'U' + i;
         }
 
+        if (codec->codec_id == AV_CODEC_ID_NONE) {
+            AVProbeData pd;
+            AVInputFormat *ifmt;
+            uint8_t header[20 + AVPROBE_PADDING_SIZE];
+            int ret;
+            int score = 0;
+
+            ret = avio_read(f[0], header, 20);
+            if (ret < 0)
+                return ret;
+            avio_skip(f[0], -ret);
+            pd.buf = header;
+            pd.buf_size = ret;
+
+            ifmt = ff_probe_input_format3(&pd, AVFMT_IMAGE2, &score);
+            if (ifmt)
+                codec->codec_id = ifmt->raw_codec_id;
+        }
+
         if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width)
             infer_size(&codec->width, &codec->height, size[0]);
     } else {
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list