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

📄 ratecontrol.h

📁 用MPEG-4对YUV视频文件编码压缩成divx视频文件
💻 H
字号:
#ifndef _RATECONTROL_H_
#define _RATECONTROL_H_

/*#include "../encoder.h" */
#include "../portab.h"
/*#include "stdio.h"*/
#include "rc_data.h"
#define MAX_SLIDING_WINDOW 20

/*
typedef struct
{
	int64_t size;
	int32_t count;
}
QuantInfo;
*/

typedef struct
{
	int32_t rtn_quant;
	int64_t frames;
	int64_t total_size;
	double framerate;
	int32_t target_rate;
	int16_t max_quant;
	int16_t min_quant;
	int64_t last_change;
	int64_t quant_sum;
	double quant_error[32];
	double avg_framesize;
	double target_framesize;
	double sequence_quality;
	int32_t averaging_period;
	int32_t reaction_delay_factor;
	int32_t buffer;
}
RateControl;


/*
	Rs: 	bit rate for the sequence (or segment).  e.g., 24000 bits/sec */
/*	Rf: 	bits used for the first frame. e.g., 10000 bits */
/*	Rc:	bits used for the current frame. It is the bit count obtained after encoding.
	Rp:	bits  to be removed from the buffer per picture.
	Ts: 	number of seconds for the sequence  (or segment).  e.g., 10 sec */
/*	Ec:	mean absolute difference for the current frame after motion compensation.
		If the macroblock is intra coded, the original spatial pixel values are summed.
	Qc:	quantisation level used for the current frame. 
	Nr:	number of P frames remaining for encoding.
	Ns:	distance between encoded frames.  e.g., 4 for 7.5 fps */
/*	Rr:	number of bits remaining for encoding this sequence (or segment).
	T:	target bit to be used for the current frame.
	S:	number of bits used for encoding the previous frame.
	Hc:	header and motion vector bits used in the current frame. It includes all the 	information except to the residual information.
	Hp:	header and motion vector bits used in the previous frame. It includes all the 	information except to the residual information.
	Ql:	quantisation level used in the previous frame
	Bs;	buffer size e.g., R/2
	B;	current buffer level e.g., R/4 - start from the middle of the buffer*/
typedef struct
   {

	BOOL IsFirst;/*是否为I,P,B的第一帧      */
	int Rc; /*:	bits used for the current frame. It is the bit count obtained after encoding. */
	int Ec; /*:	mean absolute difference for the current frame after motion compensation.
			If the macroblock is intra coded, the original spatial pixel values are summed.*/
	int Ep;/* 前一帧的平均绝对差,whq */
	int S;  /*:	number of bits used for encoding the previous frame.       */
	int Hc; /*:	header and motion vector bits used in the current frame. It includes all the 	information except to the residual information. */
	int Hp; /*:	header and motion vector bits used in the previous frame. It includes all the 	information except to the residual information.  */
	int Ql; /*:	quantisation level used in the previous frame    */
	int QpArray[MAX_SLIDING_WINDOW];/*数组中存放以前的量化值,用滑动窗口控制值的个数*/
	int Qc; /*:	quantisation level used for the current frame.  */
	double X1;  /*二阶模型的一次项系数*/
	double X2;  /*二阶模型的二次项系数*/
	double X11; /*一阶模型的系数*/
	double RpArray[MAX_SLIDING_WINDOW];/*过去帧的复杂度度量	   */
}RCQ2_DATA;

typedef struct{
	int Rp; /*:	bits  to be removed from the buffer per picture. */
	int Ts; /*: 	number of seconds for the sequence  (or segment).  e.g., 10 sec */
	int Bs; /*;	buffer size e.g., R/2 */
	int B;  /*;	current buffer level e.g., R/4 - start from the middle of the buffer */
	int Nr; /*:	number of frames remaining for encoding.   */
	int N_Total;/* total number of coded frame in a gop */	
	int Ns; /*:	distance between encoded frames.  e.g., 4 for 7.5 fps */
	int Rr; /*:	number of bits remaining for encoding this sequence (or segment). */
	int T;  /*:	target bit to be used for the current frame.                       */
	int Rs; /*: 	bit rate for the sequence (or segment).  e.g., 24000 bits/sec */
	int Rf; /*: 	bits used for the first frame.  e.g., 10000 bits */
	int max_key_interval;/*最大关键帧间隔  */
	double array_x[MAX_SLIDING_WINDOW][2];
	double  array_y[MAX_SLIDING_WINDOW];
	double  rc_error[MAX_SLIDING_WINDOW];
	RCQ2_DATA data[2];
	RCQ2_SAVE_QUEUE rc_queue[2];
}RCQ2;

/* new rate control */
int Get_Initial_Quant(RCQ2* rc,int frametype);/*得到初始量化值    */
int RC_GetQ(FILE *pfile,RCQ2* rc,int frametype,int mad);/*得到量化值   */
void RCInitialization(RCQ2* rc,int bitrate,int framerate,int sequence_time);/*初始化位率控制 */
void Target_Bit_Calculation(RCQ2* rc,int frametype);/*目标位率计算        */
void Quantisation_Calculation(FILE *pfile,RCQ2* rc,int frametype);/*计算量化值   */
void UpdateRDModel (RCQ2* rc,int frametype);/*更新二阶率失真模型         */                                          
void After_encoding_current( FILE *pfile,RCQ2* rc,int frametype,int length,int head_vector,int mad);/*编码一帧后调用   */
void Estimator(RCQ2* rc,int frametype,int * w); /*int Qp, uint32_t Rp,int w,uint32_t b  再估计用于去掉坏点    */
void RemoveOutlier(RCQ2* rc,int frametype,double X1,double X2,int Qp[],double Rp[],double Ec,int * w);/*去掉坏点  */
BOOL IsSkipFrame(RCQ2* rc); /*判断是否丢帧,new add  */



/* old rate control */
void RateControlInit(RateControl * rate_control,
					 uint32_t target_rate,
					 uint32_t reaction_delay_factor,
					 uint32_t averaging_period,
					 uint32_t buffer,
					 int framerate,
					 int max_quant,
					 int min_quant);

int RateControlGetQ(RateControl * rate_control,
					int keyframe);

void RateControlUpdate(RateControl * rate_control,
					   uint32_t quant,
					   int frame_size,
					   int keyframe);

static int get_initial_quant(int bpp);

#endif /* _RATECONTROL_H_ */

⌨️ 快捷键说明

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