📄 lencod.c
字号:
fprintf(p_log," ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_log,"| ver | Date | Time | Sequence | #Img |P/MbInt| QPI| QPP| QPB| Format |Iperiod| #B | Hdmd | S.R |#Ref | Freq |Coding|RD-opt|Intra upd|8x8Tr|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|#Bitr P|#Bitr B|#Bitr IPB| Total Time | Me Time |\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);
}
}
fprintf(p_log,"|%s/%-4s", VERSION, EXT_VERSION);
#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," %d/%d |",input->PicInterlace, input->MbInterlace);
fprintf(p_log," %-3d|",input->qp0);
fprintf(p_log," %-3d|",input->qpN);
fprintf(p_log," %-3d|",input->qpB);
fprintf(p_log,"%4dx%-4d|",input->img_width,input->img_height);
fprintf(p_log," %3d |",input->intra_period);
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_ref_frames);
// fprintf(p_log," %3d |",img->framerate/(input->jumpd+1));
fprintf(p_log," %3.2f|",(img->framerate *(float) (input->successive_Bframe + 1)) / (float)(input->jumpd+1));
if (input->symbol_mode == UVLC)
fprintf(p_log," CAVLC|");
else
fprintf(p_log," CABAC|");
fprintf(p_log," %d |",input->rdopt);
if (input->intra_upd==1)
fprintf(p_log," ON |");
else
fprintf(p_log," OFF |");
fprintf(p_log," %d |",input->AllowTransform8x8);
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|",stats->bitrate_P);
fprintf(p_log,"%7.0f|",stats->bitrate_B);
fprintf(p_log,"%9.0f|",stats->bitrate);
}
else
{
fprintf(p_log,"%7.0f|",stats->bitrate);
fprintf(p_log,"%7.0f|",0.0);
fprintf(p_log,"%9.0f|",0.0);
}
fprintf(p_log," %12d |", tot_time);
fprintf(p_log," %12d |\n", me_tot_time);
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,
stats->bit_ctr_0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
(stats->bit_ctr_0+stats->bit_ctr)/(input->no_frames+Bframe_ctr),
stats->bit_ctr_B/Bframe_ctr,
(double)0.001*tot_time/(input->no_frames+Bframe_ctr));
}
else
{
if (input->no_frames!=0)
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,
stats->bit_ctr_0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
(stats->bit_ctr_0+stats->bit_ctr)/input->no_frames,
0,
(double)0.001*tot_time/input->no_frames);
}
fclose(p_log);
if ((p_log=fopen("stat_frame.dat","a"))==NULL) // append new statistic at the end
{
snprintf(errortext, ET_SIZE, "Error open file %s \n","stat_frame.dat.dat");
// error(errortext, 500);
}
else
{
fprintf(p_log," --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fclose(p_log);
}
}
/*!
************************************************************************
* \brief
* Prints the header of the protocol.
* \par Input:
* struct inp_par *inp
* \par Output:
* none
************************************************************************
*/
void information_init()
{
char yuv_types[4][10]= {"YUV 4:0:0","YUV 4:2:0","YUV 4:2:2","YUV 4:4:4"};
printf("------------------------------- JM %s %s --------------------------------\n",VERSION, EXT_VERSION);
printf(" Input YUV file : %s \n",input->infile);
printf(" Output H.264 bitstream : %s \n",input->outfile);
if (p_dec != -1)
printf(" Output YUV file : %s \n",input->ReconFile);
printf(" YUV Format : %s \n", &yuv_types[img->yuv_format][0]);//img->yuv_format==YUV422?"YUV 4:2:2":(img->yuv_format==YUV444)?"YUV 4:4:4":"YUV 4:2:0");
printf(" Frames to be encoded I-P/B : %d/%d\n", input->no_frames, (input->successive_Bframe*(input->no_frames-1)));
printf(" PicInterlace / MbInterlace : %d/%d\n", input->PicInterlace, input->MbInterlace);
printf(" Transform8x8Mode : %d\n", input->AllowTransform8x8);
printf("-------------------------------------------------------------------------------\n");
printf(" Frame Bit/pic WP QP SnrY SnrU SnrV Time(ms) MET(ms) Frm/Fld I D\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;
int height_field_cr = img->height_cr/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
memory_size += get_mem2Dpel(&imgY_org_frm, img->height, img->width);
if (img->yuv_format != YUV400)
memory_size += get_mem3Dpel(&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
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 = (imgpel****) calloc(input->NoOfDecoders,sizeof(imgpel***))) == NULL)
no_mem_exit("init_global_buffers: decref");
for (j=0 ; j<input->NoOfDecoders; j++)
{
memory_size += get_mem3Dpel(&decs->decref[j], img->max_num_references+1, img->height, img->width);
}
memory_size += get_mem2Dpel(&decs->RefBlock, BLOCK_SIZE,BLOCK_SIZE);
memory_size += get_mem3Dpel(&decs->decY, input->NoOfDecoders, img->height, img->width);
memory_size += get_mem3Dpel(&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_mem2Dpel(&imgY_com, img->height, img->width);
// allocate memory for reference frame buffers: imgY_org, imgUV_org
memory_size += get_mem2Dpel(&imgY_org_top, height_field, img->width);
memory_size += get_mem2Dpel(&imgY_org_bot, height_field, img->width);
if (img->yuv_format != YUV400)
{
memory_size += get_mem3Dpel(&imgUV_com, 2, img->height_cr, img->width_cr);
memory_size += get_mem3Dpel(&imgUV_org_bot, 2, height_field_cr, img->width_cr);
memory_size += get_mem3Dpel(&imgUV_org_top, 2, height_field_cr, 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_mem2Dpel(imgY_org_frm); // free ref frame buffers
if (img->yuv_format != YUV400)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -