[SCM] libav/experimental: workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:31:59 UTC 2013


The following commit has been merged in the experimental branch:
commit 92ba5ffbb5fe072a3bdf37f87ec1443ee1af6744
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Tue May 21 23:13:57 2002 +0000

    workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
    
    Originally committed as revision 561 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2cfbdf6..91dde6e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -5,8 +5,8 @@
 
 #define LIBAVCODEC_VERSION_INT 0x000406
 #define LIBAVCODEC_VERSION     "0.4.6"
-#define LIBAVCODEC_BUILD       4609
-#define LIBAVCODEC_BUILD_STR   "4609"
+#define LIBAVCODEC_BUILD       4610
+#define LIBAVCODEC_BUILD_STR   "4610"
 
 enum CodecID {
     CODEC_ID_NONE, 
@@ -231,6 +231,8 @@ typedef struct AVCodecContext {
     enum CodecType codec_type; /* see CODEC_TYPE_xxx */
     enum CodecID codec_id; /* see CODEC_ID_xxx */
     unsigned int codec_tag;  /* codec tag, only used if unknown codec */
+    
+    int workaround_bugs;       /* workaround bugs in encoders which cannot be detected automatically */
     /*
 	Note: Below are located reserved fields for further usage
 	It requires for ABI !!!
@@ -253,7 +255,7 @@ typedef struct AVCodecContext {
 	    ul_res6,ul_res7,ul_res8,ul_res9,ul_res10,ul_res11,ul_res12;
     unsigned int
 	    ui_res0,ui_res1,ui_res2,ui_res3,ui_res4,ui_res5,
-	    ui_res6,ui_res7,ui_res8,ui_res9,ui_res10,ui_res11,ui_res12;
+	    ui_res6,ui_res7,ui_res8,ui_res9,ui_res10,ui_res11;
     unsigned short int
 	    us_res0,us_res1,us_res2,us_res3,us_res4,us_res5,
 	    us_res6,us_res7,us_res8,us_res9,us_res10,us_res11,us_res12;
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index be70eb3..680481d 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -43,6 +43,7 @@ static int h263_decode_init(AVCodecContext *avctx)
 
     s->width = avctx->width;
     s->height = avctx->height;
+    s->workaround_bugs= avctx->workaround_bugs;
 
     /* select sub codec */
     switch(avctx->codec->id) {
@@ -211,7 +212,11 @@ uint64_t time= rdtsc();
             //fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x);
             /* DCT & quantize */
             if (s->h263_pred && s->msmpeg4_version!=2) {
-                h263_dc_scale(s);
+                /* old ffmpeg encoded msmpeg4v3 workaround */
+                if(s->workaround_bugs==1 && s->msmpeg4_version==3) 
+                    ff_old_msmpeg4_dc_scale(s);
+                else
+                    h263_dc_scale(s);                
             } else {
                 /* default quantization values */
                 s->y_dc_scale = 8;
@@ -277,9 +282,9 @@ uint64_t time= rdtsc();
   s->has_b_frames=1;
   for(mb_y=0; mb_y<s->mb_height; mb_y++){
     int mb_x;
-    int y= mb_y*16;
+    int y= mb_y*16 + 8;
     for(mb_x=0; mb_x<s->mb_width; mb_x++){
-      int x= mb_x*16;
+      int x= mb_x*16 + 8;
       uint8_t *ptr= s->last_picture[0];
       int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
       int mx= (s->motion_val[xy][0]>>1) + x;
@@ -299,6 +304,7 @@ uint64_t time= rdtsc();
         int y1= y + (my-y)*i/max;
         ptr[y1*s->linesize + x1]+=100;
       }
+      ptr[y*s->linesize + x]+=100;
       s->mbskip_table[mb_x + mb_y*s->mb_width]=0;
     }
   }
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 3b44644..47a72f6 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -99,6 +99,7 @@ typedef struct MpegEncContext {
     float b_quant_factor;/* qscale factor between ips and b frames */
     int rc_strategy;
     int b_frame_strategy;
+    int workaround_bugs;       /* workaround bugs in encoders which cannot be detected automatically */
     /* the following fields are managed internally by the encoder */
 
     /* bit output */
@@ -491,6 +492,7 @@ int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
 int msmpeg4_decode_mb(MpegEncContext *s, 
                       DCTELEM block[6][64]);
 int msmpeg4_decode_init_vlc(MpegEncContext *s);
+void ff_old_msmpeg4_dc_scale(MpegEncContext *s);
 
 /* mjpegenc.c */
 
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 2809aee..79fd5f8 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -15,11 +15,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * msmpeg4v2 stuff by Michael Niedermayer <michaelni at gmx.at>
  */
 #include "avcodec.h"
 #include "dsputil.h"
 #include "mpegvideo.h"
 
+
 /*
  * You can also call this codec : MPEG4 with a twist ! 
  *
@@ -407,26 +410,20 @@ void msmpeg4_encode_mb(MpegEncContext * s,
     }
 }
 
-
-#if 0
-/* identical to mpeg4 for msmpeg4v3 but not msmpeg4v2 */
-void msmpeg4_dc_scale(MpegEncContext * s)
+/* old ffmpeg msmpeg4v3 mode */
+void ff_old_msmpeg4_dc_scale(MpegEncContext * s)
 {
-    if (s->qscale < 5 || s->msmpeg4_version==2){
+    if (s->qscale < 5){
         s->y_dc_scale = 8;
         s->c_dc_scale = 8;
     }else if (s->qscale < 9){
         s->y_dc_scale = 2 * s->qscale;
         s->c_dc_scale = (s->qscale + 13)>>1;
-    }else if(s->qscale < 25){
+    }else{
         s->y_dc_scale = s->qscale + 8;
         s->c_dc_scale = (s->qscale + 13)>>1;
-    }else{
-        s->y_dc_scale = 2 * s->qscale - 16;
-        s->c_dc_scale = s->qscale - 6;
     }
 }
-#endif
 
 /* dir = 0: left, dir = 1: top prediction */
 static int msmpeg4_pred_dc(MpegEncContext * s, int n, 

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list