⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c

📁 JM 11.0 KTA 2.1 Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
  {
    if (input->successive_Bframe ==input->jumpd)
    {
      enc_picture->frameNumberinFile= FrameNumberInFile;
    }
    else
    {
      enc_picture->frameNumberinFile= (FrameNumberInFile)/((input->jumpd-input->successive_Bframe-input->successive_Bframe+1));
    }
  }
#endif 
  // Here, img->structure may be either FRAME or BOTTOM FIELD depending on whether AFF coding is used
  // The picture structure decision changes really only the fld_flag

  if (img->fld_flag)            // field mode (use field when fld_flag=1 only)
  {
    field_mode_buffer (bits_fld, dis_fld_y, dis_fld_u, dis_fld_v);
    writeout_picture (top_pic);
    writeout_picture (bottom_pic);
  }
  else                          //frame mode
  {
    frame_mode_buffer (bits_frm, dis_frm_y, dis_frm_u, dis_frm_v);

#ifdef ADAPTIVE_QUANTIZATION
    if (input->UseAdaptiveQuantMatrix && mincost_flg == 0)
    {
      writeout_picture (frame_pic_aqms);
    }
    else
    {
      if (input->RDPictureDecision && img->rd_pass == 2)
        writeout_picture (frame_pic_3);
      else if (input->RDPictureDecision && img->rd_pass == 1)
        writeout_picture (frame_pic_2);
      else
        if(img->type==SP_SLICE && si_frame_indicator==1)
        {
          writeout_picture (frame_pic_2);
          si_frame_indicator=0;
        }
        else

#ifdef ADAPTIVE_FILTER
          if(img->AdaptiveFilterFlag == 1)
            writeout_picture(frame_pic_aif);
          else
#endif
            writeout_picture (frame_pic_1);
    }
#else
    if (input->RDPictureDecision && img->rd_pass == 2)
      writeout_picture (frame_pic_3);
    else if (input->RDPictureDecision && img->rd_pass == 1)
      writeout_picture (frame_pic_2);
    else
      if(img->type==SP_SLICE && si_frame_indicator==1)
      {
        writeout_picture (frame_pic_2);
        si_frame_indicator=0;
      }
      else
#ifdef ADAPTIVE_FILTER
        if(img->AdaptiveFilterFlag == 1)
          writeout_picture(frame_pic_aif);
        else
#endif
          writeout_picture (frame_pic_1);
#endif
  }

  if (frame_pic_3)
    free_slice_list(frame_pic_3);  
  if (frame_pic_2)
    free_slice_list(frame_pic_2);  
  if (frame_pic_1)
    free_slice_list(frame_pic_1);
  if (top_pic)
    free_slice_list(top_pic);
  if (bottom_pic)
    free_slice_list(bottom_pic);
#ifdef ADAPTIVE_FILTER
  if(frame_pic_aif)
    free_slice_list(frame_pic_aif);
  if(UseAdaptiveFilterForCurrentFrame() && img->AdaptiveFilterFlag==-1)
    img->AdaptiveFilterFlag=0;      // for the output only
#endif
#ifdef ADAPTIVE_QUANTIZATION
  if(input->UseAdaptiveQuantMatrix)
  {
    if (frame_pic_aqms);
    free_slice_list(frame_pic_aqms);
  }
