[x265] [PATCH] cli: add new option --cra-nal

Mahesh Pittala mahesh at multicorewareinc.com
Mon Jan 22 04:42:50 UTC 2024


>From 011a05a14afa614425c34b18eeabfb4a38851c6c Mon Sep 17 00:00:00 2001
From: Mahesh <mahesh at multicorewareinc.com>
Date: Wed, 17 Jan 2024 12:00:35 +0530
Subject: [PATCH] cli: add new option --cra-nal

Force nal type to CRA to all frames expect for the first frame, works only
with keyint 1
---
 source/CMakeLists.txt      | 2 +-
 source/common/param.cpp    | 3 +++
 source/encoder/dpb.cpp     | 2 +-
 source/encoder/dpb.h       | 2 ++
 source/encoder/encoder.cpp | 6 ++++++
 source/x265.h              | 3 +++
 source/x265cli.cpp         | 1 +
 source/x265cli.h           | 1 +
 8 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 760ef0a19..ab5ddfeb7 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF)
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 208)
+set(X265_BUILD 209)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff --git a/source/common/param.cpp b/source/common/param.cpp
index 1a4df4cdc..e90b08e3b 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -165,6 +165,7 @@ void x265_param_default(x265_param* param)
     param->keyframeMax = 250;
     param->gopLookahead = 0;
     param->bOpenGOP = 1;
+ param->craNal = 0;
     param->bframes = 4;
     param->lookaheadDepth = 20;
     param->bFrameAdaptive = X265_B_ADAPT_TRELLIS;
@@ -1284,6 +1285,7 @@ int x265_param_parse(x265_param* p, const char* name,
const char* value)
         OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion =
atobool(value);
         OPT("aq-motion") p->bAQMotion = atobool(value);
         OPT("dynamic-rd") p->dynamicRd = atof(value);
+ OPT("cra-nal") p->craNal = atobool(value);
         OPT("analysis-reuse-level")
         {
             p->analysisReuseLevel = atoi(value);
@@ -2594,6 +2596,7 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
     dst->decodedPictureHashSEI = src->decodedPictureHashSEI;
     dst->bEnableTemporalSubLayers = src->bEnableTemporalSubLayers;
     dst->bOpenGOP = src->bOpenGOP;
+ dst->craNal = src->craNal;
     dst->keyframeMax = src->keyframeMax;
     dst->keyframeMin = src->keyframeMin;
     dst->bframes = src->bframes;
diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp
index 24d3cd202..52ef91af0 100644
--- a/source/encoder/dpb.cpp
+++ b/source/encoder/dpb.cpp
@@ -489,7 +489,7 @@ NalUnitType DPB::getNalUnitType(int curPOC, bool
bIsKeyFrame)
     if (!curPOC)
         return NAL_UNIT_CODED_SLICE_IDR_N_LP;
     if (bIsKeyFrame)
-        return m_bOpenGOP ? NAL_UNIT_CODED_SLICE_CRA :
m_bhasLeadingPicture ? NAL_UNIT_CODED_SLICE_IDR_W_RADL :
NAL_UNIT_CODED_SLICE_IDR_N_LP;
+        return (m_bOpenGOP || m_craNal) ? NAL_UNIT_CODED_SLICE_CRA :
m_bhasLeadingPicture ? NAL_UNIT_CODED_SLICE_IDR_W_RADL :
NAL_UNIT_CODED_SLICE_IDR_N_LP;
     if (m_pocCRA && curPOC < m_pocCRA)
         // All leading pictures are being marked as TFD pictures here since
         // current encoder uses all reference pictures while encoding
leading
diff --git a/source/encoder/dpb.h b/source/encoder/dpb.h
index 2cc7df778..a9543fc69 100644
--- a/source/encoder/dpb.h
+++ b/source/encoder/dpb.h
@@ -40,6 +40,7 @@ public:
     int                m_lastIDR;
     int                m_pocCRA;
     int                m_bOpenGOP;
+ int                m_craNal;
     int                m_bhasLeadingPicture;
     bool               m_bRefreshPending;
     bool               m_bTemporalSublayer;
@@ -66,6 +67,7 @@ public:
         m_bRefreshPending = false;
         m_frameDataFreeList = NULL;
         m_bOpenGOP = param->bOpenGOP;
+ m_craNal = param->craNal;
         m_bTemporalSublayer = (param->bEnableTemporalSubLayers > 2);
     }

diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 1280ccc66..17bc4046f 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -3662,6 +3662,12 @@ void Encoder::configure(x265_param *p)
     if (!p->rdoqLevel)
         p->psyRdoq = 0;

+    if (p->craNal && p->keyframeMax > 1)
+    {
+        x265_log_file(NULL, X265_LOG_ERROR, " --cra-nal works only with
keyint 1, but given keyint = %s\n", p->keyframeMax);
+        m_aborted = true;
+    }
+
     /* Disable features which are not supported by the current RD level */
     if (p->rdLevel < 3)
     {
diff --git a/source/x265.h b/source/x265.h
index d2bee6e37..4452526ae 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -1260,6 +1260,9 @@ typedef struct x265_param
      * performance impact, but the use case may preclude it.  Default true
*/
     int       bOpenGOP;

+ /*Force nal type to CRA to all frames expect first frame. Default
disabled*/
+ int       craNal;
+
     /* Scene cuts closer together than this are coded as I, not IDR. */
     int       keyframeMin;

diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index cbb3be593..840ab22c1 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -166,6 +166,7 @@ namespace X265_NS {
         H0("   --rdpenalty <0..2>            penalty for 32x32 intra TU in
non-I slices. 0:disabled 1:RD-penalty 2:maximum. Default %d\n",
param->rdPenalty);
         H0("\nSlice decision options:\n");
         H0("   --[no-]open-gop               Enable open-GOP, allows I
slices to be non-IDR. Default %s\n", OPT(param->bOpenGOP));
+ H0("   --cra-nal                     Force nal type to CRA to all frames
expect first frame, works only with keyint 1. Default %s\n",
OPT(param->craNal));
         H0("-I/--keyint <integer>            Max IDR period in frames. -1
for infinite-gop. Default %d\n", param->keyframeMax);
         H0("-i/--min-keyint <integer>        Scenecuts closer together
than this are coded as I, not IDR. Default: auto\n");
         H0("   --gop-lookahead <integer>     Extends gop boundary if a
scenecut is found within this from keyint boundary. Default 0\n");
diff --git a/source/x265cli.h b/source/x265cli.h
index e937f6d77..b5fe327a6 100644
--- a/source/x265cli.h
+++ b/source/x265cli.h
@@ -135,6 +135,7 @@ static const struct option long_options[] =
     { "no-fast-intra",        no_argument, NULL, 0 },
     { "no-open-gop",          no_argument, NULL, 0 },
     { "open-gop",             no_argument, NULL, 0 },
+    { "cra-nal",              no_argument, NULL, 0 },
     { "keyint",         required_argument, NULL, 'I' },
     { "min-keyint",     required_argument, NULL, 'i' },
     { "gop-lookahead",  required_argument, NULL, 0 },
-- 
2.40.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240122/19bb945a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-option-craNal.diff
Type: application/octet-stream
Size: 6775 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240122/19bb945a/attachment.obj>


More information about the x265-devel mailing list