📄 report.c
字号:
/*!
* \file
* report.c
* \brief
* Report related files()
* \author
* Main contributors (see contributors.h for copyright, address and affiliation details)
* - Karsten Suehring <suehring@hhi.de>
* - Alexis Michael Tourapis <alexismt@ieee.org>
***********************************************************************
*/
#include "contributors.h"
#include <time.h>
#include <math.h>
#include <sys/timeb.h>
#include "global.h"
#include "context_ini.h"
#include "explicit_gop.h"
#include "filehandle.h"
#include "fmo.h"
#include "image.h"
#include "intrarefresh.h"
#include "leaky_bucket.h"
#include "me_epzs.h"
#include "output.h"
#include "parset.h"
#include "report.h"
StatParameters statistics, *stats = &statistics;
DistortionParams distortions, *dist = &distortions;
static char DistortionType[3][20] = {"SAD", "SSE", "Hadamard SAD"};
extern int frame_statistic_start;
extern ColocatedParams *Co_located;
extern ColocatedParams *Co_located_JV[MAX_PLANE]; //!< Co_located to be used during 4:4:4 independent mode encoding
extern void Clear_Motion_Search_Module (void);
void report_log_mode(InputParameters *params, StatParameters *stats, int64 bit_use[NUM_SLICE_TYPES][2]);
/*!
************************************************************************
* \brief
* Reports frame statistical data to a stats file
************************************************************************
*/
void report_frame_statistic()
{
FILE *p_stat_frm = NULL;
static int64 last_bit_ctr_n = 0;
int i;
char name[30];
int bitcounter;
StatParameters *cur_stats = &enc_picture->stats;
#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*4*| P1*8*| P2*4*| P2*8*| P3*4*| P3*8*| P8 | P8:4 | P4*4*| P4*8*| P8:5 | P8:6 | P8:7 | BI4 | BI8 | BI16 | B0 | B1 | B2 | B3 | B0*4*| B0*8*| B1*4*| B1*8*| B2*4*| B2*8*| B3*4*| B3*8*| B8 | B8:0 |B80*4*|B80*8*| B8:4 | B4*4*| B4*8*| 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]=params->infile[i + imax(0,(int) (strlen(params->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 |", params->PicInterlace, params->MbInterlace);
if (img->frm_number == 0 && img->frame_num == 0)
{
bitcounter = (int) stats->bit_counter[I_SLICE];
}
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|", dist->metric[PSNR].value[0], dist->metric[PSNR].value[1], dist->metric[PSNR].value[2]);
//report modes
//I-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[I_SLICE][I4MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[I_SLICE][I8MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[I_SLICE][I16MB]);
//chroma intra mode
fprintf(p_stat_frm, " %5d|", cur_stats->intra_chroma_mode[0]);
fprintf(p_stat_frm, " %5d|", cur_stats->intra_chroma_mode[1]);
fprintf(p_stat_frm, " %5d|", cur_stats->intra_chroma_mode[2]);
fprintf(p_stat_frm, " %5d|", cur_stats->intra_chroma_mode[3]);
//P-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][I4MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][I8MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][I16MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][0 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][1 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][2 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][3 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][1][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][1][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][2][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][2][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][3][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", stats->mode_use_transform[P_SLICE][3][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][P8x8 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][4 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[P_SLICE][4][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[P_SLICE][4][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][5 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][6 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[P_SLICE][7 ]);
//B-Modes
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][I4MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][I8MB ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][I16MB]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][0 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][1 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][2 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][3 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][0][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][0][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][1][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][1][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][2][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][2][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][3][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][3][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][P8x8]);
fprintf(p_stat_frm, " %d|", (cur_stats->b8_mode_0_use [B_SLICE][0] + cur_stats->b8_mode_0_use [B_SLICE][1]));
fprintf(p_stat_frm, " %5d|", cur_stats->b8_mode_0_use [B_SLICE][0]);
fprintf(p_stat_frm, " %5d|", cur_stats->b8_mode_0_use [B_SLICE][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][4 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][4][0]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use_transform[B_SLICE][4][1]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][5 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][6 ]);
fprintf(p_stat_frm, " %5" FORMAT_OFF_T "|", cur_stats->mode_use[B_SLICE][7 ]);
fprintf(p_stat_frm, "\n");
//save the last results
frame_statistic_start = 0;
fclose(p_stat_frm);
}
double report_slice_pred_stats(FILE *p_stat, StatParameters *stats, int slice_type, double bit_use, char *slice_name)
{
fprintf(p_stat,"\n ---------------------|----------------|-----------------|");
fprintf(p_stat,"\n %8s | Mode used | MotionInfo bits |", slice_name);
fprintf(p_stat,"\n ---------------------|----------------|-----------------|");
fprintf(p_stat,"\n Mode 0 (copy) | %5" FORMAT_OFF_T " | %8.2f |", stats->mode_use[slice_type][0 ], (double)stats->bit_use_mode[slice_type][0 ] / bit_use);
fprintf(p_stat,"\n Mode 1 (16x16) | %5" FORMAT_OFF_T " | %8.2f |", stats->mode_use[slice_type][1 ], (double)stats->bit_use_mode[slice_type][1 ] / bit_use);
fprintf(p_stat,"\n Mode 2 (16x8) | %5" FORMAT_OFF_T " | %8.2f |", stats->mode_use[slice_type][2 ], (double)stats->bit_use_mode[slice_type][2 ] / bit_use);
fprintf(p_stat,"\n Mode 3 (8x16) | %5" FORMAT_OFF_T " | %8.2f |", stats->mode_use[slice_type][3 ], (double)stats->bit_use_mode[slice_type][3 ] / bit_use);
fprintf(p_stat,"\n Mode 4 (8x8) | %5" FORMAT_OFF_T " | %8.2f |", stats->mode_use[slice_type][P8x8], (double)stats->bit_use_mode[slice_type][P8x8] / bit_use);
fprintf(p_stat,"\n Mode 5 intra 4x4 | %5" FORMAT_OFF_T " |-----------------|", stats->mode_use[slice_type][I4MB]);
fprintf(p_stat,"\n Mode 6 intra 8x8 | %5" FORMAT_OFF_T " |", stats->mode_use[slice_type][I8MB]);
fprintf(p_stat,"\n Mode 7+ intra 16x16 | %5" FORMAT_OFF_T " |", stats->mode_use[slice_type][I16MB]);
fprintf(p_stat,"\n Mode intra IPCM | %5" FORMAT_OFF_T " |", stats->mode_use[slice_type][IPCM ]);
return (double)(stats->bit_use_mode[slice_type][0] + stats->bit_use_mode[slice_type][1] + stats->bit_use_mode[slice_type][2]
+ stats->bit_use_mode[slice_type][3] + stats->bit_use_mode[slice_type][P8x8]) / bit_use;
}
/*!
***********************************************************************
* \brief
* Terminates and reports statistics on error.
*
***********************************************************************
*/
void report_stats_on_error(void)
{
params->no_frames = img->frm_number;
free_encoder_memory(img);
exit (-1);
}
void report_stats(InputParameters *params, StatParameters *stats, int64 bit_use[NUM_SLICE_TYPES][2], float frame_rate)
{
FILE *p_stat; //!< status file for the last encoding session
double mean_motion_info_bit_use[NUM_SLICE_TYPES] = {0.0};
int i;
if (strlen(params->StatsFile) == 0)
strcpy (params->StatsFile,"stats.dat");
if ((p_stat = fopen(params->StatsFile, "wt")) == 0)
{
snprintf(errortext, ET_SIZE, "Error open file %s", params->StatsFile);
error(errortext, 500);
}
fprintf(p_stat," -------------------------------------------------------------- \n");
fprintf(p_stat," This file contains statistics for the last encoded sequence \n");
fprintf(p_stat," -------------------------------------------------------------- \n");
fprintf(p_stat, " Sequence : %s\n", params->infile);
fprintf(p_stat, " No.of coded pictures : %4d\n", stats->frame_counter);
fprintf(p_stat, " Freq. for encoded bitstream : %4.0f\n", frame_rate);
fprintf(p_stat, " I Slice Bitrate(kb/s) : %6.2f\n", stats->bitrate_st[I_SLICE] / 1000);
fprintf(p_stat, " P Slice Bitrate(kb/s) : %6.2f\n", stats->bitrate_st[P_SLICE] / 1000);
fprintf(p_stat, " B Slice Bitrate(kb/s) : %6.2f\n", stats->bitrate_st[B_SLICE] / 1000);
fprintf(p_stat, " Total Bitrate(kb/s) : %6.2f\n", stats->bitrate / 1000);
for (i = 0; i < 3; i++)
{
fprintf(p_stat," ME Level %1d Metric : %s\n", i, DistortionType[params->MEErrorMetric[i]]);
}
fprintf(p_stat," Mode Decision Metric : %s\n", DistortionType[params->ModeDecisionMetric]);
switch ( params->ChromaMEEnable )
{
case 1:
fprintf(p_stat," ME for components : YCbCr\n");
break;
default:
fprintf(p_stat," ME for components : Y\n");
break;
}
fprintf(p_stat, " Image format : %dx%d\n", params->output.width, params->output.height);
if (params->intra_upd)
fprintf(p_stat," Error robustness : On\n");
else
fprintf(p_stat," Error robustness : Off\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -