<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 11, 2015 at 3:39 PM, Divya Manivannan <span dir="ltr"><<a href="mailto:divya@multicorewareinc.com" target="_blank">divya@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""># HG changeset patch<br>
# User Divya Manivannan <<a href="mailto:divya@multicorewareinc.com">divya@multicorewareinc.com</a>><br>
# Date 1433941776 -19800<br>
# Wed Jun 10 18:39:36 2015 +0530<br>
</span># Node ID ae4c2828912ce11fbcb9ad3ae0920b18716a697e<br>
<span class=""># Parent 586cb40ea52ab0a628521eb992d1723a467fe8fd<br>
cli: modify --csv as CLI only option and move csv printing to x265.cpp<br>
<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c doc/reST/api.rst<br>
<span class="">--- a/doc/reST/api.rst Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/doc/reST/api.rst Wed Jun 10 18:39:36 2015 +0530<br>
@@ -338,13 +338,8 @@<br>
Cleanup<br>
=======<br>
<br>
-At the end of the encode, the application will want to trigger logging<br>
-of the final encode statistics, if :option:`--csv` had been specified::<br>
-<br>
/* x265_encoder_log:<br>
- * write a line to the configured CSV file. If a CSV filename was not<br>
- * configured, or file open failed, or the log level indicated frame level<br>
- * logging, this function will perform no write. */<br>
+ * This function will not generate the log file. It is obsolete */<br>
void x265_encoder_log(x265_encoder *encoder, int argc, char **argv);<br>
<br>
Finally, the encoder must be closed in order to free all of its<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c doc/reST/cli.rst<br>
<span class="">--- a/doc/reST/cli.rst Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/doc/reST/cli.rst Wed Jun 10 18:39:36 2015 +0530<br>
@@ -52,6 +52,7 @@<br>
2. unable to open encoder<br>
3. unable to generate stream headers<br>
4. encoder abort<br>
+ 5. unable to open csv file<br>
<br></span></blockquote><div>Does this need to be a CLI error? I'd prefer just emitting a warning if the CSV file write is not succesful, and not abort the whole encode. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Logging/Statistic Options<br>
=========================<br>
@@ -123,6 +124,8 @@<br>
enough ahead for the necessary reference data to be available. This<br>
is more of a problem for P frames where some blocks are much more<br>
expensive than others.<br>
+<br>
+ **CLI ONLY**<br>
<br>
.. option:: --ssim, --no-ssim<br>
<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c source/CMakeLists.txt<br>
<span class="">--- a/source/CMakeLists.txt Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/CMakeLists.txt Wed Jun 10 18:39:36 2015 +0530<br>
@@ -30,7 +30,7 @@<br>
mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
<br>
# X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 61)<br>
+set(X265_BUILD 62)<br>
configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" target="_blank">x265.def.in</a>"<br>
"${PROJECT_BINARY_DIR}/x265.def")<br>
configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" target="_blank">x265_config.h.in</a>"<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c source/common/param.cpp<br>
<span class="">--- a/source/common/param.cpp Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/common/param.cpp Wed Jun 10 18:39:36 2015 +0530<br>
@@ -109,7 +109,6 @@<br>
param->frameNumThreads = 0;<br>
<br>
param->logLevel = X265_LOG_INFO;<br>
- param->csvfn = NULL;<br>
param->rc.lambdaFileName = NULL;<br>
param->bLogCuStats = 0;<br>
param->decodedPictureHashSEI = 0;<br>
@@ -857,7 +856,6 @@<br>
p->rc.bStatRead = pass & 2;<br>
}<br>
OPT("stats") p->rc.statFileName = strdup(value);<br>
- OPT("csv") p->csvfn = strdup(value);<br>
OPT("scaling-list") p->scalingLists = strdup(value);<br>
OPT2("pools", "numa-pools") p->numaPools = strdup(value);<br>
OPT("lambda-file") p->rc.lambdaFileName = strdup(value);<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c source/encoder/api.cpp<br>
<span class="">--- a/source/encoder/api.cpp Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/encoder/api.cpp Wed Jun 10 18:39:36 2015 +0530<br>
@@ -190,13 +190,13 @@<br>
}<br>
}<br>
<br>
-void x265_encoder_log(x265_encoder* enc, int argc, char **argv)<br>
-{<br>
- if (enc)<br>
- {<br>
- Encoder *encoder = static_cast<Encoder*>(enc);<br>
- encoder->writeLog(argc, argv);<br>
- }<br>
+void x265_encoder_log(x265_encoder* enc, int, char **)<br>
+{<br>
+ if (enc)<br>
+ {<br>
+ Encoder *encoder = static_cast<Encoder*>(enc);<br>
+ x265_log(encoder->m_param, X265_LOG_WARNING, "x265_encoder_log will not generate the log file. It is obsolete\n");<br>
+ }<br>
}<br>
<br>
void x265_encoder_close(x265_encoder *enc)<br>
</span>diff -r 586cb40ea52a -r ae4c2828912c source/encoder/encoder.cpp<br>
<div><div class="h5">--- a/source/encoder/encoder.cpp Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/encoder/encoder.cpp Wed Jun 10 18:39:36 2015 +0530<br>
@@ -43,14 +43,6 @@<br>
const char g_sliceTypeToChar[] = {'B', 'P', 'I'};<br>
}<br>
<br>
-static const char* summaryCSVHeader =<br>
- "Command, Date/Time, Elapsed Time, FPS, Bitrate, "<br>
- "Y PSNR, U PSNR, V PSNR, Global PSNR, SSIM, SSIM (dB), "<br>
- "I count, I ave-QP, I kpbs, I-PSNR Y, I-PSNR U, I-PSNR V, I-SSIM (dB), "<br>
- "P count, P ave-QP, P kpbs, P-PSNR Y, P-PSNR U, P-PSNR V, P-SSIM (dB), "<br>
- "B count, B ave-QP, B kpbs, B-PSNR Y, B-PSNR U, B-PSNR V, B-SSIM (dB), "<br>
- "Version\n";<br>
-<br>
static const char* defaultAnalysisFileName = "x265_analysis.dat";<br>
<br>
using namespace X265_NS;<br>
@@ -72,7 +64,6 @@<br>
m_exportedPic = NULL;<br>
m_numDelayedPic = 0;<br>
m_outputCount = 0;<br>
- m_csvfpt = NULL;<br>
m_param = NULL;<br>
m_latestParam = NULL;<br>
m_cuOffsetY = NULL;<br>
@@ -223,43 +214,6 @@<br>
initSPS(&m_sps);<br>
initPPS(&m_pps);<br>
<br>
- /* Try to open CSV file handle */<br>
- if (m_param->csvfn)<br>
- {<br>
- m_csvfpt = fopen(m_param->csvfn, "r");<br>
- if (m_csvfpt)<br>
- {<br>
- /* file already exists, re-open for append */<br>
- fclose(m_csvfpt);<br>
- m_csvfpt = fopen(m_param->csvfn, "ab");<br>
- }<br>
- else<br>
- {<br>
- /* new CSV file, write header */<br>
- m_csvfpt = fopen(m_param->csvfn, "wb");<br>
- if (m_csvfpt)<br>
- {<br>
- if (m_param->logLevel >= X265_LOG_FRAME)<br>
- {<br>
- fprintf(m_csvfpt, "Encode Order, Type, POC, QP, Bits, ");<br>
- if (m_param->rc.rateControlMode == X265_RC_CRF)<br>
- fprintf(m_csvfpt, "RateFactor, ");<br>
- fprintf(m_csvfpt, "Y PSNR, U PSNR, V PSNR, YUV PSNR, SSIM, SSIM (dB), List 0, List 1");<br>
- /* detailed performance statistics */<br>
- fprintf(m_csvfpt, ", DecideWait (ms), Row0Wait (ms), Wall time (ms), Ref Wait Wall (ms), Total CTU time (ms), Stall Time (ms), Avg WPP, Row Blocks\n");<br>
- }<br>
- else<br>
- fputs(summaryCSVHeader, m_csvfpt);<br>
- }<br>
- }<br>
-<br>
- if (!m_csvfpt)<br>
- {<br>
- x265_log(m_param, X265_LOG_ERROR, "Unable to open CSV log file <%s>, aborting\n", m_param->csvfn);<br>
- m_aborted = true;<br>
- }<br>
- }<br>
-<br>
int numRows = (m_param->sourceHeight + g_maxCUSize - 1) / g_maxCUSize;<br>
int numCols = (m_param->sourceWidth + g_maxCUSize - 1) / g_maxCUSize;<br>
for (int i = 0; i < m_param->frameNumThreads; i++)<br>
@@ -371,8 +325,6 @@<br>
<br>
if (m_analysisFile)<br>
fclose(m_analysisFile);<br>
- if (m_csvfpt)<br>
- fclose(m_csvfpt);<br>
<br>
if (m_param)<br>
{<br>
@@ -381,7 +333,6 @@<br>
free((char*)m_param->rc.statFileName);<br>
free((char*)m_param->analysisFileName);<br>
free((char*)m_param->scalingLists);<br>
- free((char*)m_param->csvfn);<br>
free((char*)m_param->numaPools);<br>
free((char*)m_param->masteringDisplayColorVolume);<br>
free((char*)m_param->contentLightLevelInfo);<br>
</div></div>@@ -796,38 +747,6 @@<br>
m_totalQp += aveQp;<br>
}<br>
<br>
-char* Encoder::statsCSVString(EncStats& stat, char* buffer)<br>
-{<br>
- if (!stat.m_numPics)<br>
- {<br>
- sprintf(buffer, "-, -, -, -, -, -, -, ");<br>
- return buffer;<br>
- }<br>
-<br>
- double fps = (double)m_param->fpsNum / m_param->fpsDenom;<br>
- double scale = fps / 1000 / (double)stat.m_numPics;<br>
-<br>
- int len = sprintf(buffer, "%-6u, ", stat.m_numPics);<br>
-<br>
- len += sprintf(buffer + len, "%2.2lf, ", stat.m_totalQp / (double)stat.m_numPics);<br>
- len += sprintf(buffer + len, "%-8.2lf, ", stat.m_accBits * scale);<br>
- if (m_param->bEnablePsnr)<br>
- {<br>
- len += sprintf(buffer + len, "%.3lf, %.3lf, %.3lf, ",<br>
- stat.m_psnrSumY / (double)stat.m_numPics,<br>
- stat.m_psnrSumU / (double)stat.m_numPics,<br>
- stat.m_psnrSumV / (double)stat.m_numPics);<br>
- }<br>
- else<br>
- len += sprintf(buffer + len, "-, -, -, ");<br>
<span class="">-<br>
- if (m_param->bEnableSsim)<br>
</span>- sprintf(buffer + len, "%.3lf, ", x265_ssim2dB(stat.m_globalSsim / (double)stat.m_numPics));<br>
- else<br>
- sprintf(buffer + len, "-, ");<br>
- return buffer;<br>
-}<br>
-<br>
char* Encoder::statsString(EncStats& stat, char* buffer)<br>
{<br>
<span class=""> double fps = (double)m_param->fpsNum / m_param->fpsDenom;<br>
</span>@@ -1075,6 +994,33 @@<br>
<div><div class="h5"> stats->bitrate = 0;<br>
stats->elapsedVideoTime = 0;<br>
}<br>
+<br>
+ double fps = (double)m_param->fpsNum / m_param->fpsDenom;<br>
+ double scale = fps / 1000;<br>
+<br>
+ stats->statsI.numPics = m_analyzeI.m_numPics;<br>
+ stats->statsI.avgQp = m_analyzeI.m_totalQp / (double)m_analyzeI.m_numPics;<br>
+ stats->statsI.bitrate = m_analyzeI.m_accBits * scale / (double)m_analyzeI.m_numPics;<br>
+ stats->statsI.psnrY = m_analyzeI.m_psnrSumY / (double)m_analyzeI.m_numPics;<br>
+ stats->statsI.psnrU = m_analyzeI.m_psnrSumU / (double)m_analyzeI.m_numPics;<br>
+ stats->statsI.psnrV = m_analyzeI.m_psnrSumV / (double)m_analyzeI.m_numPics;<br>
+ stats->statsI.ssim = x265_ssim2dB(m_analyzeI.m_globalSsim / (double)m_analyzeI.m_numPics);<br>
+<br>
+ stats->statsP.numPics = m_analyzeP.m_numPics;<br>
+ stats->statsP.avgQp = m_analyzeP.m_totalQp / (double)m_analyzeP.m_numPics;<br>
+ stats->statsP.bitrate = m_analyzeP.m_accBits * scale / (double)m_analyzeP.m_numPics;<br>
+ stats->statsP.psnrY = m_analyzeP.m_psnrSumY / (double)m_analyzeP.m_numPics;<br>
+ stats->statsP.psnrU = m_analyzeP.m_psnrSumU / (double)m_analyzeP.m_numPics;<br>
+ stats->statsP.psnrV = m_analyzeP.m_psnrSumV / (double)m_analyzeP.m_numPics;<br>
+ stats->statsP.ssim = x265_ssim2dB(m_analyzeP.m_globalSsim / (double)m_analyzeP.m_numPics);<br>
+<br>
+ stats->statsB.numPics = m_analyzeB.m_numPics;<br>
+ stats->statsB.avgQp = m_analyzeB.m_totalQp / (double)m_analyzeB.m_numPics;<br>
+ stats->statsB.bitrate = m_analyzeB.m_accBits * scale / (double)m_analyzeB.m_numPics;<br>
+ stats->statsB.psnrY = m_analyzeB.m_psnrSumY / (double)m_analyzeB.m_numPics;<br>
+ stats->statsB.psnrU = m_analyzeB.m_psnrSumU / (double)m_analyzeB.m_numPics;<br>
+ stats->statsB.psnrV = m_analyzeB.m_psnrSumV / (double)m_analyzeB.m_numPics;<br>
+ stats->statsB.ssim = x265_ssim2dB(m_analyzeB.m_globalSsim / (double)m_analyzeB.m_numPics);<br>
}<br>
<br>
/* If new statistics are added to x265_stats, we must check here whether the<br>
</div></div>@@ -1082,57 +1028,6 @@<br>
<div><div class="h5"> * future safety) */<br>
}<br>
<br>
-void Encoder::writeLog(int argc, char **argv)<br>
-{<br>
- if (m_csvfpt)<br>
- {<br>
- if (m_param->logLevel >= X265_LOG_FRAME)<br>
- {<br>
- // adding summary to a per-frame csv log file needs a summary header<br>
- fprintf(m_csvfpt, "\nSummary\n");<br>
- fputs(summaryCSVHeader, m_csvfpt);<br>
- }<br>
- // CLI arguments or other<br>
- for (int i = 1; i < argc; i++)<br>
- {<br>
- if (i) fputc(' ', m_csvfpt);<br>
- fputs(argv[i], m_csvfpt);<br>
- }<br>
-<br>
- // current date and time<br>
- time_t now;<br>
- struct tm* timeinfo;<br>
- time(&now);<br>
- timeinfo = localtime(&now);<br>
- char buffer[200];<br>
- strftime(buffer, 128, "%c", timeinfo);<br>
- fprintf(m_csvfpt, ", %s, ", buffer);<br>
-<br>
- x265_stats stats;<br>
- fetchStats(&stats, sizeof(stats));<br>
-<br>
- // elapsed time, fps, bitrate<br>
- fprintf(m_csvfpt, "%.2f, %.2f, %.2f,",<br>
- stats.elapsedEncodeTime, stats.encodedPictureCount / stats.elapsedEncodeTime, stats.bitrate);<br>
-<br>
- if (m_param->bEnablePsnr)<br>
- fprintf(m_csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",<br>
- stats.globalPsnrY / stats.encodedPictureCount, stats.globalPsnrU / stats.encodedPictureCount,<br>
- stats.globalPsnrV / stats.encodedPictureCount, stats.globalPsnr);<br>
- else<br>
- fprintf(m_csvfpt, " -, -, -, -,");<br>
- if (m_param->bEnableSsim)<br>
- fprintf(m_csvfpt, " %.6f, %6.3f,", stats.globalSsim, x265_ssim2dB(stats.globalSsim));<br>
- else<br>
- fprintf(m_csvfpt, " -, -,");<br>
-<br>
- fputs(statsCSVString(m_analyzeI, buffer), m_csvfpt);<br>
- fputs(statsCSVString(m_analyzeP, buffer), m_csvfpt);<br>
- fputs(statsCSVString(m_analyzeB, buffer), m_csvfpt);<br>
- fprintf(m_csvfpt, " %s\n", x265_version_str);<br>
- }<br>
-}<br>
-<br>
/**<br>
* Produce an ascii(hex) representation of picture digest.<br>
*<br>
</div></div>@@ -1281,59 +1176,6 @@<br>
<div><div class="h5"><br>
x265_log(m_param, X265_LOG_DEBUG, "%s\n", buf);<br>
}<br>
-<br>
- if (m_param->logLevel >= X265_LOG_FRAME && m_csvfpt)<br>
- {<br>
- // per frame CSV logging if the file handle is valid<br>
- fprintf(m_csvfpt, "%d, %c-SLICE, %4d, %2.2lf, %10d,", m_outputCount++, c, poc, curEncData.m_avgQpAq, (int)bits);<br>
- if (m_param->rc.rateControlMode == X265_RC_CRF)<br>
- fprintf(m_csvfpt, "%.3lf,", curEncData.m_rateFactor);<br>
- double psnr = (psnrY * 6 + psnrU + psnrV) / 8;<br>
- if (m_param->bEnablePsnr)<br>
- fprintf(m_csvfpt, "%.3lf, %.3lf, %.3lf, %.3lf,", psnrY, psnrU, psnrV, psnr);<br>
- else<br>
- fputs(" -, -, -, -,", m_csvfpt);<br>
- if (m_param->bEnableSsim)<br>
- fprintf(m_csvfpt, " %.6f, %6.3f", ssim, x265_ssim2dB(ssim));<br>
- else<br>
- fputs(" -, -", m_csvfpt);<br>
- if (slice->isIntra())<br>
- fputs(", -, -", m_csvfpt);<br>
- else<br>
- {<br>
- int numLists = slice->isInterP() ? 1 : 2;<br>
- for (int list = 0; list < numLists; list++)<br>
- {<br>
- fprintf(m_csvfpt, ", ");<br>
- for (int ref = 0; ref < slice->m_numRefIdx[list]; ref++)<br>
- {<br>
- int k = slice->m_refPOCList[list][ref] - slice->m_lastIDR;<br>
- fprintf(m_csvfpt, " %d", k);<br>
- }<br>
- }<br>
-<br>
- if (numLists == 1)<br>
- fputs(", -", m_csvfpt);<br>
- }<br>
-<br>
-#define ELAPSED_MSEC(start, end) (((double)(end) - (start)) / 1000)<br>
-<br>
- // detailed frame statistics<br>
- fprintf(m_csvfpt, ", %.1lf, %.1lf, %.1lf, %.1lf, %.1lf, %.1lf",<br>
- ELAPSED_MSEC(0, curEncoder->m_slicetypeWaitTime),<br>
- ELAPSED_MSEC(curEncoder->m_startCompressTime, curEncoder->m_row0WaitTime),<br>
- ELAPSED_MSEC(curEncoder->m_row0WaitTime, curEncoder->m_endCompressTime),<br>
- ELAPSED_MSEC(curEncoder->m_row0WaitTime, curEncoder->m_allRowsAvailableTime),<br>
- ELAPSED_MSEC(0, curEncoder->m_totalWorkerElapsedTime),<br>
- ELAPSED_MSEC(0, curEncoder->m_totalNoWorkerTime));<br>
- if (curEncoder->m_totalActiveWorkerCount)<br>
- fprintf(m_csvfpt, ", %.3lf", (double)curEncoder->m_totalActiveWorkerCount / curEncoder->m_activeWorkerCountSamples);<br>
- else<br>
- fputs(", 1", m_csvfpt);<br>
- fprintf(m_csvfpt, ", %d", curEncoder->m_countRowBlocks);<br>
- fprintf(m_csvfpt, "\n");<br>
- fflush(stderr);<br>
- }<br>
}<br>
<br>
#if defined(_MSC_VER)<br>
</div></div>diff -r 586cb40ea52a -r ae4c2828912c source/encoder/encoder.h<br>
<span class="">--- a/source/encoder/encoder.h Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/encoder/encoder.h Wed Jun 10 18:39:36 2015 +0530<br>
@@ -105,7 +105,6 @@<br>
EncStats m_analyzeI;<br>
EncStats m_analyzeP;<br>
EncStats m_analyzeB;<br>
- FILE* m_csvfpt;<br>
int64_t m_encodeStartTime;<br>
<br>
// weighted prediction<br>
</span>@@ -149,14 +148,10 @@<br>
<span class=""><br>
void fetchStats(x265_stats* stats, size_t statsSizeBytes);<br>
<br>
- void writeLog(int argc, char **argv);<br>
-<br>
void printSummary();<br>
<br>
char* statsString(EncStats&, char*);<br>
<br>
</span>- char* statsCSVString(EncStats& stat, char* buffer);<br>
-<br>
void configure(x265_param *param);<br>
<br>
void updateVbvPlan(RateControl* rc);<br>
diff -r 586cb40ea52a -r ae4c2828912c source/x265.cpp<br>
<div><div class="h5">--- a/source/x265.cpp Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/x265.cpp Wed Jun 10 18:39:36 2015 +0530<br>
@@ -68,12 +68,22 @@<br>
b_ctrl_c = 1;<br>
}<br>
<br>
+static const char* summaryCSVHeader =<br>
+ "Command, Date/Time, Elapsed Time, FPS, Bitrate, "<br>
+ "Y PSNR, U PSNR, V PSNR, Global PSNR, SSIM, SSIM (dB), "<br>
+ "I count, I ave-QP, I kbps, I-PSNR Y, I-PSNR U, I-PSNR V, I-SSIM (dB), "<br>
+ "P count, P ave-QP, P kbps, P-PSNR Y, P-PSNR U, P-PSNR V, P-SSIM (dB), "<br>
+ "B count, B ave-QP, B kbps, B-PSNR Y, B-PSNR U, B-PSNR V, B-SSIM (dB), "<br>
+ "Version\n";<br>
+<br>
struct CLIOptions<br>
{<br>
InputFile* input;<br>
ReconFile* recon;<br>
OutputFile* output;<br>
FILE* qpfile;<br>
+ FILE* csvfpt;<br>
+ const char* csvfn;<br>
const char* reconPlayCmd;<br>
const x265_api* api;<br>
x265_param* param;<br>
@@ -95,6 +105,8 @@<br>
recon = NULL;<br>
output = NULL;<br>
qpfile = NULL;<br>
+ csvfpt = NULL;<br>
+ csvfn = NULL;<br>
reconPlayCmd = NULL;<br>
api = NULL;<br>
param = NULL;<br>
@@ -108,6 +120,8 @@<br>
}<br>
<br>
void destroy();<br>
+ bool parseCSVFile();<br>
+ void writeLog(int argc, char **argv, x265_stats* stats);<br>
void printStatus(uint32_t frameNum);<br>
bool parse(int argc, char **argv);<br>
bool parseQPFile(x265_picture &pic_org);<br>
@@ -124,11 +138,123 @@<br>
if (qpfile)<br>
fclose(qpfile);<br>
qpfile = NULL;<br>
+ if (csvfpt)<br>
+ fclose(csvfpt);<br>
+ csvfpt = NULL;<br>
if (output)<br>
output->release();<br>
output = NULL;<br>
}<br>
<br>
+bool CLIOptions::parseCSVFile()<br>
+{<br>
+ csvfpt = fopen(csvfn, "r");<br>
+ if (csvfpt)<br>
+ {<br>
+ /* file already exists, re-open for append */<br>
+ fclose(csvfpt);<br>
+ csvfpt = fopen(csvfn, "ab");<br>
+ }<br>
+ else<br>
+ {<br>
+ /* new CSV file, write header */<br>
+ csvfpt = fopen(csvfn, "wb");<br>
+ if (csvfpt)<br>
+ fputs(summaryCSVHeader, csvfpt);<br>
+ }<br>
+<br>
+ if (!csvfpt)<br>
+ {<br>
+ x265_log(param, X265_LOG_ERROR, "Unable to open CSV log file <%s>, aborting\n", csvfn);<br>
+ return true;<br>
+ }<br>
+ return false;<br>
+}<br>
+<br>
+void CLIOptions::writeLog(int argc, char **argv, x265_stats* stats)<br>
+{<br>
+ if (csvfpt)<br>
+ {<br>
+ // CLI arguments or other<br>
+ for (int i = 1; i < argc; i++)<br>
+ {<br>
+ if (i) fputc(' ', csvfpt);<br>
+ fputs(argv[i], csvfpt);<br>
+ }<br>
+<br>
+ // current date and time<br>
+ time_t now;<br>
+ struct tm* timeinfo;<br>
+ time(&now);<br>
+ timeinfo = localtime(&now);<br>
+ char buffer[200];<br>
+ strftime(buffer, 128, "%c", timeinfo);<br>
+ fprintf(csvfpt, ", %s, ", buffer);<br>
+<br>
+ // elapsed time, fps, bitrate<br>
+ fprintf(csvfpt, "%.2f, %.2f, %.2f,",<br>
+ stats->elapsedEncodeTime, stats->encodedPictureCount / stats->elapsedEncodeTime, stats->bitrate);<br>
+<br>
+ if (param->bEnablePsnr)<br>
+ fprintf(csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",<br>
+ stats->globalPsnrY / stats->encodedPictureCount, stats->globalPsnrU / stats->encodedPictureCount,<br>
+ stats->globalPsnrV / stats->encodedPictureCount, stats->globalPsnr);<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -, -,");<br>
+ if (param->bEnableSsim)<br>
+ fprintf(csvfpt, " %.6f, %6.3f,", stats->globalSsim, x265_ssim2dB(stats->globalSsim));<br>
+ else<br>
+ fprintf(csvfpt, " -, -,");<br>
+<br>
+ if (stats->statsI.numPics)<br>
+ {<br>
+ fprintf(csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsI.numPics, stats->statsI.avgQp, stats->statsI.bitrate);<br>
+ if (param->bEnablePsnr)<br>
+ fprintf(csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsI.psnrY, stats->statsI.psnrU, stats->statsI.psnrV);<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -,");<br>
+ if (param->bEnableSsim)<br>
+ fprintf(csvfpt, " %.3lf,", stats->statsI.ssim);<br>
+ else<br>
+ fprintf(csvfpt, " -,");<br>
+ }<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -, -, -, -, -,");<br>
+<br>
+ if (stats->statsP.numPics)<br>
+ {<br>
+ fprintf(csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsP.numPics, stats->statsP.avgQp, stats->statsP.bitrate);<br>
+ if (param->bEnablePsnr)<br>
+ fprintf(csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsP.psnrY, stats->statsP.psnrU, stats->statsP.psnrV);<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -,");<br>
+ if (param->bEnableSsim)<br>
+ fprintf(csvfpt, " %.3lf,", stats->statsP.ssim);<br>
+ else<br>
+ fprintf(csvfpt, " -,");<br>
+ }<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -, -, -, -, -,");<br>
+<br>
+ if (stats->statsB.numPics)<br>
+ {<br>
+ fprintf(csvfpt, " %-6u, %2.2lf, %-8.2lf,", stats->statsB.numPics, stats->statsB.avgQp, stats->statsB.bitrate);<br>
+ if (param->bEnablePsnr)<br>
+ fprintf(csvfpt, " %.3lf, %.3lf, %.3lf,", stats->statsB.psnrY, stats->statsB.psnrU, stats->statsB.psnrV);<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -,");<br>
+ if (param->bEnableSsim)<br>
+ fprintf(csvfpt, " %.3lf,", stats->statsB.ssim);<br>
+ else<br>
+ fprintf(csvfpt, " -,");<br>
+ }<br>
+ else<br>
+ fprintf(csvfpt, " -, -, -, -, -, -, -,");<br>
+<br>
+ fprintf(csvfpt, " %s\n", x265_version_str);<br>
+ }<br>
+}<br>
+<br>
void CLIOptions::printStatus(uint32_t frameNum)<br>
{<br>
char buf[200];<br>
@@ -271,6 +397,7 @@<br>
if (0) ;<br>
OPT2("frame-skip", "seek") this->seek = (uint32_t)x265_atoi(optarg, bError);<br>
OPT("frames") this->framesToBeEncoded = (uint32_t)x265_atoi(optarg, bError);<br>
+ OPT("csv") this->csvfn = optarg;<br>
OPT("no-progress") this->bProgress = false;<br>
OPT("output") outputfn = optarg;<br>
OPT("input") inputfn = optarg;<br>
@@ -475,7 +602,8 @@<br>
* 1 - unable to parse command line<br>
* 2 - unable to open encoder<br>
* 3 - unable to generate stream headers<br>
- * 4 - encoder abort */<br>
+ * 4 - encoder abort<br>
+ * 5 - unable to open csv file */<br>
<br>
int main(int argc, char **argv)<br>
{<br>
@@ -509,6 +637,17 @@<br>
if (cliopt.reconPlayCmd)<br>
reconPlay = new ReconPlay(cliopt.reconPlayCmd, *param);<br>
<br>
+ if (cliopt.csvfn)<br>
+ {<br>
+ if (cliopt.parseCSVFile())<br>
+ {<br>
+ cliopt.destroy();<br>
+ if (cliopt.api)<br>
+ cliopt.api->param_free(cliopt.param);<br>
+ exit(5);<br>
+ }<br>
+ }<br>
+<br>
/* note: we could try to acquire a different libx265 API here based on<br>
* the profile found during option parsing, but it must be done before<br>
* opening an encoder */<br>
@@ -669,8 +808,8 @@<br>
delete reconPlay;<br>
<br>
api->encoder_get_stats(encoder, &stats, sizeof(stats));<br>
- if (param->csvfn && !b_ctrl_c)<br>
- api->encoder_log(encoder, argc, argv);<br>
+ if (cliopt.csvfn && !b_ctrl_c)<br>
+ cliopt.writeLog(argc, argv, &stats);<br>
api->encoder_close(encoder);<br>
<br>
int64_t second_largest_pts = 0;<br>
</div></div>diff -r 586cb40ea52a -r ae4c2828912c source/x265.h<br>
<div class="HOEnZb"><div class="h5">--- a/source/x265.h Wed Jun 10 17:32:11 2015 +0530<br>
+++ b/source/x265.h Wed Jun 10 18:39:36 2015 +0530<br>
@@ -302,20 +302,35 @@<br>
X265_RC_CRF<br>
} X265_RC_METHODS;<br>
<br>
+/* slice type statistics */<br>
+typedef struct x265_sliceType_stats<br>
+{<br>
+ double avgQp;<br>
+ double bitrate;<br>
+ double psnrY;<br>
+ double psnrU;<br>
+ double psnrV;<br>
+ double ssim;<br>
+ uint32_t numPics;<br>
+} x265_sliceType_stats;<br>
+<br>
/* Output statistics from encoder */<br>
typedef struct x265_stats<br>
{<br>
- double globalPsnrY;<br>
- double globalPsnrU;<br>
- double globalPsnrV;<br>
- double globalPsnr;<br>
- double globalSsim;<br>
- double elapsedEncodeTime; /* wall time since encoder was opened */<br>
- double elapsedVideoTime; /* encoded picture count / frame rate */<br>
- double bitrate; /* accBits / elapsed video time */<br>
- uint64_t accBits; /* total bits output thus far */<br>
- uint32_t encodedPictureCount; /* number of output pictures thus far */<br>
- uint32_t totalWPFrames; /* number of uni-directional weighted frames used */<br>
+ double globalPsnrY;<br>
+ double globalPsnrU;<br>
+ double globalPsnrV;<br>
+ double globalPsnr;<br>
+ double globalSsim;<br>
+ double elapsedEncodeTime; /* wall time since encoder was opened */<br>
+ double elapsedVideoTime; /* encoded picture count / frame rate */<br>
+ double bitrate; /* accBits / elapsed video time */<br>
+ uint64_t accBits; /* total bits output thus far */<br>
+ uint32_t encodedPictureCount; /* number of output pictures thus far */<br>
+ uint32_t totalWPFrames; /* number of uni-directional weighted frames used */<br>
+ x265_sliceType_stats statsI; /* statistics of I slice */<br>
+ x265_sliceType_stats statsP; /* statistics of P slice */<br>
+ x265_sliceType_stats statsB; /* statistics of B slice */<br>
} x265_stats;<br>
<br>
/* String values accepted by x265_param_parse() (and CLI) for various parameters */<br>
@@ -453,13 +468,6 @@<br>
* X265_LOG_FULL, default is X265_LOG_INFO */<br>
int logLevel;<br>
<br>
- /* filename of CSV log. If logLevel greater than or equal to X265_LOG_FRAME,<br>
- * the encoder will emit per-slice statistics to this log file in encode<br>
- * order. Otherwise the encoder will emit per-stream statistics into the log<br>
- * file when x265_encoder_log is called (presumably at the end of the<br>
- * encode) */<br>
- const char* csvfn;<br>
-<br></div></div></blockquote><div><br></div><div>Just like cu-stats, this cannot be removed entirely. Needs a deprecated message. Will modify this patch and push it in. <br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
/*== Internal Picture Specification ==*/<br>
<br>
/* Internal encoder bit depth. If x265 was compiled to use 8bit pixels<br>
@@ -1262,10 +1270,8 @@<br>
* returns encoder statistics */<br>
void x265_encoder_get_stats(x265_encoder *encoder, x265_stats *, uint32_t statsSizeBytes);<br>
<br>
-/* x265_encoder_log:<br>
- * write a line to the configured CSV file. If a CSV filename was not<br>
- * configured, or file open failed, or the log level indicated frame level<br>
- * logging, this function will perform no write. */<br>
+/* x265_encoder_log:<br>
+ * This function is obsolete. */<br>
void x265_encoder_log(x265_encoder *encoder, int argc, char **argv);<br>
<br>
/* x265_encoder_close:<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</div></div></blockquote></div><br></div></div>