[x265] [PATCH] Fix bug with --abr-ladder
Pavan Tarun Chakka Venkata
pavan.tarun at multicorewareinc.com
Thu Nov 21 10:12:42 UTC 2024
>From 24f9dea36f39856a4642263ec86ccaf757003150 Mon Sep 17 00:00:00 2001
From: Min Chen <chenm003 at 163.com>
Date: Thu, 14 Nov 2024 21:53:51 -0800
Subject: [PATCH] Fix bug with --abr-ladder
---
source/abrEncApp.cpp | 2 ++
source/common/frame.cpp | 2 +-
source/encoder/api.cpp | 2 +-
source/encoder/encoder.cpp | 1 +
source/x265.cpp | 17 +++++++++++------
source/x265cli.cpp | 9 +++------
source/x265cli.h | 5 +++++
7 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp
index 17dcf9045..1907e0bfb 100644
--- a/source/abrEncApp.cpp
+++ b/source/abrEncApp.cpp
@@ -172,6 +172,7 @@ namespace X265_NS {
{
X265_FREE(m_inputPicBuffer[pass][index]->planes[0]);
x265_picture_free(m_inputPicBuffer[pass][index]);
+ X265_FREE(m_analysisBuffer[pass][index].wt);
}
X265_FREE(m_inputPicBuffer[pass]);
@@ -388,6 +389,7 @@ namespace X265_NS {
x265_free_analysis_data(m_param, m_analysisInfo);
memcpy(m_analysisInfo, src, sizeof(x265_analysis_data));
+ m_analysisInfo->wt = NULL;
x265_alloc_analysis_data(m_param, m_analysisInfo);
bool isVbv = m_param->rc.vbvBufferSize &&
m_param->rc.vbvMaxBitrate;
diff --git a/source/common/frame.cpp b/source/common/frame.cpp
index f497979f1..3a98c23d7 100644
--- a/source/common/frame.cpp
+++ b/source/common/frame.cpp
@@ -132,7 +132,7 @@ bool Frame::create(x265_param *param, float*
quantOffsets)
}
}
- if (param->bAnalysisType == AVC_INFO)
+ //if (param->bAnalysisType == AVC_INFO)
{
m_analysisData.wt = NULL;
m_analysisData.intraData = NULL;
diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp
index 3ea67168d..4c70ec3af 100644
--- a/source/encoder/api.cpp
+++ b/source/encoder/api.cpp
@@ -933,7 +933,7 @@ void x265_free_analysis_data(x265_param *param,
x265_analysis_data* analysis)
/* Early exit freeing weights alone if level is 1 (when there is no
analysis inter/intra) */
if (!isMultiPassOpt && analysis->wt && !(param->bAnalysisType ==
AVC_INFO))
- X265_FREE(analysis->wt);
+ X265_FREE_ZERO(analysis->wt);
//Free memory for intraData pointers
if (analysis->intraData)
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 609264067..e85e09d82 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -2361,6 +2361,7 @@ int Encoder::encode(const x265_picture* pic_in,
x265_picture* pic_out)
if (strlen(m_param->analysisSave) &&
!strlen(m_param->analysisLoad))
{
x265_analysis_data* analysis =
&frameEnc[0]->m_analysisData;
+ memset(analysis, 0, sizeof(x265_analysis_data));
analysis->poc = frameEnc[0]->m_poc;
analysis->sliceType = frameEnc[0]->m_lowres.sliceType;
uint32_t widthInCU = (m_param->sourceWidth +
m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;
diff --git a/source/x265.cpp b/source/x265.cpp
index f392d27bf..357f5d6ea 100644
--- a/source/x265.cpp
+++ b/source/x265.cpp
@@ -154,11 +154,13 @@ static bool parseAbrConfig(FILE* abrConfig,
CLIOptions cliopt[], uint8_t numEnco
char line[1024];
char* argLine;
- char **argv = (char**)alloca(256 * sizeof(char *));
- char *strPool = (char*)alloca(256 * X265_MAX_STRING_SIZE *
sizeof(char));
+ char **argv = (char**)malloc(256 * sizeof(char *));
+ char *strPool = (char*)malloc(256 * X265_MAX_STRING_SIZE *
sizeof(char));
int strPoolSize = 256 * X265_MAX_STRING_SIZE;
for (uint32_t i = 0; i < numEncodes; i++)
{
+ cliopt[i].stringPool = (i == 0 ? strPool : NULL);
+ cliopt[i].argString = (i == 0 ? argv : NULL);
if (fgets(line, sizeof(line), abrConfig) == NULL) {
fprintf(stderr, "Error reading line from configuration
file.\n");
return false;
@@ -203,11 +205,12 @@ static bool parseAbrConfig(FILE* abrConfig,
CLIOptions cliopt[], uint8_t numEnco
char* token = strtok(start, " ");
while (token)
{
- argv[argc++] = strPool;
- strPool += strlen(token);
- strPoolSize -= strlen(token);
- strcpy(argv[argc++], token);
+ argv[argc] = strPool;
+ strPool += strlen(token) + 1;
+ strPoolSize -= strlen(token) + 1;
+ strcpy(argv[argc], token);
token = strtok(NULL, " ");
+ argc++;
}
argv[argc] = NULL;
if (cliopt[i].parse(argc++, argv))
@@ -287,6 +290,8 @@ int main(int argc, char **argv)
numEncodes = getNumAbrEncodes(abrConfig);
CLIOptions* cliopt = new CLIOptions[numEncodes];
+ cliopt[0].orgArgv = argv;
+ cliopt[0].argString = argv;
if (isAbrLadder)
{
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index 5bd83a143..f8cdf759a 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -447,12 +447,10 @@ namespace X265_NS {
void CLIOptions::destroy()
{
- if (isAbrLadderConfig)
- {
- for (int idx = 1; idx < argCnt; idx++)
- free(argString[idx]);
+ if(argString && argString != orgArgv)
free(argString);
- }
+ if (stringPool)
+ free(stringPool);
for (int i = 0; i < MAX_VIEWS; i++)
{
@@ -637,7 +635,6 @@ namespace X265_NS {
const char *profile = NULL;
int svtEnabled = 0;
argCnt = argc;
- argString = argv;
if (argc <= 1)
{
diff --git a/source/x265cli.h b/source/x265cli.h
index 86fd14caf..108cc8e2d 100644
--- a/source/x265cli.h
+++ b/source/x265cli.h
@@ -431,7 +431,9 @@ static const struct option long_options[] =
int64_t prevUpdateTime;
int argCnt;
+ char** orgArgv;
char** argString;
+ char *stringPool;
/* ABR ladder settings */
bool isAbrLadderConfig;
@@ -481,6 +483,9 @@ static const struct option long_options[] =
saveLevel = 0;
numRefs = 0;
argCnt = 0;
+ orgArgv = NULL;
+ argString = NULL;
+ stringPool = NULL;
}
void destroy();
--
2.41.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/7689b0f9/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Fix-bug-with-abr-ladder.patch
Type: application/octet-stream
Size: 6359 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/7689b0f9/attachment.obj>
More information about the x265-devel
mailing list