Browse code

optionally try to encode each MB with MV=<0,0> and choose the one with better RD

Originally committed as revision 2328 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2003/10/02 09:24:34
Showing 3 changed files
... ...
@@ -15,7 +15,7 @@ extern "C" {
15 15
 
16 16
 #define FFMPEG_VERSION_INT     0x000408
17 17
 #define FFMPEG_VERSION         "0.4.8"
18
-#define LIBAVCODEC_BUILD       4682
18
+#define LIBAVCODEC_BUILD       4683
19 19
 
20 20
 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
21 21
 #define LIBAVCODEC_VERSION     FFMPEG_VERSION
... ...
@@ -215,6 +215,7 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
215 215
 #define CODEC_FLAG_4MV    0x0004  ///< 4 MV per MB allowed 
216 216
 #define CODEC_FLAG_QPEL   0x0010  ///< use qpel MC 
217 217
 #define CODEC_FLAG_GMC    0x0020  ///< use GMC 
218
+#define CODEC_FLAG_MV0    0x0040  ///< always try a MB with MV=<0,0> 
218 219
 #define CODEC_FLAG_PART   0x0080  ///< use data partitioning 
219 220
 /* parent program gurantees that the input for b-frame containing streams is not written to 
220 221
    for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
... ...
@@ -830,6 +830,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xma
830 830
     int P[10][2];
831 831
     int dmin_sum=0, mx4_sum=0, my4_sum=0;
832 832
     uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
833
+    int same=1;
833 834
 
834 835
     for(block=0; block<4; block++){
835 836
         int mx4, my4;
... ...
@@ -928,8 +929,13 @@ static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xma
928 928
             
929 929
         s->motion_val[ s->block_index[block] ][0]= mx4;
930 930
         s->motion_val[ s->block_index[block] ][1]= my4;
931
+
932
+        if(mx4 != mx || my4 != my) same=0;
931 933
     }
932 934
     
935
+    if(same)
936
+        return INT_MAX;
937
+    
933 938
     if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
934 939
         dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*s->linesize, s->me.scratchpad, s->linesize);
935 940
     }
... ...
@@ -1098,14 +1104,17 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1098 1098
             mb_type|= MB_TYPE_INTER;
1099 1099
             s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
1100 1100
 				   pred_x, pred_y, &s->last_picture, 0, 0, mv_penalty);
1101
+            if(s->flags&CODEC_FLAG_MV0)
1102
+                if(mx || my)
1103
+                    mb_type |= MB_TYPE_SKIPED; //FIXME check difference
1101 1104
         }else{
1102 1105
             mx <<=shift;
1103 1106
             my <<=shift;
1104 1107
         }
1105 1108
         if((s->flags&CODEC_FLAG_4MV)
1106 1109
            && !s->me.skip && varc>50 && vard>10){
1107
-            h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift);
1108
-            mb_type|=MB_TYPE_INTER4V;
1110
+            if(h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift) < INT_MAX)
1111
+                mb_type|=MB_TYPE_INTER4V;
1109 1112
 
1110 1113
             set_p_mv_tables(s, mx, my, 0);
1111 1114
         }else
... ...
@@ -3676,6 +3676,15 @@ static void encode_picture(MpegEncContext *s, int picture_number)
3676 3676
                     encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, 
3677 3677
                                  &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
3678 3678
                 }
3679
+                if(mb_type&MB_TYPE_SKIPED){
3680
+                    s->mv_dir = MV_DIR_FORWARD;
3681
+                    s->mv_type = MV_TYPE_16X16;
3682
+                    s->mb_intra= 0;
3683
+                    s->mv[0][0][0] = 0;
3684
+                    s->mv[0][0][1] = 0;
3685
+                    encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_SKIPED, pb, pb2, tex_pb, 
3686
+                                 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
3687
+                }
3679 3688
                 if(mb_type&MB_TYPE_INTER4V){                 
3680 3689
                     s->mv_dir = MV_DIR_FORWARD;
3681 3690
                     s->mv_type = MV_TYPE_8X8;