[FFmpeg-devel] [PATCH] Fix MJPEG decoding with broken AVI header

Oded Shimon ods15
Wed May 23 18:09:12 CEST 2007


The following patch fixes decoding of this file:
ftp.mplayerhq.hu/incoming/picnotinterlace.avi

File was created using virtualdub and Pegasus MJPEG 3.0 (from what I 
know..)

Better name for "build_basic_mjpeg_vlc" and better error message 
suggestions welcome..

(Alternative implementation for this fix is to remove the EXTERNAL_HUFF 
flag and recursively call ff_mjpeg_decode_init)

Can I commit?

- ods15
-------------- next part --------------
Index: libavcodec/mjpegdec.c
===================================================================
--- libavcodec/mjpegdec.c	(revision 9108)
+++ libavcodec/mjpegdec.c	(working copy)
@@ -62,6 +62,17 @@
     return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
 }
 
+static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) {
+    build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
+              ff_mjpeg_val_dc_luminance, 12, 0, 0);
+    build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
+              ff_mjpeg_val_dc_chrominance, 12, 0, 0);
+    build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
+              ff_mjpeg_val_ac_luminance, 251, 0, 1);
+    build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
+              ff_mjpeg_val_ac_chrominance, 251, 0, 1);
+}
+
 int ff_mjpeg_decode_init(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
@@ -75,21 +86,16 @@
     s->first_picture = 1;
     s->org_height = avctx->coded_height;
 
-    build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
-              ff_mjpeg_val_dc_luminance, 12, 0, 0);
-    build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
-              ff_mjpeg_val_dc_chrominance, 12, 0, 0);
-    build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
-              ff_mjpeg_val_ac_luminance, 251, 0, 1);
-    build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
-              ff_mjpeg_val_ac_chrominance, 251, 0, 1);
+    build_basic_mjpeg_vlc(s);
 
     if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
     {
         av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
         init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
-        ff_mjpeg_decode_dht(s);
-        /* should check for error - but dunno */
+        if (ff_mjpeg_decode_dht(s)) {
+            av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n");
+            build_basic_mjpeg_vlc(s);
+        }
     }
     if (avctx->extradata_size > 9 &&
         AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) {



More information about the ffmpeg-devel mailing list