[x265] [PATCH] cli: fill pts if source does not provide one

Xinyue Lu maillist at 7086.in
Tue Mar 31 06:10:30 CEST 2015


# HG changeset patch
# User Xinyue Lu <i at 7086.in>
# Date 1427773157 25200
#      Mon Mar 30 20:39:17 2015 -0700
# Branch Yuuki
# Node ID a877426691da454fdbc9095944d93c89b436a026
# Parent  8f546de630c913b69a00ae154bf32e7a9b1a5db4
cli: fill pts if source does not provide one

Also add variables to x265_param struct to store timebase and vfr flag for future patches.

diff -r 8f546de630c9 -r a877426691da source/common/param.cpp
--- a/source/common/param.cpp	Mon Mar 30 21:11:20 2015 -0500
+++ b/source/common/param.cpp	Mon Mar 30 20:39:17 2015 -0700
@@ -122,6 +122,12 @@
      param->bEmitHRDSEI = 0;
      param->bEmitInfoSEI = 1;

+    param->fpsNum = 0;
+    param->fpsDenom = 0;
+    param->timebaseNum = 0;
+    param->timebaseDenom = 0;
+    param->bVfr = false;
+
      /* CU definitions */
      param->maxCUSize = 64;
      param->minCUSize = 8;
diff -r 8f546de630c9 -r a877426691da source/input/input.h
--- a/source/input/input.h	Mon Mar 30 21:11:20 2015 -0500
+++ b/source/input/input.h	Mon Mar 30 20:39:17 2015 -0700
@@ -48,6 +48,8 @@
      int sarWidth;
      int sarHeight;
      int frameCount;
+    int timebaseNum;
+    int timebaseDenom;

      /* user supplied */
      int skipFrames;
diff -r 8f546de630c9 -r a877426691da source/x265.cpp
--- a/source/x265.cpp	Mon Mar 30 21:11:20 2015 -0500
+++ b/source/x265.cpp	Mon Mar 30 20:39:17 2015 -0700
@@ -353,12 +353,27 @@
      param->sourceHeight = info.height;
      param->internalCsp = info.csp;

-    /* Accept fps and sar from file info if not specified by user */
+    /* Accept fps, timebase and sar from file info if not specified by user */
      if (param->fpsDenom == 0 || param->fpsNum == 0)
      {
          param->fpsDenom = info.fpsDenom;
          param->fpsNum = info.fpsNum;
      }
+    else
+        param->bVfr = false;
+    if (param->timebaseDenom == 0 || param->timebaseNum == 0)
+    {
+        param->timebaseNum = info.timebaseNum;
+        param->timebaseDenom = info.timebaseDenom;
+    }
+    /* Overwrite if we force CFR or source does not provide a timebase */
+    if (param->timebaseDenom == 0 || param->timebaseNum == 0)
+        param->bVfr = false;
+    if (!param->bVfr)
+    {
+        param->timebaseNum = param->fpsDenom;
+        param->timebaseDenom = param->fpsNum;
+    }
      if (!param->vui.aspectRatioIdc && info.sarWidth && info.sarHeight)
          setParamAspectRatio(param, info.sarWidth, info.sarHeight);
      if (this->framesToBeEncoded == 0 && info.frameCount > (int)seek)
@@ -499,8 +514,8 @@

      x265_picture pic_orig, pic_out;
      x265_picture *pic_in = &pic_orig;
-    /* Allocate recon picture if analysisMode is enabled */
-    x265_picture *pic_recon = (cliopt.recon || !!param->analysisMode) ? &pic_out : NULL;
+    /* Always allocate recon picture because we need the pts returned from encoder */
+    x265_picture *pic_recon = &pic_out;
      uint32_t inFrameCount = 0;
      uint32_t outFrameCount = 0;
      x265_nal *p_nal;
@@ -546,6 +561,8 @@
              }
          }

+        pic_in->pts = -1;
+
          if (cliopt.framesToBeEncoded && inFrameCount >= cliopt.framesToBeEncoded)
              pic_in = NULL;
          else if (cliopt.input->readPicture(pic_orig))
@@ -560,6 +577,9 @@
                  ditherImage(*pic_in, param->sourceWidth, param->sourceHeight, errorBuf, X265_DEPTH);
                  pic_in->bitDepth = X265_DEPTH;
              }
+            /* Overwrite if we force CFR or source does not provide a PTS */
+            if (!param->bVfr || pic_in->pts < 0)
+                pic_in->pts = pic_in->poc;
          }

          int numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, pic_in, pic_recon);
diff -r 8f546de630c9 -r a877426691da source/x265.h
--- a/source/x265.h	Mon Mar 30 21:11:20 2015 -0500
+++ b/source/x265.h	Mon Mar 30 20:39:17 2015 -0700
@@ -475,6 +475,13 @@
      uint32_t  fpsNum;
      uint32_t  fpsDenom;

+    /* Numerator and denominator of timebase */
+    uint32_t  timebaseNum;
+    uint32_t  timebaseDenom;
+
+    /* VFR or force-CFR? */
+    bool      bVfr;
+
      /* Width (in pixels) of the source pictures. If this width is not an even
       * multiple of 4, the encoder will pad the pictures internally to meet this
       * minimum requirement. All valid HEVC widths are supported */


More information about the x265-devel mailing list