[x264-devel] [PATCH] split horizontal and vertical mv range

Loïc Le Loarer lll+vlc at m4x.org
Thu May 11 19:29:44 CEST 2006


Hi,

Here is a patch which splits the horizontal and vertical motion vector
range and limits the vertical range correctly according to the level.

This has the effect of increasing the horizontal range which is level
independant instead of limiting it to the same value as the vertical
range by default, this may improve the encoding quality in some
situations.

This also prevent to produce invalid streams by setting a too big range.

Hope this helps.

Best regards.

-- 
Loïc
-------------- next part --------------
Index: encoder/encoder.c
===================================================================
--- encoder/encoder.c	(revision 522)
+++ encoder/encoder.c	(working copy)
@@ -423,10 +423,14 @@
             x264_log( h, X264_LOG_ERROR, "invalid level_idc: %d\n", h->param.i_level_idc );
             return -1;
         }
-        if( h->param.analyse.i_mv_range <= 0 )
-            h->param.analyse.i_mv_range = l->mv_range;
+        if( h->param.analyse.i_horizontal_mv_range <= 0 )
+            h->param.analyse.i_horizontal_mv_range = 2048; // This is a level independent limit
         else
-            h->param.analyse.i_mv_range = x264_clip3(h->param.analyse.i_mv_range, 32, 2048);
+            h->param.analyse.i_horizontal_mv_range = x264_clip3(h->param.analyse.i_horizontal_mv_range, 32, 2048);
+        if( h->param.analyse.i_vertical_mv_range <= 0 )
+            h->param.analyse.i_vertical_mv_range = l->mv_range;
+        else
+            h->param.analyse.i_vertical_mv_range = x264_clip3(h->param.analyse.i_vertical_mv_range, 32, l->mv_range);
     }
 
     if( h->param.rc.f_qblur < 0 )
Index: encoder/set.c
===================================================================
--- encoder/set.c	(revision 522)
+++ encoder/set.c	(working copy)
@@ -204,8 +204,8 @@
         sps->vui.b_motion_vectors_over_pic_boundaries = 1;
         sps->vui.i_max_bytes_per_pic_denom = 0;
         sps->vui.i_max_bits_per_mb_denom = 0;
-        sps->vui.i_log2_max_mv_length_horizontal =
-        sps->vui.i_log2_max_mv_length_vertical = (int)(log(param->analyse.i_mv_range*4-1)/log(2)) + 1;
+        sps->vui.i_log2_max_mv_length_horizontal = (int)(log(param->analyse.i_horizontal_mv_range*4-1)/log(2)) + 1;
+        sps->vui.i_log2_max_mv_length_vertical = (int)(log(param->analyse.i_vertical_mv_range*4-1)/log(2)) + 1;
     }
 }
 
@@ -537,7 +537,7 @@
     CHECK( "DPB size", l->dpb, mbs * 384 * h->sps->i_num_ref_frames );
     CHECK( "VBV bitrate", l->bitrate, h->param.rc.i_vbv_max_bitrate );
     CHECK( "VBV buffer", l->cpb, h->param.rc.i_vbv_buffer_size );
-    CHECK( "MV range", l->mv_range, h->param.analyse.i_mv_range );
+    CHECK( "MV range", l->mv_range, h->param.analyse.i_vertical_mv_range );
 
     if( h->param.i_fps_den > 0 )
         CHECK( "MB rate", l->mbps, (int64_t)mbs * h->param.i_fps_num / h->param.i_fps_den );