#endif
  /*
  // Tian Dong (Sept 2002)
  // in frame mode, the newly reconstructed frame has been inserted to the mem buffer
  // and it is time to prepare the spare picture SEI payload.
  if (input->InterlaceCodingOption == FRAME_CODING
  && input->SparePictureOption && img->type != B_SLICE)
  CalculateSparePicture ();
  */

  //Rate control
  if(input->RCEnable)
  {
    bits = (int) (stats->bit_ctr - stats->bit_ctr_n);
    rc_update_pict_frame(bits);
  }

  if (input->PicInterlace == FRAME_CODING)
  {
    if (input->rdopt == 3 && img->type != B_SLICE)
      UpdateDecoders ();      // simulate packet losses and move decoded image to reference buffers

    if (input->RestrictRef)
      UpdatePixelMap ();
  }

  if (input->Verbose != 0)
    find_snr ();
  else
  {
    snr->snr_y = 0.0;
    snr->snr_u = 0.0;
    snr->snr_v = 0.0;
    snr->sse_y = 0.0;
    snr->sse_u = 0.0;
    snr->sse_v = 0.0;
  }

  // redundant pictures: save reconstruction to calculate SNR and replace reference picture
  if(input->redundant_pic_flag && key_frame)
  {
    for(i=0; i<img->width; i++)
    {
      for(j=0; j<img->height; j++)
      {
        imgY_tmp[j][i] = enc_frame_picture->imgY[j][i];
      }
    }
    for(i=0; i<img->width_cr; i++)
    {
      for(j=0; j<img->height_cr; j++)
      {
        imgUV_tmp[0][j][i] = enc_frame_picture->imgUV[0][j][i];
        imgUV_tmp[1][j][i] = enc_frame_picture->imgUV[1][j][i];
      }
    }
  }

  if(input->redundant_pic_flag && redundant_coding)
  {
    for(i=0; i<img->width; i++)
    {
      for(j=0; j<img->height; j++)
      {
        enc_frame_picture->imgY[j][i] = imgY_tmp[j][i];
      }
    }
    for(i=0; i<img->width_cr; i++)
    {
      for(j=0; j<img->height_cr; j++)
      {
        enc_frame_picture->imgUV[0][j][i] = imgUV_tmp[0][j][i];
        enc_frame_picture->imgUV[1][j][i] = imgUV_tmp[1][j][i];
      }
    }
  }

  time (&ltime2);               // end time sec
#ifdef WIN32
  _ftime (&tstruct2);           // end time ms
#else
  ftime (&tstruct2);            // end time ms
#endif

  tmp_time = (int)((ltime2 * 1000 + tstruct2.millitm) - (ltime1 * 1000 + tstruct1.millitm));
  tot_time = tot_time + tmp_time;

  if (input->PicInterlace == ADAPTIVE_CODING)
  {
    if (img->fld_flag)
    {
      // store bottom field
      store_picture_in_dpb(enc_bottom_picture);
      free_storable_picture(enc_frame_picture);
    }
    else
    {
      // replace top with frame
      replace_top_pic_with_frame(enc_frame_picture);
      free_storable_picture(enc_bottom_picture);
    }
  }
  else
  {
    if (img->fld_flag)
    {
      store_picture_in_dpb(enc_bottom_picture);
    }
    else
    {
#ifdef ADAPTIVE_QUANTIZATION
      if ( input->UseAdaptiveQuantMatrix && mincost_flg == 0)
      {
        store_picture_in_dpb(enc_frame_picture_aqms);
        free_storable_picture(enc_frame_picture);
        free_storable_picture(enc_frame_picture2);
        free_storable_picture(enc_frame_picture3);
#ifdef ADAPTIVE_FILTER
        free_storable_picture(enc_frame_picture_aif);
#endif
      }
      else
      {
        if (img->rd_pass==2)
        {
          store_picture_in_dpb(enc_frame_picture3);
          free_storable_picture(enc_frame_picture);
          free_storable_picture(enc_frame_picture2);
#ifdef ADAPTIVE_FILTER
          free_storable_picture(enc_frame_picture_aif);
#endif
        }
        else if (img->rd_pass==1)
        {
          store_picture_in_dpb(enc_frame_picture2);
          free_storable_picture(enc_frame_picture);
          free_storable_picture(enc_frame_picture3);
#ifdef ADAPTIVE_FILTER
          free_storable_picture(enc_frame_picture_aif);
#endif
        }
        else
        {

          if(input->redundant_pic_flag==0)
          {
#ifdef ADAPTIVE_FILTER
            if(img->AdaptiveFilterFlag==1)
            {
              store_picture_in_dpb(enc_frame_picture_aif);
              free_storable_picture(enc_frame_picture);
            }
            else
#endif
            {
              store_picture_in_dpb(enc_frame_picture);
#ifdef ADAPTIVE_FILTER
              free_storable_picture(enc_frame_picture_aif);
#endif
            }
            free_storable_picture(enc_frame_picture2);
            free_storable_picture(enc_frame_picture3);
          }
          else     
          {
            // key picture will be stored in dpb after redundant picture is coded
            if(key_frame==0)
            {
              store_picture_in_dpb(enc_frame_picture);
              free_storable_picture(enc_frame_picture2);
              free_storable_picture(enc_frame_picture3);
            }
          }
        }
        free_storable_picture(enc_frame_picture_aqms);
      }
#else
      if (img->rd_pass==2)
      {
        store_picture_in_dpb(enc_frame_picture3);
        free_storable_picture(enc_frame_picture);
        free_storable_picture(enc_frame_picture2);
#ifdef ADAPTIVE_FILTER
        free_storable_picture(enc_frame_picture_aif);
#endif
      }
      else if (img->rd_pass==1)
      {
        store_picture_in_dpb(enc_frame_picture2);
        free_storable_picture(enc_frame_picture);
        free_storable_picture(enc_frame_picture3);
#ifdef ADAPTIVE_FILTER
        free_storable_picture(enc_frame_picture_aif);
#endif
      }
      else
      {
        if(input->redundant_pic_flag==0)
        {
#ifdef ADAPTIVE_FILTER
          if(img->AdaptiveFilterFlag==1)
          {
            store_picture_in_dpb(enc_frame_picture_aif);
            free_storable_picture(enc_frame_picture);
          }
          else
#endif
          {
            store_picture_in_dpb(enc_frame_picture);
#ifdef ADAPTIVE_FILTER
            free_storable_picture(enc_frame_picture_aif);
#endif
          }
          free_storable_picture(enc_frame_picture2);
          free_storable_picture(enc_frame_picture3);
        }
        else     
        {
          // key picture will be stored in dpb after redundant picture is coded
          if(key_frame==0)
          {
            store_picture_in_dpb(enc_frame_picture);
            free_storable_picture(enc_frame_picture2);
            free_storable_picture(enc_frame_picture3);
          }
        }

      }
#endif
    }
  }

