[x265] [PATCH] Fix Extra IDR issue in zonefile feature when total number of frames unknown (live).

Karam Singh karam.singh at multicorewareinc.com
Sat Apr 29 10:45:20 UTC 2023


>From 049f6d903d1f7cf400d75c48bdcf0462002f499f Mon Sep 17 00:00:00 2001
From: Karam Singh <karam.singh at multicorewareinc.com>
Date: Thu, 27 Apr 2023 18:15:28 +0530
Subject: [PATCH] Fix Extra IDR issue in zonefile feature when total number
of
 frames unknown (live)

---
 source/common/param.cpp      | 1 +
 source/encoder/slicetype.cpp | 2 ++
 source/x265.h                | 1 +
 source/x265cli.cpp           | 3 +++
 4 files changed, 7 insertions(+)

diff --git a/source/common/param.cpp b/source/common/param.cpp
index e9ca077d7..58ba49793 100644
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -2594,6 +2594,7 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
         for (int i = 0; i < src->rc.zonefileCount; i++)
         {
             dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame;
+            dst->rc.zones[0].keyframeMax = src->rc.zones[0].keyframeMax;
             memcpy(dst->rc.zones[i].zoneParam, src->rc.zones[i].zoneParam,
sizeof(x265_param));
         }
     }
diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp
index 550cc1872..2cfb39620 100644
--- a/source/encoder/slicetype.cpp
+++ b/source/encoder/slicetype.cpp
@@ -1958,6 +1958,8 @@ void Lookahead::slicetypeAnalyse(Lowres **frames,
bool bKeyframe)
             nextZoneStart += (i + 1 < m_param->rc.zonefileCount) ?
m_param->rc.zones[i + 1].startFrame + m_param->rc.zones[i +
1].zoneParam->radl : m_param->totalFrames;
             if (curZoneStart <= frames[0]->frameNum && nextZoneStart >
frames[0]->frameNum)
                 m_param->keyframeMax = nextZoneStart - curZoneStart;
+            if ((i + 1 == m_param->rc.zonefileCount) && nextZoneStart == 0)
+                m_param->keyframeMax = m_param->rc.zones[0].keyframeMax;
         }
     }
     int keylimit = m_param->keyframeMax;
diff --git a/source/x265.h b/source/x265.h
index d621e4394..06f61aa5d 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -711,6 +711,7 @@ struct x265_param;
 typedef struct x265_zone
 {
     int   startFrame, endFrame; /* range of frame numbers */
+    int   keyframeMax;          /* it store the default/user defined
keyframeMax value*/
     int   bForceQp;             /* whether to use qp vs bitrate factor */
     int   qp;
     float bitrateFactor;
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index 120a6706d..8c550550f 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -490,6 +490,9 @@ namespace X265_NS {

         memcpy(globalParam->rc.zones[zonefileCount].zoneParam,
globalParam, sizeof(x265_param));

+        if (zonefileCount == 0)
+            globalParam->rc.zones[zonefileCount].keyframeMax =
globalParam->keyframeMax;
+
         for (optind = 0;;)
         {
             int long_options_index = -1;
-- 
2.36.0.windows.1



Karam Singh
Senior Video Codec Engineer
MulticoreWare, India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20230429/de6b7cf4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Fix_Extra_IDR_issue_in_zonefile_feature_live_case.diff
Type: application/octet-stream
Size: 2793 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20230429/de6b7cf4/attachment.obj>


More information about the x265-devel mailing list