Index: encoder/analyse.c
===================================================================
--- encoder/analyse.c	(revision 522)
+++ encoder/analyse.c	(working copy)
@@ -218,26 +218,29 @@
     if( h->sh.i_type != SLICE_TYPE_I )
     {
         int i;
-        int i_fmv_range = h->param.analyse.i_mv_range - 16;
+        const int i_h_fmv_range = h->param.analyse.i_horizontal_mv_range - 16;
+        const int i_v_fmv_range = h->param.analyse.i_vertical_mv_range - 16;
 
         /* Calculate max allowed MV range */
-#define CLIP_FMV(mv) x264_clip3( mv, -i_fmv_range, i_fmv_range )
         h->mb.mv_min[0] = 4*( -16*h->mb.i_mb_x - 24 );
         h->mb.mv_max[0] = 4*( 16*( h->sps->i_mb_width - h->mb.i_mb_x - 1 ) + 24 );
-        h->mb.mv_min_fpel[0] = CLIP_FMV( -16*h->mb.i_mb_x - 8 );
-        h->mb.mv_max_fpel[0] = CLIP_FMV( 16*( h->sps->i_mb_width - h->mb.i_mb_x - 1 ) + 8 );
+#define CLIP_H_FMV(mv) x264_clip3( mv, -i_h_fmv_range, i_h_fmv_range )
+        h->mb.mv_min_fpel[0] = CLIP_H_FMV( -16*h->mb.i_mb_x - 8 );
+        h->mb.mv_max_fpel[0] = CLIP_H_FMV( 16*( h->sps->i_mb_width - h->mb.i_mb_x - 1 ) + 8 );
+#undef CLIP_H_FMV
         h->mb.mv_min_spel[0] = 4*( h->mb.mv_min_fpel[0] - 16 );
         h->mb.mv_max_spel[0] = 4*( h->mb.mv_max_fpel[0] + 16 );
         if( h->mb.i_mb_x == 0)
         {
             h->mb.mv_min[1] = 4*( -16*h->mb.i_mb_y - 24 );
             h->mb.mv_max[1] = 4*( 16*( h->sps->i_mb_height - h->mb.i_mb_y - 1 ) + 24 );
-            h->mb.mv_min_fpel[1] = CLIP_FMV( -16*h->mb.i_mb_y - 8 );
-            h->mb.mv_max_fpel[1] = CLIP_FMV( 16*( h->sps->i_mb_height - h->mb.i_mb_y - 1 ) + 8 );
+#define CLIP_V_FMV(mv) x264_clip3( mv, -i_v_fmv_range, i_v_fmv_range )
+            h->mb.mv_min_fpel[1] = CLIP_V_FMV( -16*h->mb.i_mb_y - 8 );
+            h->mb.mv_max_fpel[1] = CLIP_V_FMV( 16*( h->sps->i_mb_height - h->mb.i_mb_y - 1 ) + 8 );
+#undef CLIP_V_FMV
             h->mb.mv_min_spel[1] = 4*( h->mb.mv_min_fpel[1] - 16 );
             h->mb.mv_max_spel[1] = 4*( h->mb.mv_max_fpel[1] + 16 );
         }
-#undef CLIP_FMV
 
         a->l0.me16x16.cost =
         a->l0.i_rd16x16    =
Index: common/common.c
===================================================================
--- common/common.c	(revision 522)
+++ common/common.c	(working copy)
@@ -118,7 +118,8 @@
     param->analyse.i_me_range = 16;
     param->analyse.i_subpel_refine = 5;
     param->analyse.b_chroma_me = 1;
-    param->analyse.i_mv_range = -1; // set from level_idc
+    param->analyse.i_horizontal_mv_range = -1;
+    param->analyse.i_vertical_mv_range = -1; // set from level_idc
     param->analyse.i_chroma_qp_offset = 0;
     param->analyse.b_fast_pskip = 1;
     param->analyse.b_dct_decimate = 1;
Index: x264.h
===================================================================
--- x264.h	(revision 522)
+++ x264.h	(working copy)
@@ -195,7 +195,8 @@
 
         int          i_me_method; /* motion estimation algorithm to use (X264_ME_*) */
         int          i_me_range; /* integer pixel motion estimation search range (from predicted mv) */
-        int          i_mv_range; /* maximum length of a mv (in pixels) */
+        int          i_horizontal_mv_range; /* maximum length of a horizontal mv (in frame pixels) */
+        int          i_vertical_mv_range; /* maximum length of a vertical mv (in frame pixels) */
         int          i_subpel_refine; /* subpixel motion estimation quality */
         int          b_bidir_me; /* jointly optimize both MVs in B-frames */
         int          b_chroma_me; /* chroma ME for subpel and mode decision in P-frames */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.videolan.org/pipermail/x264-devel/attachments/20060511/e7a52814/attachment.pgp 


More information about the x264-devel mailing list