av1/encoder/temporal_filter.c
// Setups the frame buffer for temporal filtering. Basically, this fuction
// determines how many frames will be used for temporal filtering and then
// groups them into a buffer.
// Inputs:
//   cpi: Pointer to the composed information of input video.
//   filter_frame_lookahead_idx: The index of the to-filter frame in the
//                               lookahead buffer `cpi->lookahead`.
//   is_second_arf: Whether the to-filter frame is the second ARF. This field
//                  will affect the number of frames used for filtering.
//   frames: Pointer to the frame buffer to setup.
//   num_frames_for_filtering: Number of frames used for filtering.
//   filter_frame_idx: Index of the to-filter frame in the setup frame buffer.
// Returns:
//   Nothing will be returned. But the frame buffer `frames`, number of frames
//   in the buffer `num_frames_for_filtering`, and the index of the to-filter
//   frame in the buffer `filter_frame_idx` will be updated in this function.
Setups the frame buffer for temporal filtering. Basically, this fuction
determines how many frames will be used for temporal filtering and then
groups them into a buffer.
Inputs:
cpi: Pointer to the composed information of input video.
filter_frame_lookahead_idx: The index of the to-filter frame in the
lookahead buffer `cpi->lookahead`.
is_second_arf: Whether the to-filter frame is the second ARF. This field
will affect the number of frames used for filtering.
frames: Pointer to the frame buffer to setup.
num_frames_for_filtering: Number of frames used for filtering.
filter_frame_idx: Index of the to-filter frame in the setup frame buffer.
Returns:
Nothing will be returned.
Setups the frame buffer for temporal filtering . Basically this fuction determines how many frames will be used for temporal filtering and then groups them into a buffer . Inputs : cpi : Pointer to the composed information of input video . filter_frame_lookahead_idx : The index of the to - filter frame in the lookahead buffer ` cpi - > lookahead ` . is_second_arf : Whether the to - filter frame is the second ARF . This field will affect the number of frames used for filtering . frames : Pointer to the frame buffer to setup . num_frames_for_filtering : Number of frames used for filtering . filter_frame_idx : Index of the to - filter frame in the setup frame buffer . Returns : Nothing will be returned .
static void tf_setup_filtering_buffer(const AV1_COMP *cpi,
                                      const int filter_frame_lookahead_idx,
                                      const int is_second_arf,
                                      YV12_BUFFER_CONFIG **frames,
                                      int *num_frames_for_filtering,
                                      int *filter_frame_idx) {
  int num_frames = 0;          
  int num_frames_before = -1;  
  int filter_frame_offset;
  if (filter_frame_lookahead_idx == -1) {  
    num_frames = TF_NUM_FILTERING_FRAMES_FOR_KEY_FRAME;
    num_frames_before = 0;
    filter_frame_offset = filter_frame_lookahead_idx;
  } else if (filter_frame_lookahead_idx < -1) {  
    num_frames = TF_NUM_FILTERING_FRAMES_FOR_KEY_FRAME;
    num_frames_before = num_frames - 1;
    filter_frame_offset = -filter_frame_lookahead_idx;
  } else {
    num_frames = cpi->oxcf.arnr_max_frames;
    if (is_second_arf) {  
      num_frames = AOMMIN(num_frames, 3);
    }
    if (num_frames > cpi->rc.gfu_boost / 150) {
      num_frames = cpi->rc.gfu_boost / 150;
      num_frames += !(num_frames & 1);
    }
    num_frames_before = AOMMIN(num_frames >> 1, filter_frame_lookahead_idx + 1);
    const int lookahead_depth =
        av1_lookahead_depth(cpi->lookahead, cpi->compressor_stage);
    const int num_frames_after =
        AOMMIN((num_frames - 1) >> 1,
               lookahead_depth - filter_frame_lookahead_idx - 1);
    num_frames = num_frames_before + 1 + num_frames_after;
    filter_frame_offset = filter_frame_lookahead_idx;
  }
  *num_frames_for_filtering = num_frames;
  *filter_frame_idx = num_frames_before;
  for (int frame = 0; frame < num_frames; ++frame) {
    const int lookahead_idx = frame - num_frames_before + filter_frame_offset;
    struct lookahead_entry *buf = av1_lookahead_peek(
        cpi->lookahead, lookahead_idx, cpi->compressor_stage);
    frames[frame] = (buf == NULL) ? NULL : &buf->img;
  }
}
static void tf_setup_filtering_buffer ( const AV1_COMP * cpi , const int filter_frame_lookahead_idx , const int is_second_arf , YV12_BUFFER_CONFIG * * frames , int * num_frames_for_filtering , int * filter_frame_idx ) { int num_frames = 0 ; int num_frames_before = -1 ; int filter_frame_offset ; if ( filter_frame_lookahead_idx == -1 ) { num_frames = TF_NUM_FILTERING_FRAMES_FOR_KEY_FRAME ; num_frames_before = 0 ; filter_frame_offset = filter_frame_lookahead_idx ; } else if ( filter_frame_lookahead_idx < -1 ) { num_frames = TF_NUM_FILTERING_FRAMES_FOR_KEY_FRAME ; num_frames_before = num_frames - 1 ; filter_frame_offset = - filter_frame_lookahead_idx ; } else { num_frames = cpi -> oxcf . arnr_max_frames ; if ( is_second_arf ) { num_frames = AOMMIN ( num_frames , 3 ) ; } if ( num_frames > cpi -> rc . gfu_boost / 150 ) { num_frames = cpi -> rc . gfu_boost / 150 ; num_frames += ! ( num_frames & 1 ) ; } num_frames_before = AOMMIN ( num_frames >> 1 , filter_frame_lookahead_idx + 1 ) ; const int lookahead_depth = av1_lookahead_depth ( cpi -> lookahead , cpi -> compressor_stage ) ; const int num_frames_after = AOMMIN ( ( num_frames - 1 ) >> 1 , lookahead_depth - filter_frame_lookahead_idx - 1 ) ; num_frames = num_frames_before + 1 + num_frames_after ; filter_frame_offset = filter_frame_lookahead_idx ; } * num_frames_for_filtering = num_frames ; * filter_frame_idx = num_frames_before ; for ( int frame = 0 ; frame < num_frames ; ++ frame ) { const int lookahead_idx = frame - num_frames_before + filter_frame_offset ; struct lookahead_entry * buf = av1_lookahead_peek ( cpi -> lookahead , lookahead_idx , cpi -> compressor_stage ) ; frames [ frame ] = ( buf == NULL ) ? NULL : & buf -> img ; } }
Setups the frame buffer for temporal filtering.
Setups the frame buffer for temporal filtering .
// Number of frames used for filtering. // Number of frames before the to-filter frame. // Key frame. // Key frame in one-pass mode. // Set `arnr_max_frames` as 1 to disable temporal filtering. // Only use 2 neighbours for the second ARF. // Setup the frame buffer.