📄 lencod.c
字号:
(float)stat->bit_use_stuffingBits[I_SLICE]/bit_use[I_SLICE][0], (float)stat->bit_use_stuffingBits[P_SLICE]/bit_use[P_SLICE][0], (float)stat->bit_use_stuffingBits[B_SLICE]/Bframe_ctr);
else
fprintf(p_stat," Stuffing Bits | %10.2f | %10.2f | %10.2f |\n",
(float)stat->bit_use_stuffingBits[I_SLICE]/bit_use[I_SLICE][0], (float)stat->bit_use_stuffingBits[P_SLICE]/bit_use[P_SLICE][0], 0.);
fprintf(p_stat," ---------------------|----------------|----------------|----------------|\n");
fprintf(p_stat," average bits/frame |");
fprintf(p_stat," %10.2f |", (float) bit_use[I_SLICE][1]/(float) bit_use[I_SLICE][0] );
fprintf(p_stat," %10.2f |", (float) bit_use[P_SLICE][1]/(float) bit_use[P_SLICE][0] );
if(input->successive_Bframe!=0 && Bframe_ctr!=0)
fprintf(p_stat," %10.2f |", (float) bit_use[B_SLICE][1]/ (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 | QPI| QPP| QPB| Format | #B | Hdmd | S.R |#Ref | Freq |Intra upd|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|#Bitr P|#Bitr B| Total Time | Me Time |\n");
fprintf(p_log," ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ \n");
/*
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,((int)strlen(input->infile))-20)]; // write last part of path, max 20 chars
fprintf(p_log,"%20.20s|",name);
fprintf(p_log,"%5d |",input->no_frames);
fprintf(p_log," %2d |",input->qp0);
fprintf(p_log," %2d |",input->qpN);
fprintf(p_log," %2d |",input->qpB);
fprintf(p_log,"%4dx%-4d|",input->img_width,input->img_height);
fprintf(p_log,"%3d |",input->successive_Bframe);
if (input->hadamard==1)
fprintf(p_log," ON |");
else
fprintf(p_log," OFF |");
fprintf(p_log," %3d |",input->search_range );
fprintf(p_log," %2d |",input->num_reference_frames);
// fprintf(p_log," %3d |",img->framerate/(input->jumpd+1));
fprintf(p_log," %3d |",(img->framerate *(input->successive_Bframe + 1)) / (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|",stat->bitrate_B);
}
else
{
fprintf(p_log,"%7.0f|",stat->bitrate);
fprintf(p_log,"%7.0f|",0.0);
}
fprintf(p_log," %12d |", tot_time);
fprintf(p_log," %12d |\n", me_tot_time);
/*
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 && Bframe_ctr != 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+Bframe_ctr),
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);
}
/*!
************************************************************************
* \brief
* Prints the header of the protocol.
* \par Input:
* struct inp_par *inp
* \par Output:
* none
************************************************************************
*/
void information_init()
{
printf("-------------------------------------------------------------------------------\n");
printf(" Input YUV file : %s \n",input->infile);
printf(" Output H.264 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 WP QP SnrY SnrU SnrV Time(ms) MET(ms) Frm/Fld I D\n");
// printf(" Frame Bit/pic QP SnrY SnrU SnrV Time(ms) Frm/Fld IntraMBs\n");
printf("-------------------------------------------------------------------------------\n");
}
/*!
************************************************************************
* \brief
* 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()
* \par Input:
* Input Parameters struct inp_par *inp, \n
* Image Parameters struct img_par *img
* \return Number of allocated bytes
************************************************************************
*/
int init_global_buffers()
{
int j,memory_size=0;
int height_field = img->height/2;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no_frm;
extern int *last_P_no_fld;
if ((last_P_no_frm = (int*)malloc(2*img->max_num_references*sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: last_P_no");
if(!active_sps->frame_mbs_only_flag)
if ((last_P_no_fld = (int*)malloc(4*img->max_num_references*sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: last_P_no");
#endif
// allocate memory for encoding frame buffers: imgY, imgUV
// 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);
if (input->WeightedPrediction || input->WeightedBiprediction)
{
// Currently only use up to 20 references. Need to use different indicator such as maximum num of references in list
memory_size += get_mem3Dint(&wp_weight,6,MAX_REFERENCE_PICTURES,3);
memory_size += get_mem3Dint(&wp_offset,6,MAX_REFERENCE_PICTURES,3);
memory_size += get_mem4Dint(&wbp_weight, 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3);
}
// allocate memory for reference frames of each block: refFrArr
// int refFrArr[72][88];
if(input->successive_Bframe!=0 || input->StoredBPictures > 0)
{
memory_size += get_mem3Dint(&direct_ref_idx, 2, img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
memory_size += get_mem2Dint(&direct_pdir, img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
}
// 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);
if (input->rdopt==2)
{
memory_size += get_mem2Dint(&decs->resY, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
if ((decs->decref = (byte****) calloc(input->NoOfDecoders,sizeof(byte***))) == NULL)
no_mem_exit("init_global_buffers: decref");
for (j=0 ; j<input->NoOfDecoders; j++)
{
memory_size += get_mem3D(&decs->decref[j], img->max_num_references+1, img->height, img->width);
}
memory_size += get_mem2D(&decs->RefBlock, BLOCK_SIZE,BLOCK_SIZE);
memory_size += get_mem3D(&decs->decY, input->NoOfDecoders, img->height, img->width);
memory_size += get_mem3D(&decs->decY_best, input->NoOfDecoders, img->height, img->width);
memory_size += get_mem2D(&decs->status_map, img->height/MB_BLOCK_SIZE,img->width/MB_BLOCK_SIZE);
memory_size += get_mem2D(&decs->dec_mb_mode, img->width/MB_BLOCK_SIZE,img->height/MB_BLOCK_SIZE);
}
if (input->RestrictRef)
{
memory_size += get_mem2D(&pixel_map, img->height,img->width);
memory_size += get_mem2D(&refresh_map, img->height/8,img->width/8);
}
if(!active_sps->frame_mbs_only_flag)
{
// allocate memory for encoding frame buffers: imgY, imgUV
memory_size += get_mem2D(&imgY_com, img->height, img->width);
memory_size += get_mem3D(&imgUV_com, 2, img->height/2, img->width_cr);
// allocate memory for reference frame buffers: imgY_org, imgUV_org
memory_size += get_mem2D(&imgY_org_top, height_field, img->width);
memory_size += get_mem3D(&imgUV_org_top, 2, height_field/2, img->width_cr);
memory_size += get_mem2D(&imgY_org_bot, height_field, img->width);
memory_size += get_mem3D(&imgUV_org_bot, 2, height_field/2, img->width_cr);
}
if(input->FMEnable)
memory_size += get_mem_FME();
return (memory_size);
}
/*!
************************************************************************
* \brief
* Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int get_mem4global_buffers()
* \par Input:
* Input Parameters struct inp_par *inp, \n
* Image Parameters struct img_par *img
* \par Output:
* none
************************************************************************
*/
void free_global_buffers()
{
int i,j;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no_frm;
extern int *last_P_no_fld;
free (last_P_no_frm);
free (last_P_no_fld);
#endif
free_mem2D(imgY_org_frm); // free ref frame buffers
free_mem3D(imgUV_org_frm,2);
// free multiple ref frame buffers
// number of reference frames increased by one for next P-frame
if (input->WeightedPrediction || input->WeightedBiprediction)
{
free_mem3Dint(wp_weight,6);
free_mem3Dint(wp_offset,6);
free_mem4Dint(wbp_weight,6,MAX_REFERENCE_PICTURES);
}
if(input->successive_Bframe!=0 || input->StoredBPictures > 0)
{
free_mem3Dint(direct_ref_idx,2);
free_mem2Dint(direct_pdir);
} // end if B frame
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -