📄 lencod.c
字号:
* Frees a picture
* \param
* pic: POinter to a Picture to be freed
************************************************************************
*/
void free_picture(Picture *pic)
{
if (pic != NULL)
{
free_slice_list(pic);
free (pic);
}
}
/*!
************************************************************************
* \brief
* Reports frame statistical data to a stats file
************************************************************************
*/
void report_frame_statistic()
{
FILE *p_stat_frm = NULL;
static int64 last_mode_use[NUM_PIC_TYPE][MAXMODE];
static int last_b8_mode_0[NUM_PIC_TYPE][2];
static int last_mode_chroma_use[4];
static int64 last_bit_ctr_n = 0;
int i;
char name[30];
int bitcounter;
#ifndef WIN32
time_t now;
struct tm *l_time;
char string[1000];
#else
char timebuf[128];
#endif
// write to log file
if ((p_stat_frm = fopen("stat_frame.dat", "r")) == 0) // check if file exists
{
if ((p_stat_frm = 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 // Create header for new log file
{
fprintf(p_stat_frm, " --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_stat_frm, "| Encoder statistics. This file is generated during first encoding session, new sessions will be appended |\n");
fprintf(p_stat_frm, " --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
}
}
else
{
fclose (p_stat_frm);
if ((p_stat_frm = fopen("stat_frame.dat", "a")) == NULL) // File exists, just open for appending
{
snprintf(errortext, ET_SIZE, "Error open file %s \n", "stat_frame.dat.dat");
error(errortext, 500);
}
}
if (frame_statistic_start)
{
fprintf(p_stat_frm, "| ver | Date | Time | Sequence |Frm | QP |P/MbInt| Bits | SNRY | SNRU | SNRV | I4 | I8 | I16 | IC0 | IC1 | IC2 | IC3 | PI4 | PI8 | PI16 | P0 | P1 | P2 | P3 | P1*8*| P1*4*| P2*8*| P2*4*| P3*8*| P3*4*| P8 | P8:4 | P4*8*| P4*4*| P8:5 | P8:6 | P8:7 | BI4 | BI8 | BI16 | B0 | B1 | B2 | B3 | B0*8*| B0*4*| B1*8*| B1*4*| B2*8*| B2*4*| B3*8*| B3*4*| B8 | B8:0 |B80*8*|B80*4*| B8:4 | B4*8*| B4*4*| B8:5 | B8:6 | B8:7 |\n");
fprintf(p_stat_frm, " ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ \n");
}
//report
fprintf(p_stat_frm, "|%4s/%s", VERSION, EXT_VERSION);
#ifdef WIN32
_strdate( timebuf );
fprintf(p_stat_frm, "| %1.5s |", timebuf);
_strtime( timebuf);
fprintf(p_stat_frm, " % 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_stat_frm, "| %1.5s |", string );
strftime (string, sizeof string, "%H:%M:%S", l_time);
fprintf(p_stat_frm, " %1.5s |", string);
#endif
for (i=0;i<30;i++)
name[i]=input->infile[i + imax(0,(int) (strlen(input->infile)- 30))]; // write last part of path, max 30 chars
fprintf(p_stat_frm, "%30.30s|", name);
fprintf(p_stat_frm, "%3d |", frame_no);
fprintf(p_stat_frm, "%3d |", img->qp);
fprintf(p_stat_frm, " %d/%d |", input->PicInterlace, input->MbInterlace);
if (img->frm_number == 0 && img->frame_num == 0)
{
bitcounter = (int) stats->bit_ctr_I;
}
else
{
bitcounter = (int) (stats->bit_ctr_n - last_bit_ctr_n);
last_bit_ctr_n = stats->bit_ctr_n;
}
//report bitrate
fprintf(p_stat_frm, " %9d|", bitcounter);
//report snr's
fprintf(p_stat_frm, " %2.4f| %2.4f| %2.4f|", snr->snr_y, snr->snr_u, snr->snr_v);
//report modes
//I-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[I_SLICE][I4MB] - last_mode_use[I_SLICE][I4MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[I_SLICE][I8MB] - last_mode_use[I_SLICE][I8MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[I_SLICE][I16MB] - last_mode_use[I_SLICE][I16MB]);
//chroma intra mode
fprintf(p_stat_frm, " %5d|", stats->intra_chroma_mode[0] - last_mode_chroma_use[0]);
fprintf(p_stat_frm, " %5d|", stats->intra_chroma_mode[1] - last_mode_chroma_use[1]);
fprintf(p_stat_frm, " %5d|", stats->intra_chroma_mode[2] - last_mode_chroma_use[2]);
fprintf(p_stat_frm, " %5d|", stats->intra_chroma_mode[3] - last_mode_chroma_use[3]);
//P-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][I4MB] - last_mode_use[P_SLICE][I4MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][I8MB] - last_mode_use[P_SLICE][I8MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][I16MB] - last_mode_use[P_SLICE][I16MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][0 ] - last_mode_use[P_SLICE][0 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][1 ] - last_mode_use[P_SLICE][1 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][2 ] - last_mode_use[P_SLICE][2 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][3 ] - last_mode_use[P_SLICE][3 ]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][0][1]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][0][1]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][0][2]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][0][2]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][0][3]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][0][3]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][P8x8] - last_mode_use[P_SLICE][P8x8]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][4 ] - last_mode_use[P_SLICE][4 ]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][0][4]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][0][4]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][5 ] - last_mode_use[P_SLICE][5 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][6 ] - last_mode_use[P_SLICE][6 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[P_SLICE][7 ] - last_mode_use[P_SLICE][7 ]);
//B-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][I4MB] - last_mode_use[B_SLICE][I4MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][I8MB] - last_mode_use[B_SLICE][I8MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][I16MB] - last_mode_use[B_SLICE][I16MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][0 ] - last_mode_use[B_SLICE][0 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][1 ] - last_mode_use[B_SLICE][1 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][2 ] - last_mode_use[B_SLICE][2 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][3 ] - last_mode_use[B_SLICE][3 ]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][1][0]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][1][0]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][1][1]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][1][1]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][1][2]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][1][2]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][1][3]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][1][3]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][P8x8] - last_mode_use[B_SLICE][P8x8]);
fprintf(p_stat_frm, " %d|", (stats->b8_mode_0_use [B_SLICE][0]+stats->b8_mode_0_use [B_SLICE][1]) - (last_b8_mode_0[B_SLICE][0]+last_b8_mode_0[B_SLICE][1]));
fprintf(p_stat_frm, " %5d|", stats->b8_mode_0_use [B_SLICE][1] - last_b8_mode_0[B_SLICE][1]);
fprintf(p_stat_frm, " %5d|", stats->b8_mode_0_use [B_SLICE][0] - last_b8_mode_0[B_SLICE][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][4 ] - last_mode_use[B_SLICE][4 ]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[1][1][4]);
fprintf(p_stat_frm, " %5d|", stats->mode_use_transform[0][1][4]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][5 ] - last_mode_use[B_SLICE][5 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][6 ] - last_mode_use[B_SLICE][6 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use[B_SLICE][7 ] - last_mode_use[B_SLICE][7 ]);
fprintf(p_stat_frm, "\n");
//save the last results
memcpy(last_mode_use[I_SLICE], stats->mode_use[I_SLICE], MAXMODE * sizeof(int64));
memcpy(last_mode_use[P_SLICE], stats->mode_use[P_SLICE], MAXMODE * sizeof(int64));
memcpy(last_mode_use[B_SLICE], stats->mode_use[B_SLICE], MAXMODE * sizeof(int64));
memset(stats->mode_use_transform[1], 0, 2 * MAXMODE * sizeof(int));
memset(stats->mode_use_transform[0], 0, 2 * MAXMODE * sizeof(int));
memcpy(last_b8_mode_0[B_SLICE], stats->b8_mode_0_use[B_SLICE], 2 * sizeof(int));
memcpy(last_mode_chroma_use, stats->intra_chroma_mode, 4 * sizeof(int));
frame_statistic_start = 0;
fclose(p_stat_frm);
}
/*!
************************************************************************
* \brief
* Reports the gathered information to appropriate outputs
* \par Input:
* struct inp_par *inp, \n
* struct img_par *img, \n
* struct stat_par *stats, \n
* struct stat_par *stats \n
*
* \par Output:
* None
************************************************************************
*/
void report()
{
int64 bit_use[NUM_PIC_TYPE][2] ;
int i,j;
char name[40];
int64 total_bits;
float frame_rate;
double mean_motion_info_bit_use[2] = {0.0};
#ifndef WIN32
time_t now;
struct tm *l_time;
char string[1000];
#else
char timebuf[128];
#endif
bit_use[I_SLICE][0] = frame_ctr[I_SLICE];
bit_use[P_SLICE][0] = imax(frame_ctr[P_SLICE] + frame_ctr[SP_SLICE],1);
bit_use[B_SLICE][0] = frame_ctr[B_SLICE];
// Accumulate bit usage for inter and intra frames
for (j=0; j < NUM_PIC_TYPE; j++)
{
bit_use[j][1] = 0;
}
for (j=0; j < NUM_PIC_TYPE; j++)
{
for(i=0; i < MAXMODE; i++)
bit_use[j][1] += stats->bit_use_mode[j][i];
bit_use[j][1] += stats->bit_use_header[j];
bit_use[j][1] += stats->bit_use_mb_type[j];
bit_use[j][1] += stats->tmp_bit_use_cbp[j];
bit_use[j][1] += stats->bit_use_coeffC[j];
bit_use[j][1] += stats->bit_use_coeff[0][j];
bit_use[j][1] += stats->bit_use_coeff[1][j];
bit_use[j][1] += stats->bit_use_coeff[2][j];
bit_use[j][1] += stats->bit_use_delta_quant[j];
bit_use[j][1] += stats->bit_use_stuffingBits[j];
}
frame_rate = (img->framerate *(float)(stats->successive_Bframe + 1)) / (float) (input->jumpd+1);
//! Currently adding NVB bits on P rate. Maybe additional stats info should be created instead and added in log file
stats->bitrate_I = (stats->bit_ctr_I)*(frame_rate)/(float) (input->no_frames + frame_ctr[B_SLICE]);
stats->bitrate_P = (stats->bit_ctr_P)*(frame_rate)/(float) (input->no_frames + frame_ctr[B_SLICE]);
stats->bitrate_B = (stats->bit_ctr_B)*(frame_rate)/(float) (input->no_frames + frame_ctr[B_SLICE]);
switch (input->Verbose)
{
case 0:
case 1:
default:
fprintf(stdout,"------------------ Average data all frames -----------------------------------\n\n");
break;
case 2:
fprintf(stdout,"------------------------------------ Average data all frames ---------------------------------\n\n");
break;
}
if (input->Verbose != 0)
{
int impix = input->img_height * input->img_width;
int impix_cr = input->img_height_cr * input->img_width_cr;
unsigned int max_pix_value_sqd = img->max_imgpel_value_comp[0] * img->max_imgpel_value_comp[0];
unsigned int max_pix_value_sqd_uv = img->max_imgpel_value_comp[1] * img->max_imgpel_value_comp[1];
float csnr_y = (float) (10 * log10 (max_pix_value_sqd *
(double)((double) impix / (snr->msse_y == 0.0? 1.0 : snr->msse_y))));
float csnr_u = (float) (10 * log10 (max_pix_value_sqd_uv *
(double)((double) impix_cr / (snr->msse_u == 0.0? 1.0 : snr->msse_u))));
float csnr_v = (float) (10 * log10 (max_pix_value_sqd_uv *
(double)((double) impix_cr / (snr->msse_v == 0.0? 1.0 : snr->msse_v))));
fprintf(stdout, " Total encoding time for the seq. : %.3f sec (%.2f fps)\n", tot_time*0.001, 1000.0*(input->no_frames + frame_ctr[B_SLICE])/tot_time);
fprintf(stdout, " Total ME time for sequence : %.3f sec \n\n", me_tot_time*0.001);
fprintf(stdout," PSNR Y(dB) : %5.2f\n", snr->snr_ya);
fprintf(stdout," PSNR U(dB) : %5.2f\n", snr->snr_ua);
fprintf(stdout," PSNR V(dB) : %5.2f\n", snr->snr_va);
fprintf(stdout," cSNR Y(dB) : %5.2f (%5.2f)\n", csnr_y,snr->msse_y/impix);
fprintf(stdout," cSNR U(dB) : %5.2f (%5.2f)\n", csnr_u,snr->msse_u/impix_cr);
fprintf(stdout," cSNR V(dB) : %5.2f (%5.2f)\n\n", csnr_v,snr->msse_v/impix_cr);
}
else
fprintf(stdout, " Total encoding time for the seq. : %.3f sec (%.2f fps)\n\n", tot_time*0.001, 1000.0*(input->no_frames + frame_ctr[B_SLICE])/tot_time);
if (frame_ctr[B_SLICE] != 0)
{
fprintf(stdout, " Total bits : %" FORMAT_OFF_T " (I %" FORMAT_OFF_T ", P %" FORMAT_OFF_T ", B %" FORMAT_OFF_T " NVB %d) \n",
total_bits=stats->bit_ctr_P + stats->bit_ctr_I + stats->bit_ctr_B + stats->bit_ctr_parametersets,
stats->bit_ctr_I, stats->bit_ctr_P, stats->bit_ctr_B, stats->bit_ctr_parametersets);
frame_rate = (img->framerate *(float)(stats->successive_Bframe + 1)) / (float) (input->jumpd+1);
// stats->bitrate= ((float) total_bits * frame_rate)/((float) (input->no_frames + frame_ctr[B_SLICE]));
stats->bitrate= ((float) total_bits * frame_rate) / ((float)(frame_ctr[I_SLICE] + frame_ctr[P_SLICE] + frame_ctr[B_SLICE]));
fprintf(stdout, " Bit rate (kbit/s) @ %2.2f Hz : %5.2f\n", frame_rate, stats->bitrate/1000);
}
else if (input->sp_periodicity == 0)
{
fprintf(stdout, " Total bits : %" FORMAT_OFF_T " (I %" FORMAT_OFF_T ", P %" FORMAT_OFF_T ", NVB %d) \n",
total_bits=stats->bit_ctr_P + stats->bit_ctr_I + stats->bit_ctr_parametersets, stats->bit_ctr_I, stats->bit_ctr_P, stats->bit_ctr_parametersets);
frame_rate = img->framerate / ( (float) (input->jumpd + 1) );
stats->bitrate= ((float) total_bits * frame_rate) / ((float) input->no_frames );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -