Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 16.01 KB | None | 0 0
  1. From b667b5d57e090e6554094eeaa4fc108dec3ad8dd Mon Sep 17 00:00:00 2001
  2. From: Dan Larkin <danielhlarkin@gmail.com>
  3. Date: Wed, 13 Jul 2011 11:33:48 -0500
  4. Subject: [PATCH 1/2] Preparation for --subme 11, threshold handling will change output
  5.  
  6. ---
  7. encoder/analyse.c |   24 ++++++++++++------------
  8.  1 files changed, 12 insertions(+), 12 deletions(-)
  9.  
  10. diff --git a/encoder/analyse.c b/encoder/analyse.c
  11. index 0dd7235..f27169c 100644
  12. --- a/encoder/analyse.c
  13. +++ b/encoder/analyse.c
  14. @@ -1033,7 +1033,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  15.  
  16.  static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  17.  {
  18. -    if( a->i_satd_i16x16 <= i_satd_thresh )
  19. +    if( a->i_satd_i16x16 < i_satd_thresh )
  20.      {
  21.          h->mb.i_type = I_16x16;
  22.          x264_analyse_update_cache( h, a );
  23. @@ -1042,7 +1042,7 @@ static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  24.      else
  25.          a->i_satd_i16x16 = COST_MAX;
  26.  
  27. -    if( a->i_satd_i4x4 <= i_satd_thresh && a->i_satd_i4x4 < COST_MAX )
  28. +    if( a->i_satd_i4x4 < i_satd_thresh )
  29.      {
  30.          h->mb.i_type = I_4x4;
  31.          x264_analyse_update_cache( h, a );
  32. @@ -1051,7 +1051,7 @@ static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  33.      else
  34.          a->i_satd_i4x4 = COST_MAX;
  35.  
  36. -    if( a->i_satd_i8x8 <= i_satd_thresh && a->i_satd_i8x8 < COST_MAX )
  37. +    if( a->i_satd_i8x8 < i_satd_thresh && a->i_satd_i8x8 < COST_MAX )
  38.      {
  39.          h->mb.i_type = I_8x8;
  40.          x264_analyse_update_cache( h, a );
  41. @@ -2576,7 +2576,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  42.          a->l0.i_rd16x16 = x264_rd_cost_mb( h, a->i_lambda2 );
  43.      }
  44.  
  45. -    if( a->l0.i_cost16x8 <= thresh )
  46. +    if( a->l0.i_cost16x8 < thresh )
  47.      {
  48.          h->mb.i_partition = D_16x8;
  49.          x264_analyse_update_cache( h, a );
  50. @@ -2585,7 +2585,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  51.      else
  52.          a->l0.i_cost16x8 = COST_MAX;
  53.  
  54. -    if( a->l0.i_cost8x16 <= thresh )
  55. +    if( a->l0.i_cost8x16 < thresh )
  56.      {
  57.          h->mb.i_partition = D_8x16;
  58.          x264_analyse_update_cache( h, a );
  59. @@ -2594,7 +2594,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  60.      else
  61.          a->l0.i_cost8x16 = COST_MAX;
  62.  
  63. -    if( a->l0.i_cost8x8 <= thresh )
  64. +    if( a->l0.i_cost8x8 < thresh )
  65.      {
  66.          h->mb.i_type = P_8x8;
  67.          h->mb.i_partition = D_8x8;
  68. @@ -2655,7 +2655,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  69.      //FIXME not all the update_cache calls are needed
  70.      h->mb.i_partition = D_16x16;
  71.      /* L0 */
  72. -    if( a->l0.me16x16.cost <= thresh && a->l0.i_rd16x16 == COST_MAX )
  73. +    if( a->l0.me16x16.cost < thresh && a->l0.i_rd16x16 == COST_MAX )
  74.      {
  75.          h->mb.i_type = B_L0_L0;
  76.          x264_analyse_update_cache( h, a );
  77. @@ -2663,7 +2663,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  78.      }
  79.  
  80.      /* L1 */
  81. -    if( a->l1.me16x16.cost <= thresh && a->l1.i_rd16x16 == COST_MAX )
  82. +    if( a->l1.me16x16.cost < thresh && a->l1.i_rd16x16 == COST_MAX )
  83.      {
  84.          h->mb.i_type = B_L1_L1;
  85.          x264_analyse_update_cache( h, a );
  86. @@ -2671,7 +2671,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  87.      }
  88.  
  89.      /* BI */
  90. -    if( a->i_cost16x16bi <= thresh && a->i_rd16x16bi == COST_MAX )
  91. +    if( a->i_cost16x16bi < thresh && a->i_rd16x16bi == COST_MAX )
  92.      {
  93.          h->mb.i_type = B_BI_BI;
  94.          x264_analyse_update_cache( h, a );
  95. @@ -2679,7 +2679,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  96.      }
  97.  
  98.      /* 8x8 */
  99. -    if( a->i_cost8x8bi <= thresh && a->i_rd8x8bi == COST_MAX )
  100. +    if( a->i_cost8x8bi < thresh && a->i_rd8x8bi == COST_MAX )
  101.      {
  102.          h->mb.i_type = B_8x8;
  103.          h->mb.i_partition = D_8x8;
  104. @@ -2689,7 +2689,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  105.      }
  106.  
  107.      /* 16x8 */
  108. -    if( a->i_cost16x8bi <= thresh && a->i_rd16x8bi == COST_MAX )
  109. +    if( a->i_cost16x8bi < thresh && a->i_rd16x8bi == COST_MAX )
  110.      {
  111.          h->mb.i_type = a->i_mb_type16x8;
  112.          h->mb.i_partition = D_16x8;
  113. @@ -2698,7 +2698,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  114.      }
  115.  
  116.      /* 8x16 */
  117. -    if( a->i_cost8x16bi <= thresh && a->i_rd8x16bi == COST_MAX )
  118. +    if( a->i_cost8x16bi < thresh && a->i_rd8x16bi == COST_MAX )
  119.      {
  120.          h->mb.i_type = a->i_mb_type8x16;
  121.          h->mb.i_partition = D_8x16;
  122. --
  123. 1.7.4.1
  124.  
  125.  
  126. From 0359b664e37fad03d560456870e8eda6a84a2622 Mon Sep 17 00:00:00 2001
  127. From: Dan Larkin <danielhlarkin@gmail.com>
  128. Date: Wed, 13 Jul 2011 12:45:23 -0500
  129. Subject: [PATCH 2/2] Added --subme 11, which disables all early terminations in analysis
  130.  
  131. ---
  132. encoder/analyse.c |   47 +++++++++++++++++++++++++----------------------
  133.  encoder/encoder.c |    4 ++--
  134.  encoder/me.c      |    1 +
  135.  3 files changed, 28 insertions(+), 24 deletions(-)
  136.  
  137. diff --git a/encoder/analyse.c b/encoder/analyse.c
  138. index f27169c..3bf3153 100644
  139. --- a/encoder/analyse.c
  140. +++ b/encoder/analyse.c
  141. @@ -132,6 +132,7 @@ typedef struct
  142.      int i_mb_type8x16;
  143.  
  144.      int b_direct_available;
  145. +    int b_early_terminate;
  146.  
  147.  } x264_mb_analysis_t;
  148.  
  149. @@ -587,6 +588,8 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int qp )
  150.          else
  151.              a->b_force_intra = 0;
  152.      }
  153. +    
  154. +    a->b_early_terminate = h->param.analyse.i_subpel_refine < 11;
  155.  }
  156.  
  157.  /* Prediction modes allowed for various combinations of neighbors. */
  158. @@ -782,7 +785,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  159.  
  160.      /* Not heavily tuned */
  161.      static const uint8_t i16x16_thresh_lut[11] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4 };
  162. -    int i16x16_thresh = a->b_fast_intra ? (i16x16_thresh_lut[h->mb.i_subpel_refine]*i_satd_inter)>>1 : COST_MAX;
  163. +    int i16x16_thresh = (a->b_early_terminate && a->b_fast_intra) ? (i16x16_thresh_lut[h->mb.i_subpel_refine]*i_satd_inter)>>1 : COST_MAX;
  164.  
  165.      if( !h->mb.b_lossless && predict_mode[3] >= 0 )
  166.      {
  167. @@ -834,7 +837,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  168.      {
  169.          ALIGNED_ARRAY_16( pixel, edge,[33] );
  170.          x264_pixel_cmp_t sa8d = (h->pixf.mbcmp[0] == h->pixf.satd[0]) ? h->pixf.sa8d[PIXEL_8x8] : h->pixf.mbcmp[PIXEL_8x8];
  171. -        int i_satd_thresh = a->i_mbrd ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
  172. +        int i_satd_thresh = (!a->b_early_terminate || a->i_mbrd) ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
  173.  
  174.          // FIXME some bias like in i4x4?
  175.          int i_cost = lambda * 4; /* base predmode costs */
  176. @@ -927,7 +930,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  177.          }
  178.          /* Not heavily tuned */
  179.          static const uint8_t i8x8_thresh[11] = { 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6 };
  180. -        if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
  181. +        if( a->b_early_terminate && X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
  182.              return;
  183.      }
  184.  
  185. @@ -935,10 +938,10 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  186.      if( flags & X264_ANALYSE_I4x4 )
  187.      {
  188.          int i_cost = lambda * (24+16); /* 24from JVT (SATD0), 16 from base predmode costs */
  189. -        int i_satd_thresh = X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 );
  190. +        int i_satd_thresh = a->b_early_terminate ? X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 ) : COST_MAX;
  191.          h->mb.i_cbp_luma = 0;
  192.  
  193. -        if( a->i_mbrd )
  194. +        if( a->b_early_terminate && a->i_mbrd )
  195.              i_satd_thresh = i_satd_thresh * (10-a->b_fast_intra)/8;
  196.  
  197.          if( h->sh.i_type == SLICE_TYPE_B )
  198. @@ -1572,7 +1575,7 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a, int i
  199.  
  200.          /* Early termination based on the current SATD score of partition[0]
  201.             plus the estimated SATD score of partition[1] */
  202. -        if( !i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  203. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  204.          {
  205.              a->l0.i_cost16x8 = COST_MAX;
  206.              return;
  207. @@ -1637,7 +1640,7 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a, int i
  208.  
  209.          /* Early termination based on the current SATD score of partition[0]
  210.             plus the estimated SATD score of partition[1] */
  211. -        if( !i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  212. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  213.          {
  214.              a->l0.i_cost8x16 = COST_MAX;
  215.              return;
  216. @@ -2454,8 +2457,8 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a, int i
  217.  
  218.          /* Early termination based on the current SATD score of partition[0]
  219.             plus the estimated SATD score of partition[1] */
  220. -        if( !i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  221. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  222. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  223. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  224.          {
  225.              a->i_cost16x8bi = COST_MAX;
  226.              return;
  227. @@ -2547,8 +2550,8 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  228.  
  229.          /* Early termination based on the current SATD score of partition[0]
  230.             plus the estimated SATD score of partition[1] */
  231. -        if( !i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  232. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  233. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  234. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  235.          {
  236.              a->i_cost8x16bi = COST_MAX;
  237.              return;
  238. @@ -2566,10 +2569,10 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  239.  
  240.  static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  241.  {
  242. -    int thresh = i_satd * 5/4;
  243. +    int thresh = a->b_early_terminate ? i_satd * 5/4 : COST_MAX;
  244.  
  245.      h->mb.i_type = P_L0;
  246. -    if( a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2 )
  247. +    if( !a->b_early_terminate || (a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2) )
  248.      {
  249.          h->mb.i_partition = D_16x16;
  250.          x264_analyse_update_cache( h, a );
  251. @@ -2639,7 +2642,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  252.  
  253.  static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_inter )
  254.  {
  255. -    int thresh = i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16;
  256. +    int thresh = a->b_early_terminate ? i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16 : COST_MAX;
  257.  
  258.      if( a->b_direct_available && a->i_rd16x16direct == COST_MAX )
  259.      {
  260. @@ -3020,8 +3023,8 @@ intra_analysis:
  261.              i_partition = D_16x16;
  262.              i_cost = analysis.l0.me16x16.cost;
  263.  
  264. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  265. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost )
  266. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  267. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost) )
  268.              {
  269.                  i_type = P_8x8;
  270.                  i_partition = D_8x8;
  271. @@ -3056,8 +3059,8 @@ intra_analysis:
  272.  
  273.              /* Now do 16x8/8x16 */
  274.              i_thresh16x8 = analysis.l0.me8x8[1].cost_mv + analysis.l0.me8x8[2].cost_mv;
  275. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  276. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8 )
  277. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  278. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8) )
  279.              {
  280.                  int i_avg_mv_ref_cost = (analysis.l0.me8x8[2].cost_mv + analysis.l0.me8x8[2].i_ref_cost
  281.                                        + analysis.l0.me8x8[3].cost_mv + analysis.l0.me8x8[3].i_ref_cost + 1) >> 1;
  282. @@ -3177,7 +3180,7 @@ intra_analysis:
  283.                  h->mb.i_partition = i_partition;
  284.                  if( i_cost < COST_MAX )
  285.                      x264_mb_analyse_transform_rd( h, &analysis, &i_satd_inter, &i_cost );
  286. -                x264_intra_rd( h, &analysis, i_satd_inter * 5/4 );
  287. +                x264_intra_rd( h, &analysis, analysis.b_early_terminate ? i_satd_inter * 5/4 : COST_MAX );
  288.              }
  289.  
  290.              COPY2_IF_LT( i_cost, analysis.i_satd_i16x16, i_type, I_16x16 );
  291. @@ -3431,17 +3434,17 @@ intra_analysis:
  292.  
  293.                  /* We can gain a little speed by checking the mode with the lowest estimated cost first */
  294.                  int try_16x8_first = i_cost_est16x8bi_total < i_cost_est8x16bi_total;
  295. -                if( try_16x8_first && i_cost_est16x8bi_total < i_cost )
  296. +                if( !analysis.b_early_terminate || (try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  297.                  {
  298.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  299.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  300.                  }
  301. -                if( i_cost_est8x16bi_total < i_cost )
  302. +                if( !analysis.b_early_terminate || i_cost_est8x16bi_total < i_cost )
  303.                  {
  304.                      x264_mb_analyse_inter_b8x16( h, &analysis, i_cost );
  305.                      COPY3_IF_LT( i_cost, analysis.i_cost8x16bi, i_type, analysis.i_mb_type8x16, i_partition, D_8x16 );
  306.                  }
  307. -                if( !try_16x8_first && i_cost_est16x8bi_total < i_cost )
  308. +                if( analysis.b_early_terminate && (!try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  309.                  {
  310.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  311.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  312. diff --git a/encoder/encoder.c b/encoder/encoder.c
  313. index 79880a3..4022819 100644
  314. --- a/encoder/encoder.c
  315. +++ b/encoder/encoder.c
  316. @@ -503,7 +503,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  317.      h->param.rc.f_rf_constant = x264_clip3f( h->param.rc.f_rf_constant, -QP_BD_OFFSET, 51 );
  318.      h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
  319.      h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, 0, QP_MAX );
  320. -    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 10 );
  321. +    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
  322.      h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
  323.      h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
  324.      if( h->param.rc.i_rc_method == X264_RC_CRF )
  325. @@ -784,7 +784,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  326.          h->param.rc.f_aq_strength = 0;
  327.      }
  328.      h->param.analyse.i_noise_reduction = x264_clip3( h->param.analyse.i_noise_reduction, 0, 1<<16 );
  329. -    if( h->param.analyse.i_subpel_refine == 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  330. +    if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  331.          h->param.analyse.i_subpel_refine = 9;
  332.  
  333.      {
  334. diff --git a/encoder/me.c b/encoder/me.c
  335. index ca6c602..10b7ef2 100644
  336. --- a/encoder/me.c
  337. +++ b/encoder/me.c
  338. @@ -46,6 +46,7 @@ static const uint8_t subpel_iterations[][4] =
  339.      {0,0,2,2},
  340.      {0,0,4,10},
  341.      {0,0,4,10},
  342. +    {0,0,4,10},
  343.      {0,0,4,10}};
  344.  
  345.  /* (x-1)%6 */
  346. --
  347. 1.7.4.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement