📄 lencod.c
字号:
for (j=0; j < 2; j++)
{
fprintf(p_stat," %10.2f |", (float)stat->tmp_bit_use_cbp[j]/bit_use[j][0]);
}
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," %10.2f |", (float)stat->tmp_bit_use_cbp[2]/Bframe_ctr);
else
fprintf(p_stat," %10.2f |", 0.);
fprintf(p_stat,"\n");
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," Coeffs. Y | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_coeffY[0]/bit_use[0][0], (float)stat->bit_use_coeffY[1]/bit_use[1][0], (float)stat->bit_use_coeffY[2]/Bframe_ctr);
else
fprintf(p_stat," Coeffs. Y | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_coeffY[0]/bit_use[0][0], (float)stat->bit_use_coeffY[1]/(float)bit_use[1][0], 0.);
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," Coeffs. C | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_coeffC[0]/bit_use[0][0], (float)stat->bit_use_coeffC[1]/bit_use[1][0], (float)stat->bit_use_coeffC[2]/Bframe_ctr);
else
fprintf(p_stat," Coeffs. C | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_coeffC[0]/bit_use[0][0], (float)stat->bit_use_coeffC[1]/bit_use[1][0], 0.);
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," Delta quant | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_delta_quant[0]/bit_use[0][0], (float)stat->bit_use_delta_quant[1]/bit_use[1][0], (float)stat->bit_use_delta_quant[2]/Bframe_ctr);
else
fprintf(p_stat," Delta quant | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_delta_quant[0]/bit_use[0][0], (float)stat->bit_use_delta_quant[1]/bit_use[1][0], 0.);
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," Stuffing Bits | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_stuffingBits[0]/bit_use[0][0], (float)stat->bit_use_stuffingBits[1]/bit_use[1][0], (float)stat->bit_use_stuffingBits[2]/Bframe_ctr);
else
fprintf(p_stat," Stuffing Bits | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_stuffingBits[0]/bit_use[0][0], (float)stat->bit_use_stuffingBits[1]/bit_use[1][0], 0.);
fprintf(p_stat," --------------------|----------------|----------------|----------------|\n");
fprintf(p_stat," average bits/frame |");
for (i=0; i < 2; i++)
{
fprintf(p_stat," %10.2f |", (float) bit_use[i][1]/(float) bit_use[i][0] );
}
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," %10.2f |", (float) bit_use_Bframe/ (float) Bframe_ctr );
else
fprintf(p_stat," %10.2f |", 0.);
fprintf(p_stat,"\n");
fprintf(p_stat," --------------------|----------------|----------------|----------------|\n");
fclose(p_stat);
// write to log file
if ((p_log=fopen("log.dat","r"))==0) // check if file exist
{
if ((p_log=fopen("log.dat","a"))==NULL) // append new statistic at the end
{
snprintf(errortext, ET_SIZE, "Error open file %s \n","log.dat");
error(errortext, 500);
}
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
{
fclose (p_log);
if ((p_log=fopen("log.dat","a"))==NULL) // File exist,just open for appending
{
snprintf(errortext, ET_SIZE, "Error open file %s \n","log.dat");
error(errortext, 500);
}
}
#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|",img->width,img->height); //add by wuzhongmou 0610
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);
}
/*
*************************************************************************
* Function:Prints the header of the protocol.
* Input:struct inp_par *inp
* Output:
* Return:
* Attention:
*************************************************************************
*/
void information_init()
{
printf("-----------------------------------------------------------------------------\n");
printf(" Input YUV file : %s \n",input->infile);
printf(" Output AVS bitstream : %s \n",input->outfile);
if (p_dec != NULL)
printf(" Output YUV file : %s \n",input->ReconFile);
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) FRM/FLD IntraMBs\n");
}
/*
*************************************************************************
* Function:Dynamic memory allocation of frame size related global buffers
buffers are defined in global.h, allocated memory must be freed in
void free_global_buffers()
* Input: Input Parameters struct inp_par *inp, \n
Image Parameters struct img_par *img
* Output:
* Return: Number of allocated bytes
* Attention:
*************************************************************************
*/
int init_global_buffers()
{
int memory_size=0;
int height_field = img->height/2;
int refnum;
int i;
imgY_org_buffer = (byte*)malloc(input->img_height*input->img_width*3/2); //add by wuzhongmou 0610
memory_size += input->img_height*input->img_width*3/2; //add by wuzhongmou 0610
// 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_frm, img->height, img->width);
memory_size += get_mem3D(&imgUV_org_frm, 2, img->height_cr, img->width_cr);
// 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_frm, 2, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
// allocate memory for reference frames of each block: refFrArr
// int refFrArr[72][88];
memory_size += get_mem2Dint(&refFrArr_frm, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
if(input->successive_Bframe!=0)
{
// allocate memory for temp B-frame motion vector buffer: fw_refFrArr, bw_refFrArr
// int ...refFrArr[72][88];
memory_size += get_mem2Dint(&fw_refFrArr_frm, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&bw_refFrArr_frm, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
}
// 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);
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 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_PAD_SIZE, (img->width+2*IMG_PAD_SIZE)*4);
memory_size += get_mem2Dint(&img4Y_tmp, (img->height+2*IMG_PAD_SIZE)*4, (img->width+2*IMG_PAD_SIZE)*4);
if (input->InterlaceCodingOption != FRAME_CODING)
{
// allocate memory for encoding frame buffers: imgY, imgUV
// byte imgY[288][352];
// byte imgUV[2][144][176];
memory_size += get_mem2D(&imgY_com, img->height, img->width);
memory_size += get_mem3D(&imgUV_com, 2, img->height/2, img->width_cr);
memory_size += get_mem2D(&imgY_org_top, img->height/2, img->width);
memory_size += get_mem3D(&imgUV_org_top, 2, img->height_cr/2, img->width_cr);
memory_size += get_mem2D(&imgY_org_bot, img->height/2, img->width);
memory_size += get_mem3D(&imgUV_org_bot, 2, img->height_cr/2, img->width_cr);
// allocate memory for encoding frame buffers: imgY, imgUV
// byte imgY[288][352];
// byte imgUV[2][144][176];
memory_size += get_mem2D(&imgY_top, height_field, img->width);
memory_size += get_mem3D(&imgUV_top, 2, height_field/2, img->width_cr);
memory_size += get_mem2D(&imgY_bot, height_field, img->width);
memory_size += get_mem3D(&imgUV_bot, 2, height_field/2, img->width_cr);
if(input->successive_Bframe!=0)
{
// allocate memory for temp B-frame motion vector buffer: fw_refFrArr, bw_refFrArr
// int ...refFrArr[72][88];
memory_size += get_mem2Dint(&fw_refFrArr_top, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&bw_refFrArr_top, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&fw_refFrArr_bot, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&bw_refFrArr_bot, height_field/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_top, 2, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
memory_size += get_mem3Dint(&tmp_mv_bot, 2, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE+4);
// allocate memory for reference frames of each block: refFrArr
// int refFrArr[72][88];
memory_size += get_mem2Dint(&refFrArr_top, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&refFrArr_bot, height_field/BLOCK_SIZE, img->width/BLOCK_SIZE);
}
//FAST MOTION ESTIMATION. ZHIBO CHEN 2003.3
#ifdef FastME
memory_size += get_mem_FME();
#endif
for(refnum=0; refnum<3; refnum++)
for (i=0; i<3; i++)
{
if (i==0)
{
get_mem2D(&reference_frame[refnum][i],img->height,img->width);
}else
{
get_mem2D(&reference_frame[refnum][i],img->height_cr,img->width_cr);
}
}
//forward reference frame buffer
ref_frm[0] = reference_frame[0]; //reference_frame[ref_index][yuv][height][width],ref_frm[ref_index][yuv][height][width]
ref_frm[1] = reference_frame[1];
current_frame = reference_frame[2];
//allocate field buffer
if(input->InterlaceCodingOption != FRAME_CODING)
{
for(refnum=0; refnum<6; refnum++)
for (i=0; i<3; i++)
{
if (i==0)
{
get_mem2D(&reference_field[refnum][i],img->height/2,img->width);
}else
{
get_mem2D(&reference_field[refnum][i],img->height_cr/2,img->width_cr);
}
}
//forward reference frame buffer
for (i=0; i<4; i++)
ref_fld[i] = reference_field[i];
current_field = reference_field[4];
ref_fld[4] = reference_field[5];
}
// !!
allalpha_lum = (int*)malloc(((img->height*img->width)/256)*sizeof(int));
allbelta_lum = (int*)malloc(((img->height*img->width)/256)*sizeof(int));
return (memory_size);
}
/*
*************************************************************************
* Function: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, \n
Image Parameters struct img_par *img
* Output:
* Return:
* Attention:
*************************************************************************
*/
void free_global_buffers()
{
int i,j;
free(imgY_org_buffer);
free_mem2D(imgY_org_frm);
free_mem3D(imgUV_org_frm,2);
free_mem3Dint(tmp_mv_frm,2);
free_mem2Dint(refFrArr_frm);
// number of reference frames increased by one for next P-frame
for(i=0;i<2;i++)
free(mref_frm[i]);
for(i=0;i<3;i++)
{
free(reference_frame[0][i]);
free(reference_frame[1][i]);
free(reference_frame[2][i]);
}
if (input->InterlaceCodingOption != FRAME_CODING)
{
for(j=0;j<6;j++)
for(i=0;i<3;i++)
{
free(reference_field[j][i]);
}
}
free_mem2D(nextP_imgY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -