📄 lencod.c
字号:
fprintf(p_stat,"\n");
fprintf(p_stat," -------------------|---------------|---------------|---------------|\n");
/* write to log file */
if (fopen("log.dat","r")==0) /* check if file exist */
{
if ((p_log=fopen("log.dat","a"))==0) /* append new statistic at the end */
{
printf("Error open file %s \n","log.dat");
exit(0);
}
else /* Create header for new log file */
{
fprintf(p_log," ---------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_log,"| Encoder statistics. This file is generated during first encoding session, new sessions will be appended |\n");
fprintf(p_log," ---------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_log,"| Date | Time | Sequence |#Img|Quant1|QuantN|Format|Hadamard|Search r|#Ref |Freq |Intra upd|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|#Bitr P|#Bitr B|\n");
fprintf(p_log," ---------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
}
}
else
p_log=fopen("log.dat","a"); /* File exist,just open for appending */
#ifdef WIN32
_strdate( timebuf );
fprintf(p_log,"| %1.5s |",timebuf );
_strtime( timebuf);
fprintf(p_log," % 1.5s |",timebuf);
#else
now = time ((time_t *) NULL); /* Get the system time and put it into 'now' as 'calender time' */
time (&now);
l_time = localtime (&now);
strftime (string, sizeof string, "%d-%b-%Y", l_time);
fprintf(p_log,"| %1.5s |",string );
strftime (string, sizeof string, "%H:%M:%S", l_time);
fprintf(p_log,"| %1.5s |",string );
#endif
for (i=0;i<20;i++)
name[i]=input->infile[i+max(0,strlen(input->infile)-20)]; /* write last part of path, max 20 chars */
fprintf(p_log,"%20.20s|",name);
fprintf(p_log,"%3d |",input->no_frames);
fprintf(p_log," %2d |",input->qp0);
fprintf(p_log," %2d |",input->qpN);
fprintf(p_log,"%dx%d|",input->img_width,input->img_height);
if (input->hadamard==1)
fprintf(p_log," ON |");
else
fprintf(p_log," OFF |");
fprintf(p_log," %2d |",input->search_range );
fprintf(p_log," %2d |",input->no_multpred);
fprintf(p_log," %2d |",img->framerate/(input->jumpd+1));
if (input->intra_upd==1)
fprintf(p_log," ON |");
else
fprintf(p_log," OFF |");
fprintf(p_log,"%5.3f|",snr->snr_y1);
fprintf(p_log,"%5.3f|",snr->snr_u1);
fprintf(p_log,"%5.3f|",snr->snr_v1);
fprintf(p_log,"%5.3f|",snr->snr_ya);
fprintf(p_log,"%5.3f|",snr->snr_ua);
fprintf(p_log,"%5.3f|",snr->snr_va);
if(input->successive_Bframe != 0)
{
fprintf(p_log,"%7.0f|",stat->bitrate_P);
fprintf(p_log,"%7.0f|\n",stat->bitrate_B);
}
else
{
fprintf(p_log,"%7.0f|",stat->bitrate);
fprintf(p_log,"%7.0f|\n",0.0);
}
fclose(p_log);
p_log=fopen("data.txt","a");
if(input->successive_Bframe != 0) // B picture used
{
fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d %5d %.3f\n",
input->no_frames, input->qp0, input->qpN,
snr->snr_y1,
snr->snr_u1,
snr->snr_v1,
stat->bit_ctr_0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
(stat->bit_ctr_0+stat->bit_ctr)/input->no_frames,
stat->bit_ctr_B/Bframe_ctr,
(double)0.001*tot_time/(input->no_frames+Bframe_ctr));
}
else
{
fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d %5d %.3f\n",
input->no_frames, input->qp0, input->qpN,
snr->snr_y1,
snr->snr_u1,
snr->snr_v1,
stat->bit_ctr_0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
(stat->bit_ctr_0+stat->bit_ctr)/input->no_frames,
0,
(double)0.001*tot_time/input->no_frames);
}
fclose(p_log);
/* B pictures */
free(stat->mode_use_Bframe);
free(stat->bit_use_mode_Bframe);
// getchar();
}
/************************************************************************
*
* Name : init()
*
* Description: Some matrices are initilized here.
*
* Input : none
*
* Output : none
*
************************************************************************/
void init()
{
int k, i, ii, ind, j, i2;
InitMotionVectorSearchModule();
/* img->lpfilter is the table used for loop and post filter. */
for (k=0; k < 6; k++)
{
for (i=1; i <= 100; i++)
{
ii=min(k,i);
img->lpfilter[k][i+300]= ii;
img->lpfilter[k][300-i]=-ii;
}
}
/* img->mv_bituse[] is the number of bits used for motion vectors.
It is used to add a portion to the SAD depending on bit usage in the motion search
*/
img->mv_bituse[0]=1;
ind=0;
for (i=0; i < 9; i++)
{
ii= 2*i + 3;
for (j=1; j <= (int)pow(2,i); j++)
{
ind++;
img->mv_bituse[ind]=ii;
}
}
/* quad(0:255) SNR quad array */
for (i=0; i < 256; ++i) /* fix from TML1 / TML2 sw, truncation removed */
{
i2=i*i;
img->quad[i]=i2;
}
/* B pictures : img->blk_bitsue[] is used when getting bidirection SAD */
for (i=0; i < 7; i++)
{
if(i==0) img->blk_bituse[i]=1;
else if(i==1 || i==2) img->blk_bituse[i]=3;
else img->blk_bituse[i]=5;
}
}
/************************************************************************
*
* Name : information_init()
*
* Description: Prints the header of the protocol
*
* Input : struct inp_par *inp, char *config_filename
*
* Output : none
*
************************************************************************/
void information_init(char *config_filename)
{
printf("--------------------------------------------------------------------------\n");
printf(" Input YUV file : %s \n",input->infile);
printf(" Output H.26L bitstream : %s \n",input->outfile);
if (p_dec != NULL)
printf(" Output YUV file(debug) : test.dec \n");
printf(" Output log file : log.dat \n");
printf(" Output statistics file : stat.dat \n");
printf("--------------------------------------------------------------------------\n");
printf(" Frame Bit/pic QP SnrY SnrU SnrV Time(ms)\n");
}
/************************************************************************
*
* Name : int get_mem4global_buffers(struct inp_par *inp, struct img_par *img)
*
* Description: Dynamic memory allocation of frame size related global buffers
* buffers are defined in global.h, allocated memory must be freed in
* void free_mem4global_buffers()
*
* Input : Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* Output : Number of allocated bytes
*
************************************************************************/
int get_mem4global_buffers()
{
int j,memory_size=0;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no;
if ((last_P_no = (int*)malloc(img->buf_cycle*sizeof(int))) == NULL) no_mem_exit(1);
#endif
/* allocate memory for encoding frame buffers: imgY, imgUV*/
/* byte imgY[288][352]; */
/* byte imgUV[2][144][176]; */
memory_size += get_mem2D(&imgY, img->height, img->width);
memory_size += get_mem3D(&imgUV, 2, img->height_cr, img->width_cr);
/* allocate memory for reference frame buffers: imgY_org, imgUV_org*/
/* byte imgY_org[288][352]; */
/* byte imgUV_org[2][144][176]; */
memory_size += get_mem2D(&imgY_org, img->height, img->width);
memory_size += get_mem3D(&imgUV_org, 2, img->height_cr, img->width_cr);
/* allocate memory for post filter frame buffers: imgY_pf, imgUV_pf*/
/* byte imgY_pf[288][352]; */
/* byte imgUV_pf[2][144][176]; */
memory_size += get_mem2D(&imgY_pf, img->height, img->width);
memory_size += get_mem3D(&imgUV_pf, 2, img->height_cr, img->width_cr);
/* allocate memory for B frame coding: nextP_imgY, nextP_imgUV*/
/* byte nextP_imgY[288][352]; */
/* byte nextP_imgUV[2][144][176]; */
memory_size += get_mem2D(&nextP_imgY, img->height, img->width);
memory_size += get_mem3D(&nextP_imgUV, 2, img->height_cr, img->width_cr);
/* allocate memory for multiple ref. frame buffers: mref, mcref*/
/*byte mref[MAX_MULT_PRED][1152][1408]; */ /* 1/4 pix luma */
/*byte mcef[MAX_MULT_PRED][2][352][288]; */ /* pix chroma */
/* rows and cols for croma component mcef[ref][croma][4x][4y] are switched */
/* compared to luma mref[ref][4y][4x] for whatever reason */
/* number of reference frames increased by one for next P-frame*/
memory_size += get_mem3D(&mref, img->buf_cycle+1, img->height*4, img->width*4);
if((mcef = (byte****)calloc(img->buf_cycle+1,sizeof(byte***))) == NULL) no_mem_exit(1);
for(j=0;j<img->buf_cycle+1;j++)
{
memory_size += get_mem3D(&(mcef[j]), 2, img->width_cr*2, img->height_cr*2);
}
InitRefbuf (Refbuf11, Refbuf11_P);
/* allocate memory for B-frame coding (last upsampled P-frame): mref_P, mcref_P*/
/* is currently also used in oneforthpix_1() and _2() for coding without B-frames*/
/*byte mref[1152][1408]; */ /* 1/4 pix luma */
/*byte mcef[2][352][288]; */ /* pix chroma */
memory_size += get_mem2D(&mref_P, img->height*4, img->width*4);
memory_size += get_mem3D(&mcef_P, 2, img->width_cr*2, img->height_cr*2);
if(input->successive_Bframe!=0)
{
/* allocate memory for temp B-frame motion vector buffer: tmp_fwMV, tmp_bwMV, dfMV, dbMV*/
/* int ...MV[2][72][92]; ([2][72][88] should be enough) */
memory_size += get_mem3Dint(&tmp_fwMV, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
memory_size += get_mem3Dint(&tmp_bwMV, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
memory_size += get_mem3Dint(&dfMV, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
memory_size += get_mem3Dint(&dbMV, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
/* allocate memory for temp B-frame motion vector buffer: fw_refFrArr, bw_refFrArr*/
/* int ...refFrArr[72][88]; */
memory_size += get_mem2Dint(&fw_refFrArr, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&bw_refFrArr, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
}
/* allocate memory for temp P and B-frame motion vector buffer: tmp_mv, temp_mv_block*/
/* int tmp_mv[2][72][92]; ([2][72][88] should be enough) */
memory_size += get_mem3Dint(&tmp_mv, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
/* allocate memory for temp quarter pel luma frame buffer: img4Y_tmp*/
/* int img4Y_tmp[576][704]; (previously int imgY_tmp in global.h) */
memory_size += get_mem2Dint(&img4Y_tmp, img->height*2, img->width*2);
/* allocate memory for temp 1/8-pel luma frame buffer: img8Y_tmp*/
memory_size += get_mem2D(&img8Y_tmp, 4*img->width, img->height);
/* allocate memory for tmp loop filter frame buffers: imgY_tmp, imgUV_tmp*/
/* byte imgY_tmp[288][352]; */
memory_size += get_mem2D(&imgY_tmp, img->height, img->width);
memory_size += get_mem3D(&imgUV_tmp, 2, img->height_cr, img->width_cr);
/* allocate memory for reference frames of each block: refFrArr*/
/* int refFrArr[72][88]; */
memory_size += get_mem2Dint(&refFrArr, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
/* allocate memory for filter strength for 4x4 lums and croma blocks:loopb, loopc*/
/*byte loopb[91][75]; i.e.[x][y]*/
/*byte loopc[47][39]; */
memory_size += get_mem2D(&loopb, img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
memory_size += get_mem2D(&loopc, img->width_cr/BLOCK_SIZE+3, img->height_cr/BLOCK_SIZE+3);
return (memory_size);
}
/************************************************************************
*
* Name : void free_mem4global_buffers(struct inp_par *inp, struct img_par *img)
*
* Description: Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int get_mem4global_buffers()
*
* Input : Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* Output : none
*
************************************************************************/
void free_mem4global_buffers()
{
int i,j;
for(i=0;i<img->height;i++)
{
free(imgY[i]);
}
free(imgY);
for(i=0;i<img->height_cr;i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -