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

📄 main.c

📁 H.263的压缩算法
💻 C
📖 第 1 页 / 共 5 页
字号:
    exit(-1);  }  if (successive_B_frames && scalability_mode)  {    fprintf(stderr,"Warning:");    fprintf(stderr,"Encoder does not yet support multiple scalability options.\n");    exit(-1);  }  /* check for mode restrictions */  if (syntax_arith_coding && (alternative_inter_vlc || modified_quantization))  {    fprintf(stderr,"Warning:");    fprintf(stderr, "Syntax based Arithmetic Coding cannot be used with Alternative Inter VLC, Improved PB or  Modified Quantization modes.\n");    exit(-1);  } if (EPTYPE==ON && pb_frames)  {    fprintf(stderr,"Warning:");    fprintf(stderr, "PB frames (annex G) mode cannot be use with any of the H.263 PLUS options.\nUse Improved PB frames (annex M) mode instead.\n");    exit(-1);  }  /* Open stream for writing */  streamfile = fopen (streamname, "wb");  if (streamname == NULL)   {    fprintf(stderr,"Unable to open streamfile\n");    exit(-1);  }	  /* Clear output files */  if ((cleared = fopen(outputfile,"wb")) == NULL)   {    fprintf(stderr,"Couldn't open outputfile: %s\n",outputfile);    exit(-1);  }  else   {    fclose(cleared);  }  if (writediff)   {    if ((cleared = fopen(diff_filename,"wb")) == NULL)     {      fprintf(stderr,"Couldn't open diff-file: %s\n",diff_filename);      exit(-1);    }    else     {      fclose(cleared);    }  }  if (QP == 0 || QPI == 0)   {    fprintf(stderr,"Warning:");    fprintf(stderr,"QP is zero. Bitstream will not be correctly decodable\n");  }  if (ref_frame_rate != 25.0 && ref_frame_rate != 30.0)   {    fprintf(stderr,"Warning: Reference frame rate should be 25 or 30 fps\n");  }  /* pb frames and improved pb frames can't be used together*/  if (pb_frames && improved_pb_frames)  {    fprintf(stdout,"PB frames option can't be used with Improved pb frames option\n");    fprintf(stdout,"PB frames option is ignored\n");  }  pic->target_frame_rate = (ref_frame_rate /                            (orig_frameskip * chosen_frameskip));  return;}/********************************************************************** * *	Name:         DeterminePictureType *	Description:  Sets next picture type to be encoded  *	 *	Input:        frame number, picture structure, frameskip (P and B) *         *	Returns:       *	Side effects:  * *	Date: 970930  Author: Michael Gallant <mikeg@ee.ubc.ca> * ***********************************************************************/void DeterminePictureType(int *frame_no, Pict *pic, int P_skip, int B_skip, int i){  static int last_P_skip;  if (0 == i || (force_intra ? (0 == i%force_intra) : 0))  {    /* Intra */    pic->picture_coding_type = PCT_INTRA;        if (0 == i)    {      *frame_no = prev_I_P_frame_no = start;      prev_I_P_pic_TR = pic->TR = prev_I_P_pic_TR;    }    else    {      *frame_no = prev_I_P_frame_no = prev_I_P_frame_no + P_skip;      prev_I_P_pic_TR = pic->TR = prev_I_P_pic_TR + (P_skip * orig_frameskip);    }  }  else  {    if ( (scalability_mode) && (PCT_INTER == prev_pict_type || PCT_INTRA == prev_pict_type) )    {      /* EI or EP pictures */      pic->picture_coding_type = (PCT_INTRA == prev_pict_type) ? PCT_EI : PCT_EP;      *frame_no = prev_I_P_frame_no;      pic->TR = prev_I_P_pic_TR;    }    else    {      if (successive_B_frames)      {        if (B_pictures_to_code)        {          /* B picture */          pic->picture_coding_type = PCT_B;          *frame_no = prev_I_P_frame_no - (B_pictures_to_code * B_skip);          --B_pictures_to_code;          pic->TR = prev_I_P_pic_TR + ( (successive_B_frames - B_pictures_to_code) *                                        (B_skip * orig_frameskip));          pic->TRB = pic->TR - prev_I_P_pic_TR;          TRP = last_P_skip;        }        else        {          /* P picture */          if (PCT_B == prev_pict_type)          {             prev_I_P_pic_TR = pic->TR + B_skip;          }          B_pictures_to_code = successive_B_frames;          if (prev_I_P_frame_no + P_skip <= end)          {            pic->picture_coding_type = PCT_INTER;            *frame_no = prev_I_P_frame_no = prev_I_P_frame_no + P_skip;            pic->TR = prev_I_P_pic_TR +                       (P_skip * orig_frameskip);            last_P_skip = P_skip;          }          else          {            *frame_no = prev_I_P_frame_no;            pic->picture_coding_type = -1;            pic->TR = prev_I_P_pic_TR;          }        }      }      else      {        if (pb_frames || improved_pb_frames)        {          if (prev_I_P_frame_no + P_skip > end)          {            *frame_no = prev_I_P_frame_no;            pic->picture_coding_type = -1;            pic->TR = prev_I_P_pic_TR;          }          else          {            if (PCT_INTRA == prev_pict_type || P_skip>8 || (prev_I_P_frame_no + 2*P_skip) > end)            { /* If previous picture is INTRA || the temporal reference of P thus                 the temporal reference of B is larger than 8 || there are not enough                 frames left to code as PB than code the next picture as P picture */              pic->PB = 0;              pic->picture_coding_type = PCT_INTER;                 *frame_no = prev_I_P_frame_no = prev_I_P_frame_no + P_skip;              prev_I_P_pic_TR = pic->TR = prev_I_P_pic_TR +                                           (P_skip * orig_frameskip);            }            else            {/* PB or IPB picture */              pic->PB = (improved_pb_frames) ? IM_PB_FRAMES : PB_FRAMES;              pic->picture_coding_type = (improved_pb_frames) ? PCT_IPB : PCT_PB;              *frame_no = prev_I_P_frame_no + P_skip;              prev_I_P_frame_no += 2 * P_skip;              prev_I_P_pic_TR = pic->TR = prev_I_P_pic_TR +                                           (2 * P_skip * orig_frameskip);            }          }        }        else        {          /* P picture */          pic->picture_coding_type = PCT_INTER;          *frame_no = prev_I_P_frame_no = prev_I_P_frame_no + P_skip;          prev_I_P_pic_TR = pic->TR = prev_I_P_pic_TR +                                       (P_skip * orig_frameskip);        }      }    }  }  if (*frame_no > end)   {    pic->picture_coding_type = -1;    pic->TR = prev_I_P_pic_TR;  }}/********************************************************************** * *	Name:         CalculateStatistics *	Description:  Displays bit usage and SNR info *	 *	Input:        current image and reconstructed image, bit structure *                    and picture structure *         *	Returns:       *	Side effects:  * *	Date: 970930  Author: Michael Gallant <mikeg@ee.ubc.ca> * ***********************************************************************/void CalculateStatistics(PictImage *curr_image, PictImage *curr_recon,                          PictImage *pb_b_image, PictImage *pb_b_recon,                          Bits *bits, int QP, Pict *pic){  fprintf(stdout,"done\n");  ComputeSNR(curr_image, curr_recon, res, pic->picture_coding_type, writediff);  fflush(stdout);  if (arith_used)   {    bits->header += encoder_flush();    arith_used = 0;  }  bits->header += alignbits ();  /* pictures shall be byte aligned */  AddBitsPicture(bits);        switch (pic->picture_coding_type)  {    case PCT_INTRA:      fprintf(stdout,"Average Intra QP: %d\n", QP);      AddRes(intra_res,res,pic);      AddBits(intra_bits, bits);      break;    case PCT_INTER:      fprintf(stdout,"Results for P-frame:\n");      AddRes(inter_res,res,pic);      fprintf(stdout,"Average Inter QP: %5.2f\n", pic->QP_mean);      AddBits(inter_bits, bits);      AddBits(total_bits, bits);        break;    case PCT_PB:    case PCT_IPB:      fprintf(stdout,"Results for P component of PB frame:\n");      AddRes(inter_res,res,pic);      PrintSNR(res, 1);      ComputeSNR(pb_b_image, pb_b_recon, res, pic->picture_coding_type, writediff);      fprintf(stdout,"Results for B component of PB frame:\n");      AddRes(pb_res,res,pic);      fprintf(stdout,"Average P component QP: %d\n", QP);      fprintf(stdout,"Average B component BQUANT: %d\n", pic->BQUANT);      AddBits(pb_bits, bits);      AddBits(total_bits, bits);             break;    case PCT_B:      fprintf(stdout,"Results for true B-frame:\n");      AddRes(b_res,res,pic);      AddRes(scal_res,res,pic);      fprintf(stdout,"Average B QP: %d\n", QP);      AddBits(b_bits, bits);      AddBits(scal_bits, bits);             break;    case PCT_EI:      fprintf(stdout,"Results for EI frame:\n");      AddRes(ei_res,res,pic);      AddRes(scal_res,res,pic);      fprintf(stdout,"Average enhancement layer (EI) QP: %d\n", QP);      AddBits(ei_bits, bits);      AddBits(scal_bits, bits);            break;    case PCT_EP:      fprintf(stdout,"Results for EP frame:\n");      AddRes(ep_res,res,pic);      AddRes(scal_res,res,pic);      fprintf(stdout,"Average enhancement layer (EP) QP: %d\n", QP);      AddBits(ep_bits, bits);      AddBits(scal_bits, bits);            break;    default:      break;  }  PrintSNR(res, 1);  PrintResult(bits, 1, 1);}int FrameLayerRC(Pict *pic){  int frameskip;  switch (rate_control_method)   {    case  NO:       frameskip = chosen_frameskip;      break;    case TMN5_RC:    case TMN8_RC:      CommBacklog = mmax(0, CommBacklog + (int) (bits->total - (float) pic->bit_rate /                          ((pic->PB) ? (pic->target_frame_rate/2) :                                       (pic->target_frame_rate))));      frameskip = 1;      while (CommBacklog > ((float) pic->bit_rate / pic->target_frame_rate))      {        CommBacklog = mmax(0, (int) (CommBacklog - (float) pic->bit_rate /                            pic->target_frame_rate));        frameskip += 1;      }      frameskip = (int) (frameskip * pic->src_frame_rate / pic->target_frame_rate);      break;    case  OFFLINE_RC:       /* Aim for the targetrate with a once per frame rate control scheme */      if (frame_no - start > (end - start) * start_rate_control/100.0)          /* when generating the MPEG-4 anchors, rate control was started            after 70% of the sequence was finished.            Set start_rate_control with option "-R <n>" */        pic->QUANT = FrameUpdateQP(total_bits->total + intra_bits->total,                         bits->total,                     (end-frame_no) / chosen_frameskip + ((pic->PB) ? 1:0),                     QP, targetrate, seconds);      frameskip = chosen_frameskip;      break;          default:      break;          }    if (frameskip > 256)  {    fprintf (stderr, "Warning: frameskip > 256\n");  }    return frameskip;}     

⌨️ 快捷键说明

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