📄 global.h
字号:
{{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
};
/* Table B-15, DCT coefficients table one
*
* indexed by [run][level-1]
* split into two tables (dct_code_tab1a, dct_code_tab2a) to reduce size
* 'End of Block' is treated elsewhere
* codes do not include s (sign bit)
*/
static VLCtable dct_code_tab1a[2][40]=
{
/* run = 0, level = 1...40 */
{
{0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
{0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
{0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
{0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
{0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
{0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
{0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
{0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
{0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
{0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
},
/* run = 1, level = 1...18 */
{
{0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
{0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
{0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
{0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
{0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
{0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
{0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
{0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
{0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
{0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
}
};
static VLCtable dct_code_tab2a[30][5]=
{
/* run = 2...31, level = 1...5 */
{{0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10}, {0x14,13}},
{{0x07, 5}, {0x26, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
{{0x06, 6}, {0xfd, 8}, {0x12,12}, {0x00, 0}, {0x00, 0}},
{{0x07, 6}, {0x04, 9}, {0x12,13}, {0x00, 0}, {0x00, 0}},
{{0x06, 7}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
{{0x04, 7}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x05, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x78, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x7a, 7}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x21, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x25, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x24, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x05, 9}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x07, 9}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x0d,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
{{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
};
/////////////////////////////////////
/////////////////////////////////////////////////
static double c[8][8]; /* 变换系数 */
/* picture data arrays */
/* reconstructed frames */
unsigned char *newrefframe[3], *oldrefframe[3], *auxframe[3];
/* original frames */
unsigned char *neworgframe[3], *oldorgframe[3], *auxorgframe[3];
/* prediction of current frame */
unsigned char *predframe[3];
/* 8*8 block data */
short (*blocks)[64];
/* intra / non_intra quantization matrices */
unsigned char intra_q[64], inter_q[64];
unsigned char chrom_intra_q[64],chrom_inter_q[64];
/* prediction values for DCT coefficient (0,0) */
int dc_dct_pred[3];
/* macroblock side information array */
struct mbinfo *mbinfo;
/* motion estimation parameters */
struct motion_data *motion_data;
/* clipping (=saturation) table */
unsigned char *clp;
/* name strings */
char id_string[256], tplorg[256], tplref[256];
char iqname[256], niqname[256];
char statname[256];
char errortext[256];
FILE *outfile, *statfile; /* file descriptors */
int inputtype; /* format of input frames */
int quiet; /* suppress warnings */
/* coding model parameters */
int N; /* number of frames in Group of Pictures */
int M; /* distance between I/P frames */
int P; /* intra slice refresh interval */
int nframes; /* total number of frames to encode */
int frame0,tc0; /* number and timecode of first frame */
int mpeg1; /* ISO/IEC IS 11172-2 sequence */
int fieldpic; /* use field pictures */
/* sequence specific data (sequence header) */
int horizontal_size, vertical_size; /* frame size (pels) */
int width, height; /* encoded frame size (pels) multiples of 16 or 32 */
int chrom_width,chrom_height,block_count;
int mb_width, mb_height; /* frame size (macroblocks) */
int width2, height2, mb_height2, chrom_width2; /* picture size */
int aspectratio; /* aspect ratio information (pel or display) */
int frame_rate_code; /* coded value of frame rate */
double frame_rate; /* frames per second */
double bit_rate; /* bits per second */
int vbv_buffer_size; /* size of VBV buffer (* 16 kbit) */
int constrparms; /* constrained parameters flag (MPEG-1 only) */
int load_iquant, load_niquant; /* use non-default quant. matrices */
int load_ciquant,load_cniquant;
/* sequence specific data (sequence extension) */
int profile, level; /* syntax / parameter constraints */
int prog_seq; /* progressive sequence */
int chroma_format;
int low_delay; /* no B pictures, skipped pictures */
/* sequence specific data (sequence display extension) */
int video_format; /* component, PAL, NTSC, SECAM or MAC */
int color_primaries; /* source primary chromaticity coordinates */
int transfer_characteristics; /* opto-electronic transfer char. (gamma) */
int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */
int display_horizontal_size, display_vertical_size; /* display size */
/* picture specific data (picture header) */
int temp_ref; /* temporal reference */
int pict_type; /* picture coding type (I, P or B) */
int vbv_delay; /* video buffering verifier delay (1/90000 seconds) */
/* picture specific data (picture coding extension) */
int forw_hor_f_code, forw_vert_f_code;
int back_hor_f_code, back_vert_f_code; /* motion vector ranges */
int dc_prec; /* DC coefficient precision for intra coded blocks */
int pict_struct; /* picture structure (frame, top / bottom field) */
int topfirst; /* display top field first */
/* use only frame prediction and frame DCT (I,P,B,current) */
int frame_pred_dct_tab[3], frame_pred_dct;
int conceal_tab[3]; /* use concealment motion vectors (I,P,B) */
int qscale_tab[3], q_scale_type; /* linear/non-linear quantizaton table */
int intravlc_tab[3], intravlc; /* intra vlc format (I,P,B,current) */
int altscan_tab[3], altscan; /* alternate scan (I,P,B,current) */
int repeatfirst; /* repeat first field after second field */
int prog_frame; /* progressive frame */
unsigned char zig_zag_scan[64]={0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63};
/* alternate scan */
unsigned char alternate_scan[64]={
0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
};
/* default intra quantization matrix */
unsigned char default_intra_quantizer_matrix[64]=
{
8, 16, 19, 22, 26, 27, 29, 34,
16, 16, 22, 24, 27, 29, 34, 37,
19, 22, 26, 27, 29, 34, 34, 38,
22, 22, 26, 27, 29, 34, 37, 40,
22, 26, 27, 29, 32, 35, 40, 48,
26, 27, 29, 32, 35, 40, 48, 58,
26, 27, 29, 34, 38, 46, 56, 69,
27, 29, 35, 38, 46, 56, 69, 83
};
/* non-linear quantization coefficient table */
unsigned char non_linear_mquant_table[32]=
{
0, 1, 2, 3, 4, 5, 6, 7,
8,10,12,14,16,18,20,22,
24,28,32,36,40,44,48,52,
56,64,72,80,88,96,104,112
};
/* non-linear mquant table for mapping from scale to code
* since reconstruction levels are not bijective with the index map,
* it is up to the designer to determine most of the quantization levels
*/
unsigned char map_non_linear_mquant[113]=
{
0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,
22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,
26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,
29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31
};
static char profile_level_defined[5][4]={
/* HL H-14 ML LL */
{1, 1, 1, 0}, /* HP */
{0, 1, 0, 0}, /* Spat */
{0, 0, 1, 1}, /* SNR */
{1, 1, 1, 1}, /* MP */
{0, 0, 1, 0} /* SP */};
//conform.c
void range_checks(void);
void profile_and_level_checks();
//fdctref.c
void init_fdct(void);
void fdct(short *block);
//idct.c
void idct(short *block);
void init_idct(void);
//motion.c
void motion_estimation(unsigned char *oldorg, unsigned char *neworg,
unsigned char *oldref, unsigned char *newref, unsigned char *cur,
unsigned char *curref, int sxf, int syf, int sxb, int syb,
struct mbinfo *mbi, int secondfield, int ipflag);
//mpeg2enc.c
void error(char *text);
//predict.c
void predict(unsigned char *reff[], unsigned char *refb[],
unsigned char *cur[3], int secondfield, struct mbinfo *mbi);
//putbits.c
void initbits(void);
void putbits(int val, int n);
void alignbits(void);
int bitcount(void);
//puthdr.c
void putseqhdr(void);
void putseqext(void);
void putseqdispext(void);
void putuserdata(char *userdata);
void putgophdr(int frame, int closed_gop);
void putpicthdr(void);
void putpictcodext(void);
void putseqend(void);
//putmpg.c
void putintrablk(short *blk, int cc);
void putnonintrablk(short *blk);
void putmv(int dmv, int f_code);
//putpic.c
void putpict(unsigned char *frame);
//putseq.c
//void putseq(void);
//putvlc.c
void putDClum(int val);
void putDCchrom(int val);
void putACfirst(int run, int val);
void putAC(int run, int signed_level, int vlcformat);
void putaddrinc(int addrinc);
void putmbtype(int pict_type, int mb_type);
void putmotioncode(int motion_code);
void putdmv(int dmv);
void putcbp(int cbp);
//quantize.c
int quant_intra(short *src, short *dst, int dc_prec,unsigned char *quant_mat, int mquant);
int quant_non_intra(short *src, short *dst,unsigned char *quant_mat, int mquant);
void iquant_intra(short *src, short *dst, int dc_prec,unsigned char *quant_mat, int mquant);
void iquant_non_intra(short *src, short *dst,unsigned char *quant_mat, int mquant);
//ratectl.c
void rc_init_seq(void);
void rc_init_GOP(int np, int nb);
void rc_init_pict(unsigned char *frame);
void rc_update_pict(void);
int rc_start_mb(void);
int rc_calc_mquant(int j);
void vbv_end_of_picture(void);
void calc_vbv_delay(void);
//readpic.c
void readframe(char *fname, unsigned char *frame[]);
//stats.c
void calcSNR(unsigned char *org[3], unsigned char *rec[3]);
void stats(void);
//transfrm.c
void transform(unsigned char *pred[], unsigned char *cur[],struct mbinfo *mbi, short blocks[][64]);
void itransform(unsigned char *pred[], unsigned char *cur[],struct mbinfo *mbi, short blocks[][64]);
void dct_type_estimation(unsigned char *pred, unsigned char *cur,struct mbinfo *mbi);
//writepic.c
void writeframe(char *fname, unsigned char *frame[]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -