美文网首页
av1代码学习5---av1_encode()

av1代码学习5---av1_encode()

作者: 青吟乐 | 来源:发表于2020-06-21 12:44 被阅读0次

1,函数功能

函数主要从上一层将空域滤波完的图像像frame_input设置必须的一些属性后进行编码encode_frame_to_data_rate()

2,代码学习

//从上一层滤波后的图像frame_input设置一些属性后进行编码encode_frame_to_data_rate()
int av1_encode(AV1_COMP *const cpi, uint8_t *const dest,
               const EncodeFrameInput *const frame_input,
               const EncodeFrameParams *const frame_params,
               EncodeFrameResults *const frame_results) {
  AV1_COMMON *const cm = &cpi->common;  //设置目前的common
  CurrentFrame *const current_frame = &cm->current_frame;  //当前帧

  cpi->unscaled_source = frame_input->source;            //设置不量化帧
  cpi->source = frame_input->source;                     //设置原始帧
  cpi->unscaled_last_source = frame_input->last_source;  //上一帧

  current_frame->refresh_frame_flags = frame_params->refresh_frame_flags;//标志位
  cm->error_resilient_mode = frame_params->error_resilient_mode;//容错帧
  cm->primary_ref_frame = frame_params->primary_ref_frame;  //关键参考帧
  cm->current_frame.frame_type = frame_params->frame_type;  //当前帧类型
  cm->show_frame = frame_params->show_frame;
  cpi->ref_frame_flags = frame_params->ref_frame_flags;  //参考帧标志位
  cpi->speed = frame_params->speed;                      //编码速度
  cm->show_existing_frame = frame_params->show_existing_frame;  //貌似用于解码的选项
  cpi->existing_fb_idx_to_show = frame_params->existing_fb_idx_to_show;

  memcpy(
      cm->remapped_ref_idx, frame_params->remapped_ref_idx,
      REF_FRAMES *
          sizeof(
              *cm->remapped_ref_idx));  //根据frame_params->remapped_ref_idx申请新的参考帧列表空间
  /*依次刷新标志位*/
  cpi->refresh_last_frame = frame_params->refresh_last_frame;
  cpi->refresh_golden_frame = frame_params->refresh_golden_frame;
  cpi->refresh_bwd_ref_frame = frame_params->refresh_bwd_ref_frame;
  cpi->refresh_alt2_ref_frame = frame_params->refresh_alt2_ref_frame;
  cpi->refresh_alt_ref_frame = frame_params->refresh_alt_ref_frame;

  /*若当前帧是关键帧则作为第0帧*/
  if (current_frame->frame_type == KEY_FRAME && cm->show_frame)
    current_frame->frame_number = 0;
  /**/
  if (cm->show_existing_frame) {
    current_frame->order_hint = cm->cur_frame->order_hint;
    current_frame->display_order_hint = cm->cur_frame->display_order_hint;
  } else {
    current_frame->order_hint =
        current_frame->frame_number + frame_params->order_offset;
    current_frame->display_order_hint = current_frame->order_hint;
    current_frame->order_hint %=
        (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1));
  }

  if (cpi->oxcf.pass == 1) {
#if !CONFIG_REALTIME_ONLY
    av1_first_pass(cpi, frame_input->ts_duration);
#endif
  } else if (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2) {
    if (encode_frame_to_data_rate(cpi, &frame_results->size, dest) !=
        AOM_CODEC_OK) {
      return AOM_CODEC_ERROR;
    }
  } else {
    return AOM_CODEC_ERROR;
  }

  return AOM_CODEC_OK;
}

相关文章

网友评论

      本文标题:av1代码学习5---av1_encode()

      本文链接:https://www.haomeiwen.com/subject/ehnoxktx.html