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

📄 xmin.c

📁 h.263 c编码源码。目录下有input。qcif原始未压缩文件
💻 C
字号:

#include <stdio.h>

#include "libr263.h"
#include "rlib.h"

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif

FILE *outputstream; /* Must be declared global for OwnWriteFunction */

// 写bit到输出文件
void OwnWriteFunction(int byte)
{
  putc(byte, outputstream);

  return;
}
int EncodeBlocks[9][11]; 

void main ()
{
  CParam cparams;           // 参数 
  Bits bits;                //输出bit
  FILE  *inputstream;
  FILE  *reconfile;
  struct qcif qcif_frame;
  struct cif cif_frame;
  int framecount;


  /* Open input and output files */
  reconfile = fopen("recon.qcif","wb");     //b
  outputstream = fopen("output.263","wb");
  inputstream = fopen("input.qcif","rb");     // b


  if(!inputstream || !outputstream || !reconfile) {
    if(outputstream)
      fclose(outputstream);
    if(inputstream)
      fclose(inputstream);
    if(reconfile)
      fclose(reconfile);
    fprintf(stderr,"Cannot open in or output\n");
    exit(1);
  }

   cparams.format = CPARAM_QCIF;   
   framecount = 0;  

   //初始化cparams参数,pic参数
  InitCompress(&cparams);  

  //写入bit的函数
  WriteByteFunction = OwnWriteFunction;

  if(!ReadQCIF(inputstream,&qcif_frame)) {
    fprintf(stderr,"Cannot read from inputstream");
    exit(1);
  }
  

  cparams.inter = CPARAM_INTRA;  
  cparams.Q_intra = 8;
  cparams.data = &qcif_frame;


  fprintf(stderr,"qcif data is on: %p\n",&qcif_frame);
//  fprintf(stderr,"cif data is on: %p\n",&cif_frame);

  // 压缩第一帧I帧
  CompressToH263(&cparams, &bits);
  
  //重建qcif数据
  WriteQCIF(reconfile,cparams.recon);
//  WriteCIF(reconfile,cparams.recon);
  

  //帧间
  cparams.inter = CPARAM_INTER;
  cparams.half_pixel_searchwindow = 4;
  cparams.search_method = CPARAM_LOGARITHMIC;
  cparams.Q_inter = 8; 
  cparams.advanced_method = CPARAM_ADVANCED;   //1 
  cparams.EncodeThisBlock = &EncodeBlocks;



  while(ReadQCIF(inputstream, &qcif_frame))
  { 
    ++framecount;

//    if(framecount % 4 == 1) {
 
      if(cparams.advanced_method)  //1
	   FindMotion(&cparams,2,2);   //门限设定2,2,
                                   //每个宏块是否move,放入 *(params->EncodeThisBlock + j*mbc + i)
      CompressToH263(&cparams, &bits);
 //   }

    // In case of skipped frames, the previous frame is displayed again,
    //   therefore, the previous frame should be included in the recon-
    //   structed QCIF video stream.
    

    WriteQCIF(reconfile,cparams.recon);
  //   WriteCIF(reconfile,cparams.recon);

    // Not really nice, but it's just an example

    if(framecount > 88)
      break;
  }



  fclose(inputstream);
  fclose(outputstream);
  fclose(reconfile);

}

⌨️ 快捷键说明

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