[x265] [X265][PATCH] Enforce framethreads to 1 for zerolatency tune

Somu Vineela somu at multicorewareinc.com
Fri Jul 25 13:12:59 UTC 2025


>From 28fa59b0b10d3b82aedd0ba7138e93f21883c774 Mon Sep 17 00:00:00 2001
From: somuvineela <somu at multicorewareinc.com>
Date: Tue, 22 Jul 2025 19:18:03 +0530
Subject: [PATCH] Enforce framethreads to 1 for zerolatency tune

FFmpeg overrides frameNumThreads based on avctx->thread_count, so frameNumThreads is forced to one in encoder_open() when zerolatency tune is set.
---
 source/common/param.cpp    | 2 ++
 source/encoder/encoder.cpp | 6 ++++++
 source/x265.h              | 3 +++
 3 files changed, 11 insertions(+)

diff --git a/source/common/param.cpp b/source/common/param.cpp
index a35b06339..598ae21b6 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -641,6 +641,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*
     }
     if (tune)
     {
+        param->tune = tune;
         if (!strcmp(tune, "psnr"))
         {
             param->rc.aqStrength = 0.0;
@@ -2702,6 +2703,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)
     if (strlen(src->numaPools)) snprintf(dst->numaPools, X265_MAX_STRING_SIZE, "%s", src->numaPools);
     else dst->numaPools[0] = 0;

+    dst->tune = src->tune;
     dst->bEnableWavefront = src->bEnableWavefront;
     dst->bDistributeModeAnalysis = src->bDistributeModeAnalysis;
     dst->bDistributeMotionEstimation = src->bDistributeMotionEstimation;
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 2e65cb1a9..5b1efdcbf 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -254,6 +254,12 @@ void Encoder::create()
         p->bEnableWavefront = 0;
     }

+    // For zero-latency tune, frameNumThreads must be set to 1
+    if (p->tune && (!strcmp(p->tune, "zerolatency") || !strcmp(p->tune, "zero-latency")))
+    {
+        p->frameNumThreads = 1;
+    }
+
     bool allowPools = !strlen(p->numaPools) || strcmp(p->numaPools, "none");

     // Trim the thread pool if --wpp, --pme, and --pmode are disabled
diff --git a/source/x265.h b/source/x265.h
index 7241beda2..fcc8337df 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -2344,6 +2344,9 @@ typedef struct x265_param
     /*Frame level RateControl Configuration*/
     int     bConfigRCFrame;
     int    isAbrLadderEnable;
+
+    /*tune*/
+    const char* tune;
 } x265_param;

 /* x265_param_alloc:
--
2.43.0.windows.1


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20250725/db797677/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: enforce_frame_threads_for_zerolatency_tune.diff
Type: application/octet-stream
Size: 2340 bytes
Desc: enforce_frame_threads_for_zerolatency_tune.diff
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20250725/db797677/attachment-0001.obj>


More information about the x265-devel mailing list