Home | History | Annotate | Download | only in examples
      1 @TEMPLATE encoder_tmpl.c
      2 VP8 Set Active and ROI Maps
      3 ===========================
      4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
      5 This is an example demonstrating how to control the VP8 encoder's
      6 ROI and Active maps.
      7 
      8 ROI (Reigon of Interest) maps are a way for the application to assign
      9 each macroblock in the image to a region, and then set quantizer and
     10 filtering parameters on that image.
     11 
     12 Active maps are a way for the application to specify on a
     13 macroblock-by-macroblock basis whether there is any activity in that
     14 macroblock.
     15 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
     16 
     17 
     18 Configuration
     19 -------------
     20 An ROI map is set on frame 22. If the width of the image in macroblocks
     21 is evenly divisble by 4, then the output will appear to have distinct
     22 columns, where the quantizer, loopfilter, and static threshold differ
     23 from column to column.
     24 
     25 An active map is set on frame 33. If the width of the image in macroblocks
     26 is evenly divisble by 4, then the output will appear to have distinct
     27 columns, where one column will have motion and the next will not.
     28 
     29 The active map is cleared on frame 44.
     30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  PER_FRAME_CFG
     31 if(frame_cnt + 1 == 22) {
     32     vpx_roi_map_t  roi;
     33     int            i;
     34 
     35     roi.rows = cfg.g_h/16;
     36     roi.cols = cfg.g_w/16;
     37 
     38     roi.delta_q[0] = 0;
     39     roi.delta_q[1] = -2;
     40     roi.delta_q[2] = -4;
     41     roi.delta_q[3] = -6;
     42 
     43     roi.delta_lf[0] = 0;
     44     roi.delta_lf[1] = 1;
     45     roi.delta_lf[2] = 2;
     46     roi.delta_lf[3] = 3;
     47 
     48     roi.static_threshold[0] = 1500;
     49     roi.static_threshold[1] = 1000;
     50     roi.static_threshold[2] =  500;
     51     roi.static_threshold[3] =    0;
     52 
     53     /* generate an ROI map for example */
     54     roi.roi_map = malloc(roi.rows * roi.cols);
     55     for(i=0;i<roi.rows*roi.cols;i++)
     56         roi.roi_map[i] = i & 3;
     57 
     58     if(vpx_codec_control(&codec, VP8E_SET_ROI_MAP, &roi))
     59         die_codec(&codec, "Failed to set ROI map");
     60 
     61     free(roi.roi_map);
     62 } else if(frame_cnt + 1 == 33) {
     63     vpx_active_map_t  active;
     64     int               i;
     65 
     66     active.rows = cfg.g_h/16;
     67     active.cols = cfg.g_w/16;
     68 
     69     /* generate active map for example */
     70     active.active_map = malloc(active.rows * active.cols);
     71     for(i=0;i<active.rows*active.cols;i++)
     72         active.active_map[i] = i & 1;
     73 
     74     if(vpx_codec_control(&codec, VP8E_SET_ACTIVEMAP, &active))
     75         die_codec(&codec, "Failed to set active map");
     76 
     77     free(active.active_map);
     78 } else if(frame_cnt + 1 == 44) {
     79     vpx_active_map_t  active;
     80 
     81     active.rows = cfg.g_h/16;
     82     active.cols = cfg.g_w/16;
     83 
     84     /* pass in null map to disable active_map*/
     85     active.active_map = NULL;
     86 
     87     if(vpx_codec_control(&codec, VP8E_SET_ACTIVEMAP, &active))
     88         die_codec(&codec, "Failed to set active map");
     89 }
     90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  PER_FRAME_CFG
     91 
     92 
     93 Observing The Effects
     94 ---------------------
     95 Use the `simple_decoder` example to decode this sample, and observe
     96 the change in the image at frames 22, 33, and 44.
     97