The attached patch against the Mercurial version of x265 attempts to
eliminate a tiny bit of unnecessary string rereading and writing in
the creation of a status message which I suspect is printed once per
video frame (involving ~8 calls to sprintf, I think), in the function
RateControl::writeRateControlFrameStats, which is in the file
x265/source/encoder/ratecontrol.cpp .
I happened to notice it the problem because I have been trying
cppcheck on various source trees, and it complained about some sprintf
calls in that function where the destination was also being passed as
an argument to "%s". I think that practice may be safe because that
"%s" was the very first thing in the string, but once I looked at the
code, I got the itch to eliminate the unnecessary string rewriting and
memset calls.
I ran x265 --multi-pass-opt-rps --pass=1 to convert a video file and
got exactly the same x265_2pass.log file with and without this change.
The log file appeared to include ~4800 lines containing the effected
messages (so, x4 = 38,400 sprintf calls?).
Please note that I am not an x265 developer, and this is my first
attempt at submitting an x265 patch. So, please feel free to let me
know if I should be following a different process. If nobody tells me
to do otherwise and if there are no complaints about this patch on
this mailing list in the next couple of days, I guess I will submit it
to x265Contributions at multicorewareinc.com.
I submit the attached Contribution under the terms of the
MulticoreWre, Inc. x265 Contributor Agreement.
Adam
diff -r 4217e691387c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon May 06 15:54:01 2019 +0530
+++ b/source/encoder/ratecontrol.cpp Sat May 18 05:47:23 2019 -0700
@@ -2854,15 +2854,14 @@
int i, num = rpsWriter->numberOfPictures;
char deltaPOC[128];
char bUsed[40];
- memset(deltaPOC, 0, sizeof(deltaPOC));
- memset(bUsed, 0, sizeof(bUsed));
- sprintf(deltaPOC, "deltapoc:~");
- sprintf(bUsed, "bused:~");
+ char *deltaPOC_end = deltaPOC + sprintf(deltaPOC, "deltapoc:~");
+ char *bUsed_end = bUsed + sprintf(bUsed, "bused:~");
for (i = 0; i < num; i++)
{
- sprintf(deltaPOC, "%s%d~", deltaPOC, rpsWriter->deltaPOC[i]);
- sprintf(bUsed, "%s%d~", bUsed, rpsWriter->bUsed[i]);
+ deltaPOC_end +=
+ sprintf(deltaPOC_end, "%d~", rpsWriter->deltaPOC[i]);
+ bUsed_end += sprintf(bUsed_end, "%d~", rpsWriter->bUsed[i]);
}
if (fprintf(m_statFileOut,
_______________________________________________
x265-devel mailing list
[email protected]
https://mailman.videolan.org/listinfo/x265-devel