#ifdef _LEAKYBUCKET_
  // Store bits used for this frame and increment counter of no. of coded frames
  Bit_Buffer[total_frame_buffer] = (int) (stats->bit_ctr - stats->bit_ctr_n);
  total_frame_buffer++;
#endif

  // POC200301: Verify that POC coding type 2 is not used if more than one consecutive 
  // non-reference frame is requested or if decoding order is different from output order
  if (img->pic_order_cnt_type == 2)
  {
    if (!img->nal_reference_idc) consecutive_non_reference_pictures++;
    else consecutive_non_reference_pictures = 0;

    if (frame_no < prev_frame_no || consecutive_non_reference_pictures>1)
      error("POC type 2 cannot be applied for the coding pattern where the encoding /decoding order of pictures are different from the output order.\n", -1);
    prev_frame_no = frame_no;
  }

  if (stats->bit_ctr_parametersets_n!=0)
    ReportNALNonVLCBits(tmp_time, me_time);

  if (IMG_NUMBER == 0)
    ReportFirstframe(tmp_time,me_time);
  else
  {
    //Rate control
    if(input->RCEnable)
    {
      if((!input->PicInterlace)&&(!input->MbInterlace))
        bits=(int) (stats->bit_ctr - stats->bit_ctr_n);
      else
      {
        bits = (int) (stats->bit_ctr - Pprev_bits); // used for rate control update */
        Pprev_bits = stats->bit_ctr;
      }
    }

    switch (img->type)
    {
    case I_SLICE:
      stats->bit_ctr_I += stats->bit_ctr - stats->bit_ctr_n;
      ReportIntra(tmp_time,me_time);
      break;
    case SP_SLICE:
      stats->bit_ctr_P += stats->bit_ctr - stats->bit_ctr_n;
      ReportSP(tmp_time,me_time);
      break;
    case B_SLICE:
      stats->bit_ctr_B += stats->bit_ctr - stats->bit_ctr_n;
      ReportB(tmp_time,me_time);
      break;
    default:      // P
      stats->bit_ctr_P += stats->bit_ctr - stats->bit_ctr_n;
      ReportP(tmp_time,me_time);      
    }
  }  


  if (input->Verbose == 0)
  { 
    //for (i = 0; i <= (img->number & 0x0F); i++)
    //printf(".");
    //printf("                              \r");
    printf("Completed Encoding Frame %05d.\r",frame_no);
  }
  // Flush output statistics
  fflush(stdout);

  stats->bit_ctr_n = stats->bit_ctr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -