[x265] [PATCH] cli: modify --csv as CLI only option and move csv printing to x265.cpp

Deepthi Nandakumar deepthi at multicorewareinc.com
Thu Jun 11 13:59:07 CEST 2015


On Thu, Jun 11, 2015 at 3:39 PM, Divya Manivannan <
divya at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Divya Manivannan <divya at multicorewareinc.com>
> # Date 1433941776 -19800
> #      Wed Jun 10 18:39:36 2015 +0530
> # Node ID ae4c2828912ce11fbcb9ad3ae0920b18716a697e
> # Parent  586cb40ea52ab0a628521eb992d1723a467fe8fd
> cli: modify --csv as CLI only option and move csv printing to x265.cpp
>
> diff -r 586cb40ea52a -r ae4c2828912c doc/reST/api.rst
> --- a/doc/reST/api.rst  Wed Jun 10 17:32:11 2015 +0530
> +++ b/doc/reST/api.rst  Wed Jun 10 18:39:36 2015 +0530
> @@ -338,13 +338,8 @@
>  Cleanup
>  =======
>
> -At the end of the encode, the application will want to trigger logging
> -of the final encode statistics, if :option:`--csv` had been specified::
> -
>         /* x265_encoder_log:
> -        *       write a line to the configured CSV file.  If a CSV
> filename was not
> -        *       configured, or file open failed, or the log level
> indicated frame level
> -        *       logging, this function will perform no write. */
> +        *       This function will not generate the log file. It is
> obsolete */
>         void x265_encoder_log(x265_encoder *encoder, int argc, char
> **argv);
>
>  Finally, the encoder must be closed in order to free all of its
> diff -r 586cb40ea52a -r ae4c2828912c doc/reST/cli.rst
> --- a/doc/reST/cli.rst  Wed Jun 10 17:32:11 2015 +0530
> +++ b/doc/reST/cli.rst  Wed Jun 10 18:39:36 2015 +0530
> @@ -52,6 +52,7 @@
>         2. unable to open encoder
>         3. unable to generate stream headers
>         4. encoder abort
> +       5. unable to open csv file
>
> 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.


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

Just like cu-stats, this cannot be removed entirely. Needs a deprecated
message. Will modify this patch and push it in.


>      /*== Internal Picture Specification ==*/
>
>      /* Internal encoder bit depth. If x265 was compiled to use 8bit pixels
> @@ -1262,10 +1270,8 @@
>   *       returns encoder statistics */
>  void x265_encoder_get_stats(x265_encoder *encoder, x265_stats *, uint32_t
> statsSizeBytes);
>
> -/* x265_encoder_log:
> - *       write a line to the configured CSV file.  If a CSV filename was
> not
> - *       configured, or file open failed, or the log level indicated
> frame level
> - *       logging, this function will perform no write. */
> +/* x265_encoder_log:
> + *       This function is obsolete. */
>  void x265_encoder_log(x265_encoder *encoder, int argc, char **argv);
>
>  /* x265_encoder_close:
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20150611/48838aa3/attachment-0001.html>


More information about the x265-devel mailing list