Guest User

techouse

a guest
Jun 4th, 2008
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. --- common/common.c Sun Jan 27 13:39:08 2008
  2. +++ common/common.c Sun Jan 27 13:39:08 2008
  3. @@ -483,6 +483,8 @@
  4. p->analyse.i_mv_range_thread = atoi(value);
  5. OPT2("subme", "subq")
  6. p->analyse.i_subpel_refine = atoi(value);
  7. + OPT2("me-prepass", "meprepass")
  8. + p->analyse.i_me_prepass = atobool(value);
  9. OPT("rdcmp")
  10. b_error |= parse_enum( value, x264_rdcmp_names, &p->analyse.i_rdcmp );
  11. OPT("bime")
  12. @@ -881,6 +883,7 @@
  13. s += sprintf( s, " analyse=%#x:%#x", p->analyse.intra, p->analyse.inter );
  14. s += sprintf( s, " me=%s", x264_motion_est_names[ p->analyse.i_me_method ] );
  15. s += sprintf( s, " subme=%d", p->analyse.i_subpel_refine );
  16. + s += sprintf( s, " me-prepass=%d", p->analyse.i_me_prepass );
  17. s += sprintf( s, " rdcmp=%s", x264_rdcmp_names[ p->analyse.i_rdcmp ] );
  18. s += sprintf( s, " brdo=%d", p->analyse.b_bframe_rdo );
  19. s += sprintf( s, " mixed_ref=%d", p->analyse.b_mixed_references );
  20. --- x264.c Sun Jan 27 13:39:08 2008
  21. +++ x264.c Sun Jan 27 13:39:08 2008
  22. @@ -248,7 +248,8 @@
  23. H1( " --mvrange-thread <int> Minimum buffer between threads [-1 (auto)]\n" );
  24. H0( " -m, --subme <integer> Subpixel motion estimation and partition\n"
  25. " decision quality: 1=fast, 7=best. [%d]\n", defaults->analyse.i_subpel_refine );
  26. - H0( " --b-rdo RD based mode decision for B-frames. Requires subme 6.\n" );
  27. + H0( " --me-prepass Run an ME prepass on predictors. Requires subme 3 or higher.\n");
  28. + H0( " --b-rdo RD based mode decision for B-frames. Requires subme 6 or higher.\n" );
  29. H0( " --rdcmp Metric used for RD mode decision [\"%s\"]\n",
  30. strtable_lookup( x264_rdcmp_names, defaults->analyse.i_rdcmp ) );
  31. H0( " - ssd: normal (maximum PSNR)\n"
  32. @@ -427,6 +428,7 @@
  33. { "mvrange", required_argument, NULL, 0 },
  34. { "mvrange-thread", required_argument, NULL, 0 },
  35. { "subme", required_argument, NULL, 'm' },
  36. + { "me-prepass", no_argument, NULL, 0 },
  37. { "rdcmp", required_argument, NULL, 0 },
  38. { "b-rdo", no_argument, NULL, 0 },
  39. { "mixed-refs", no_argument, NULL, 0 },
  40. --- x264.h Sun Jan 27 13:39:08 2008
  41. +++ x264.h Sun Jan 27 13:39:08 2008
  42. @@ -233,6 +233,7 @@
  43. int i_mv_range; /* maximum length of a mv (in pixels). -1 = auto, based on level */
  44. int i_mv_range_thread; /* minimum space between threads. -1 = auto, based on number of threads. */
  45. int i_subpel_refine; /* subpixel motion estimation quality */
  46. + int i_me_prepass; /* run an ME prepass on predictors */
  47. int b_bidir_me; /* jointly optimize both MVs in B-frames */
  48. int b_chroma_me; /* chroma ME for subpel and mode decision in P-frames */
  49. int b_bframe_rdo; /* RD based mode decision for B-frames */
  50. --- encoder/me.c Sun Jan 27 13:39:08 2008
  51. +++ encoder/me.c Sun Jan 27 20:25:50 2008
  52. @@ -69,6 +69,23 @@
  53. COPY3_IF_LT( bpred_cost, cost, bpred_mx, mx, bpred_my, my ); \
  54. }
  55.  
  56. +#define COST_MV_HPEL2( mx, my, cost ) \
  57. +{ \
  58. + int stride = 16; \
  59. + uint8_t *src = h->mc.get_ref( pix, &stride, m->p_fref, m->i_stride[0], mx, my, bw, bh ); \
  60. + cost = h->pixf.fpelcmp[i_pixel]( m->p_fenc[0], FENC_STRIDE, src, stride ) \
  61. + + p_cost_mvx[ mx ] + p_cost_mvy[ my ]; \
  62. +}
  63. +
  64. +#define COST_MV_HPEL3( mx, my) \
  65. +{ \
  66. + int stride = 16; \
  67. + uint8_t *src = h->mc.get_ref( pix, &stride, m->p_fref, m->i_stride[0], mx, my, bw, bh ); \
  68. + int cost = h->pixf.fpelcmp[i_pixel]( m->p_fenc[0], FENC_STRIDE, src, stride ) \
  69. + + p_cost_mvx[ mx ] + p_cost_mvy[ my ]; \
  70. + COPY3_IF_LT( bestcost, cost, bestx, mx, besty, my ); \
  71. +}
  72. +
  73. #define COST_MV_X3_DIR( m0x, m0y, m1x, m1y, m2x, m2y, costs )\
  74. {\
  75. uint8_t *pix_base = p_fref + bmx + bmy*m->i_stride[0];\
  76. @@ -171,8 +188,13 @@
  77. int mv_y_min = h->mb.mv_min_fpel[1];
  78. int mv_x_max = h->mb.mv_max_fpel[0];
  79. int mv_y_max = h->mb.mv_max_fpel[1];
  80. + int mv_x_min4 = h->mb.mv_min_fpel[0]<<2;
  81. + int mv_y_min4 = h->mb.mv_min_fpel[1]<<2;
  82. + int mv_x_max4 = h->mb.mv_max_fpel[0]<<2;
  83. + int mv_y_max4 = h->mb.mv_max_fpel[1]<<2;
  84.  
  85. #define CHECK_MVRANGE(mx,my) ( mx >= mv_x_min && mx <= mv_x_max && my >= mv_y_min && my <= mv_y_max )
  86. +#define CHECK_MVRANGE4(mx,my) ( mx >= mv_x_min4 && mx <= mv_x_max4 && my >= mv_y_min4 && my <= mv_y_max4 )
  87.  
  88. const int16_t *p_cost_mvx = m->p_cost_mv - m->mvp[0];
  89. const int16_t *p_cost_mvy = m->p_cost_mv - m->mvp[1];
  90. @@ -183,19 +205,88 @@
  91. pmy = ( bmy + 2 ) >> 2;
  92. bcost = COST_MAX;
  93.  
  94. - /* try extra predictors if provided */
  95. - if( h->mb.i_subpel_refine >= 3 )
  96. - {
  97. - COST_MV_HPEL( bmx, bmy );
  98. - for( i = 0; i < i_mvc; i++ )
  99. + /* try extra predictors if provided */
  100. + if( h->mb.i_subpel_refine >= 3 )
  101. + {
  102. + COST_MV_HPEL( bmx, bmy );
  103. + if(!h->param.analyse.i_me_prepass)
  104. + {
  105. + for( i = 0; i < i_mvc; i++ )
  106. + {
  107. + const int mx = x264_clip3( mvc[i][0], mv_x_min*4, mv_x_max*4 );
  108. + const int my = x264_clip3( mvc[i][1], mv_y_min*4, mv_y_max*4 );
  109. + if( mx != bpred_mx || my != bpred_my )
  110. + COST_MV_HPEL( mx, my );
  111. + }
  112. + }
  113. + else
  114. {
  115. - int mx = mvc[i][0];
  116. - int my = mvc[i][1];
  117. - if( (mx | my) && ((mx-bmx) | (my-bmy)) )
  118. + for( i = 0; i < i_mvc; i++ )
  119. {
  120. - mx = x264_clip3( mx, mv_x_min*4, mv_x_max*4 );
  121. - my = x264_clip3( my, mv_y_min*4, mv_y_max*4 );
  122. - COST_MV_HPEL( mx, my );
  123. + const int mx = x264_clip3( mvc[i][0], mv_x_min*4, mv_x_max*4 );
  124. + const int my = x264_clip3( mvc[i][1], mv_y_min*4, mv_y_max*4 );
  125. + int doSearch = 1;
  126. + int j;
  127. + for(j = 0; j < i; j++)
  128. + {
  129. + if(mvc[i][0] == mvc[j][0] && mvc[i][1] == mvc[j][1]) doSearch = 0;
  130. + }
  131. + if( ( mx != bpred_mx || my != bpred_my ) && doSearch)
  132. + {
  133. + int bestcost;
  134. + int bestx = mx;
  135. + int besty = my;
  136. + COST_MV_HPEL2( mx, my, bestcost );
  137. + COPY3_IF_LT( bpred_cost, bestcost, bpred_mx, bestx, bpred_my, besty );
  138. + if(bestcost < 2*bpred_cost)
  139. + {
  140. + int n;
  141. + int dir = -2;
  142. + COST_MV_HPEL2(bestx-4,besty,costs[0]);
  143. + COST_MV_HPEL2(bestx-2,besty+4,costs[1]);
  144. + COST_MV_HPEL2(bestx+2,besty+4,costs[2]);
  145. + COST_MV_HPEL2(bestx+4,besty,costs[3]);
  146. + COST_MV_HPEL2(bestx+2,besty-4,costs[4]);
  147. + COST_MV_HPEL2(bestx-2,besty-4,costs[5]);
  148. + COPY2_IF_LT( bestcost, costs[0], dir, 0 );
  149. + COPY2_IF_LT( bestcost, costs[1], dir, 1 );
  150. + COPY2_IF_LT( bestcost, costs[2], dir, 2 );
  151. + COPY2_IF_LT( bestcost, costs[3], dir, 3 );
  152. + COPY2_IF_LT( bestcost, costs[4], dir, 4 );
  153. + COPY2_IF_LT( bestcost, costs[5], dir, 5 );
  154. + if( dir != -2 )
  155. + {
  156. + static const int hex2[8][2] = {{-2,-4}, {-4,0}, {-2,4}, {2,4}, {4,0}, {2,-4}, {-2,-4}, {-4,0}};
  157. + bestx += hex2[dir+1][0];
  158. + besty += hex2[dir+1][1];
  159. + for( n = 1; n < i_me_range && CHECK_MVRANGE4(bestx, besty); n++ )
  160. + {
  161. + static const int mod6[8] = {5,0,1,2,3,4,5,0};
  162. + const int odir = mod6[dir+1];
  163. + COST_MV_HPEL2(hex2[odir+0][0]+bestx,hex2[odir+0][1]+besty,costs[0]);
  164. + COST_MV_HPEL2(hex2[odir+1][0]+bestx,hex2[odir+1][1]+besty,costs[1]);
  165. + COST_MV_HPEL2(hex2[odir+2][0]+bestx,hex2[odir+2][1]+besty,costs[2]);
  166. + dir = -2;
  167. + COPY2_IF_LT( bestcost, costs[0], dir, odir-1 );
  168. + COPY2_IF_LT( bestcost, costs[1], dir, odir );
  169. + COPY2_IF_LT( bestcost, costs[2], dir, odir+1 );
  170. + if( dir == -2 )
  171. + break;
  172. + bestx += hex2[dir+1][0];
  173. + besty += hex2[dir+1][1];
  174. + }
  175. + }
  176. + COST_MV_HPEL3(bestx+2,besty-2);
  177. + COST_MV_HPEL3(bestx+2,besty);
  178. + COST_MV_HPEL3(bestx+2,besty+2);
  179. + COST_MV_HPEL3(bestx,besty-2);
  180. + COST_MV_HPEL3(bestx,besty+2);
  181. + COST_MV_HPEL3(bestx-2,besty-2);
  182. + COST_MV_HPEL3(bestx-2,besty);
  183. + COST_MV_HPEL3(bestx-2,besty+2);
  184. + COPY3_IF_LT(bpred_cost,bestcost,bpred_mx,bestx,bpred_my,besty);
  185. + }
  186. + }
  187. }
  188. }
  189. bmx = ( bpred_mx + 2 ) >> 2;
  190.  
Advertisement
Add Comment
Please, Sign In to add comment