[x265] Fwd: Fix build issues

2018-06-03 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Radhakrishnan 
# Date 1527845200 -19800
#  Fri Jun 01 14:56:40 2018 +0530
# Node ID ef02ddaad3dcc07a7750989b21878f82cd6c2f97
# Parent  9cde2c278464be0db96d41f9605a2dc7a3137165
Fixes cmake error "cannot find x265.pdb" when installing files for static
debug build provided enable_cli is off.

diff -r 9cde2c278464 -r ef02ddaad3dc source/CMakeLists.txt
--- a/source/CMakeLists.txt Wed May 30 20:54:07 2018 +0530
+++ b/source/CMakeLists.txt Fri Jun 01 14:56:40 2018 +0530
@@ -554,7 +554,7 @@
 ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
 endif()
 install(FILES x265.h "${PROJECT_BINARY_DIR}/x265_config.h" DESTINATION
include)
-if(WIN32)
+if((WIN32 AND ENABLE_CLI) OR (WIN32 AND ENABLE_SHARED))
 if(MSVC_IDE)
 install(FILES "${PROJECT_BINARY_DIR}/Debug/x265.pdb" DESTINATION
${BIN_INSTALL_DIR} CONFIGURATIONS Debug)
 install(FILES "${PROJECT_BINARY_DIR}/RelWithDebInfo/x265.pdb"
DESTINATION ${BIN_INSTALL_DIR} CONFIGURATIONS RelWithDebInfo)


fix-install-error-x265.patch
Description: Binary data
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] Clean up SEI::write function

2018-03-22 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1521028474 -19800
#  Wed Mar 14 17:24:34 2018 +0530
# Node ID a65dc9e0ecf2a71abbda117debca8f7cd5d5e8b9
# Parent  b9f5b5d7bf95c2a4dda1cec51fc104f9122f374b
Clean up SEI::write function

define another SEI function to count the payload size and return count in bits.
Set the payload size before calling SEI::write() to avoid clutter of if 
conditions in
write function. Write payloadtype and payload size in bitstream for all SEI in 
same way
as it is the syntax defined in the spec for any SEI.

diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppThu Mar 15 10:52:52 2018 +0530
+++ b/source/encoder/encoder.cppWed Mar 14 17:24:34 2018 +0530
@@ -2332,7 +2332,7 @@
 bs.resetBits();
 SEIuserDataUnregistered idsei;
 idsei.m_userData = (uint8_t*)buffer;
-idsei.setSize((uint32_t)strlen(buffer));
+idsei.setSize((uint32_t)strlen(buffer) + 16);
 idsei.write(bs, m_sps);
 bs.writeByteAlignment();
 list.serialize(NAL_UNIT_PREFIX_SEI, bs);
@@ -2350,7 +2350,8 @@
 SEIActiveParameterSets sei;
 sei.m_selfContainedCvsFlag = true;
 sei.m_noParamSetUpdateFlag = true;
-
+int payloadSize = sei.countPayloadSize(m_sps);
+sei.setSize(payloadSize);
 bs.resetBits();
 sei.write(bs, m_sps);
 bs.writeByteAlignment();
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Thu Mar 15 10:52:52 2018 +0530
+++ b/source/encoder/frameencoder.cpp   Wed Mar 14 17:24:34 2018 +0530
@@ -634,7 +634,8 @@
 
 // hrdFullness() calculates the initial CPB removal delay and 
offset
 m_top->m_rateControl->hrdFullness(bpSei);
-
+int payloadSize = bpSei->countPayloadSize(*slice->m_sps);
+bpSei->setSize(payloadSize);
 m_bs.resetBits();
 bpSei->write(m_bs, *slice->m_sps);
 m_bs.writeByteAlignment();
@@ -651,6 +652,7 @@
 sei.m_recoveryPocCnt = 0;
 sei.m_exactMatchingFlag = true;
 sei.m_brokenLinkFlag = false;
+sei.setSize(sei.countPayloadSize(*slice->m_sps));
 m_bs.resetBits();
 sei.write(m_bs, *slice->m_sps);
 m_bs.writeByteAlignment();
@@ -688,6 +690,8 @@
 }
 
 m_bs.resetBits();
+int payloadSize = sei->countPayloadSize(*slice->m_sps);
+sei->setSize(payloadSize);
 sei->write(m_bs, *slice->m_sps);
 m_bs.writeByteAlignment();
 m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs);
@@ -702,7 +706,7 @@
 SEIuserDataUnregistered sei;
 sei.m_userData = payload->payload;
 m_bs.resetBits();
-sei.setSize(payload->payloadSize);
+sei.setSize(payload->payloadSize + 16);
 sei.write(m_bs, *slice->m_sps);
 m_bs.writeByteAlignment();
 m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs);
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/sei.cpp
--- a/source/encoder/sei.cppThu Mar 15 10:52:52 2018 +0530
+++ b/source/encoder/sei.cppWed Mar 14 17:24:34 2018 +0530
@@ -34,44 +34,33 @@
 0xBB, 0x55, 0xA4, 0xFE, 0x7F, 0xC2, 0xFC, 0x4E
 };
 
+/* count the size of the payload and return the size in bits */
+int SEI::countPayloadSize(const SPS& sps)
+{
+BitCounter counter;
+int count = 0;
+m_bitIf = 
+writeSEI(sps);
+X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload 
unaligned\n");
+count = counter.getNumberOfWrittenBits() >> 3;
+return count;
+}
+
 /* marshal a single SEI message sei, storing the marshalled representation
  * in bitstream bs */
 void SEI::write(Bitstream& bs, const SPS& sps)
 {
 uint32_t type = m_payloadType;
 m_bitIf = 
-BitCounter count;
-bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS || m_payloadType 
== PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD);
-if (hrdTypes)
-{
-m_bitIf = 
-/* virtual writeSEI method, write to bit counter to determine size */
-writeSEI(sps);
-m_bitIf = 
-uint32_t payloadType = m_payloadType;
-for (; payloadType >= 0xff; payloadType -= 0xff)
-WRITE_CODE(0xff, 8, "payload_type");
-}
+uint32_t payloadSize = m_payloadSize;
+uint32_t payloadType = m_payloadType;
+for (; payloadType >= 0xff; payloadType -= 0xff)
+WRITE_CODE(0xff, 8, "payload_type");
 WRITE_CODE(type, 8, "payload_type");
-uint32_t payloadSize;
-if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType 
== USER_DATA_REGISTERED_ITU_T_T35)
-{
-if (hrdTypes)

Re: [x265] [PATCH] Fix payload size for SEIRecoveryPoint

2018-03-16 Thread Aarthi Priya Thirumalai
Yeah but I didn't add it to that flag as this is not a hrd related
parameter. But I will clean up this function and resend the patch.
pls ignore this

Aarthi Priya Thirumalai
Technical Lead, UHDkit
Multicoreware Inc

On Fri, Mar 16, 2018 at 5:35 PM, Ashok Kumar Mishra <
as...@multicorewareinc.com> wrote:

>
>
> On Fri, Mar 16, 2018 at 4:24 PM, <aar...@multicorewareinc.com> wrote:
>
>> # HG changeset patch
>> # User Aarthi Thirumalai <aar...@multicorewareinc.com>
>> # Date 1521028474 -19800
>> #  Wed Mar 14 17:24:34 2018 +0530
>> # Node ID 265d516af978a209bd22a6ae43487cecd01c4503
>> # Parent  d7c26df32fae052b7e895fee9bda1c22b24cc44b
>> Fix payload size for SEIRecoveryPoint
>>
>> diff -r d7c26df32fae -r 265d516af978 source/encoder/sei.cpp
>> --- a/source/encoder/sei.cppTue Mar 13 13:40:13 2018 +0530
>> +++ b/source/encoder/sei.cppWed Mar 14 17:24:34 2018 +0530
>> @@ -41,8 +41,9 @@
>>  uint32_t type = m_payloadType;
>>  m_bitIf = 
>>  BitCounter count;
>> +uint32_t payloadSize = m_payloadSize;
>>  bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS ||
>> m_payloadType == PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD);
>>
>
> I think it is not required to check the condition "m_payloadType ==
> RECOVERY_POINT" in other places
> if you add this in above flag hrdTypes.
>
>
>> -if (hrdTypes)
>> +if (hrdTypes || m_payloadType == RECOVERY_POINT)
>>  {
>>  m_bitIf = 
>>  /* virtual writeSEI method, write to bit counter to determine
>> size */
>> @@ -53,10 +54,10 @@
>>  WRITE_CODE(0xff, 8, "payload_type");
>>  }
>>  WRITE_CODE(type, 8, "payload_type");
>> -uint32_t payloadSize;
>> -if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED ||
>> m_payloadType == USER_DATA_REGISTERED_ITU_T_T35)
>> +if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED ||
>> m_payloadType == USER_DATA_REGISTERED_ITU_T_T35 ||
>> +m_payloadType == RECOVERY_POINT)
>>  {
>> -if (hrdTypes)
>> +if (hrdTypes || m_payloadType == RECOVERY_POINT)
>>  {
>>  X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7),
>> "payload unaligned\n");
>>  payloadSize = count.getNumberOfWrittenBits() >> 3;
>> @@ -65,13 +66,10 @@
>>  payloadSize = m_payloadSize + 16;
>>  else
>>  payloadSize = m_payloadSize;
>> -
>> -for (; payloadSize >= 0xff; payloadSize -= 0xff)
>> -WRITE_CODE(0xff, 8, "payload_size");
>> -WRITE_CODE(payloadSize, 8, "payload_size");
>>  }
>> -else
>> -WRITE_CODE(m_payloadSize, 8, "payload_size");
>> +for (; payloadSize >= 0xff; payloadSize -= 0xff)
>> +WRITE_CODE(0xff, 8, "payload_size");
>> +WRITE_CODE(payloadSize, 8, "payload_size");
>>  /* virtual writeSEI method, write to bs */
>>  writeSEI(sps);
>>  }
>>
>> ___
>> x265-devel mailing list
>> x265-devel@videolan.org
>> https://mailman.videolan.org/listinfo/x265-devel
>>
>>
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] Fix payload size for SEIRecoveryPoint

2018-03-16 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1521028474 -19800
#  Wed Mar 14 17:24:34 2018 +0530
# Node ID 265d516af978a209bd22a6ae43487cecd01c4503
# Parent  d7c26df32fae052b7e895fee9bda1c22b24cc44b
Fix payload size for SEIRecoveryPoint

diff -r d7c26df32fae -r 265d516af978 source/encoder/sei.cpp
--- a/source/encoder/sei.cppTue Mar 13 13:40:13 2018 +0530
+++ b/source/encoder/sei.cppWed Mar 14 17:24:34 2018 +0530
@@ -41,8 +41,9 @@
 uint32_t type = m_payloadType;
 m_bitIf = 
 BitCounter count;
+uint32_t payloadSize = m_payloadSize;
 bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS || m_payloadType 
== PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD);
-if (hrdTypes)
+if (hrdTypes || m_payloadType == RECOVERY_POINT)
 {
 m_bitIf = 
 /* virtual writeSEI method, write to bit counter to determine size */
@@ -53,10 +54,10 @@
 WRITE_CODE(0xff, 8, "payload_type");
 }
 WRITE_CODE(type, 8, "payload_type");
-uint32_t payloadSize;
-if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType 
== USER_DATA_REGISTERED_ITU_T_T35)
+if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType 
== USER_DATA_REGISTERED_ITU_T_T35 ||
+m_payloadType == RECOVERY_POINT)
 {
-if (hrdTypes)
+if (hrdTypes || m_payloadType == RECOVERY_POINT)
 {
 X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload 
unaligned\n");
 payloadSize = count.getNumberOfWrittenBits() >> 3;
@@ -65,13 +66,10 @@
 payloadSize = m_payloadSize + 16;
 else
 payloadSize = m_payloadSize;
-
-for (; payloadSize >= 0xff; payloadSize -= 0xff)
-WRITE_CODE(0xff, 8, "payload_size");
-WRITE_CODE(payloadSize, 8, "payload_size");
 }
-else
-WRITE_CODE(m_payloadSize, 8, "payload_size");
+for (; payloadSize >= 0xff; payloadSize -= 0xff)
+WRITE_CODE(0xff, 8, "payload_size");
+WRITE_CODE(payloadSize, 8, "payload_size");
     /* virtual writeSEI method, write to bs */
 writeSEI(sps);
 }
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1521028474 -19800
#  Wed Mar 14 17:24:34 2018 +0530
# Node ID 265d516af978a209bd22a6ae43487cecd01c4503
# Parent  d7c26df32fae052b7e895fee9bda1c22b24cc44b
Fix payload size for SEIRecoveryPoint

diff -r d7c26df32fae -r 265d516af978 source/encoder/sei.cpp
--- a/source/encoder/sei.cpp	Tue Mar 13 13:40:13 2018 +0530
+++ b/source/encoder/sei.cpp	Wed Mar 14 17:24:34 2018 +0530
@@ -41,8 +41,9 @@
 uint32_t type = m_payloadType;
 m_bitIf = 
 BitCounter count;
+uint32_t payloadSize = m_payloadSize;
 bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS || m_payloadType == PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD);
-if (hrdTypes)
+if (hrdTypes || m_payloadType == RECOVERY_POINT)
 {
 m_bitIf = 
 /* virtual writeSEI method, write to bit counter to determine size */
@@ -53,10 +54,10 @@
 WRITE_CODE(0xff, 8, "payload_type");
 }
 WRITE_CODE(type, 8, "payload_type");
-uint32_t payloadSize;
-if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType == USER_DATA_REGISTERED_ITU_T_T35)
+if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType == USER_DATA_REGISTERED_ITU_T_T35 ||
+m_payloadType == RECOVERY_POINT)
 {
-if (hrdTypes)
+if (hrdTypes || m_payloadType == RECOVERY_POINT)
 {
 X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload unaligned\n");
 payloadSize = count.getNumberOfWrittenBits() >> 3;
@@ -65,13 +66,10 @@
 payloadSize = m_payloadSize + 16;
 else
 payloadSize = m_payloadSize;
-
-for (; payloadSize >= 0xff; payloadSize -= 0xff)
-WRITE_CODE(0xff, 8, "payload_size");
-WRITE_CODE(payloadSize, 8, "payload_size");
 }
-else
-WRITE_CODE(m_payloadSize, 8, "payload_size");
+for (; payloadSize >= 0xff; payloadSize -= 0xff)
+WRITE_CODE(0xff, 8, "payload_size");
+WRITE_CODE(payloadSize, 8, "payload_size");
 /* virtual writeSEI method, write to bs */
 writeSEI(sps);
 }
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] insert SEIRecoveryPoint at IDR frames when --idr-recovery-sei is set

2018-03-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1520503694 -19800
#  Thu Mar 08 15:38:14 2018 +0530
# Node ID b7c8bfabc808a933cf6bdcef63bf49c8177851a6
# Parent  613d9f443769767fb99299a524ad0055f9237ce3
insert SEIRecoveryPoint at IDR frames when --idr-recovery-sei is set

diff -r 613d9f443769 -r b7c8bfabc808 doc/reST/cli.rst
--- a/doc/reST/cli.rst  Mon Mar 05 15:14:34 2018 +0530
+++ b/doc/reST/cli.rst  Thu Mar 08 15:38:14 2018 +0530
@@ -2212,6 +2212,9 @@
 
Only effective at RD levels 5 and 6
 
+.. option:: --idr-recovery-sei, --no-idr-recoveery-sei
+Emit RecoveryPoint info as sei in bitstream for each IDR frame. Default 
disabled.
+
 DCT Approximations
 =
 
diff -r 613d9f443769 -r b7c8bfabc808 source/CMakeLists.txt
--- a/source/CMakeLists.txt Mon Mar 05 15:14:34 2018 +0530
+++ b/source/CMakeLists.txt Thu Mar 08 15:38:14 2018 +0530
@@ -29,7 +29,7 @@
 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 154)
+set(X265_BUILD 155)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 613d9f443769 -r b7c8bfabc808 source/common/param.cpp
--- a/source/common/param.cpp   Mon Mar 05 15:14:34 2018 +0530
+++ b/source/common/param.cpp   Thu Mar 08 15:38:14 2018 +0530
@@ -133,7 +133,7 @@
 param->bEmitHRDSEI = 0;
 param->bEmitInfoSEI = 1;
 param->bEmitHDRSEI = 0;
-
+param->bEmitIDRRecoverySEI = 0;
 /* CU definitions */
 param->maxCUSize = 64;
 param->minCUSize = 8;
@@ -982,6 +982,7 @@
 OPT("limit-sao") p->bLimitSAO = atobool(value);
 OPT("dhdr10-info") p->toneMapFile = strdup(value);
 OPT("dhdr10-opt") p->bDhdr10opt = atobool(value);
+OPT("idr-recovery-sei") p->bEmitIDRRecoverySEI = atobool(value);
 OPT("const-vbv") p->rc.bEnableConstVbv = atobool(value);
 OPT("ctu-info") p->bCTUInfo = atoi(value);
 OPT("scale-factor") p->scaleFactor = atoi(value);
@@ -1730,6 +1731,7 @@
 BOOL(p->bEmitHDRSEI, "hdr");
 BOOL(p->bHDROpt, "hdr-opt");
 BOOL(p->bDhdr10opt, "dhdr10-opt");
+BOOL(p->bEmitIDRRecoverySEI, "idr-recovery-sei");
 if (p->analysisSave)
 s += sprintf(s, " analysis-save");
 if (p->analysisLoad)
diff -r 613d9f443769 -r b7c8bfabc808 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Mar 05 15:14:34 2018 +0530
+++ b/source/encoder/encoder.cppThu Mar 08 15:38:14 2018 +0530
@@ -2268,7 +2268,7 @@
 list.serialize(NAL_UNIT_SPS, bs);
 
 bs.resetBits();
-sbacCoder.codePPS( m_pps, (m_param->maxSlices <= 1), m_iPPSQpMinus26);
+sbacCoder.codePPS(m_pps, (m_param->maxSlices <= 1), m_iPPSQpMinus26);
 bs.writeByteAlignment();
 list.serialize(NAL_UNIT_PPS, bs);
 
@@ -2303,14 +2303,14 @@
 if (opts)
 {
 char *buffer = X265_MALLOC(char, strlen(opts) + 
strlen(PFX(version_str)) +
- strlen(PFX(build_info_str)) + 
200);
+strlen(PFX(build_info_str)) + 200);
 if (buffer)
 {
 sprintf(buffer, "x265 (build %d) - %s:%s - H.265/HEVC codec - "
-"Copyright 2013-2018 (c) Multicoreware, Inc - "
-"http://x265.org - options: %s",
-X265_BUILD, PFX(version_str), PFX(build_info_str), 
opts);
-
+"Copyright 2013-2018 (c) Multicoreware, Inc - "
+"http://x265.org - options: %s",
+X265_BUILD, PFX(version_str), PFX(build_info_str), opts);
+
 bs.resetBits();
 SEIuserDataUnregistered idsei;
 idsei.m_userData = (uint8_t*)buffer;
diff -r 613d9f443769 -r b7c8bfabc808 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Mon Mar 05 15:14:34 2018 +0530
+++ b/source/encoder/frameencoder.cpp   Thu Mar 08 15:38:14 2018 +0530
@@ -594,7 +594,6 @@
 
 /* reset entropy coders and compute slice id */
 m_entropyCoder.load(m_initSliceContext);
-   
 for (uint32_t sliceId = 0; sliceId < m_param->maxSlices; sliceId++)   
 for (uint32_t row = m_sliceBaseRow[sliceId]; row < 
m_sliceBaseRow[sliceId + 1]; row++)
 m_rows[row].init(m_initSliceContext, sliceId);   
@@ -644,6 +643,19 @@
 
 m_top->m_lastBPSEI = m_rce.encodeOrder;
 }
+
+if (m_frame->m_lowres.slic

[x265] [PATCH] api: change signature of x265_csvlog_encode()

2018-01-04 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1515059166 -19800
#  Thu Jan 04 15:16:06 2018 +0530
# Node ID f29e88d85ca29d23c05d3c7d03f0f506a12bc780
# Parent  5f6f6189a239aad91505ee1ed8b1874450779a2a
api: change signature of x265_csvlog_encode()

replace x265_encoder* with x265_param* and int padx, int pady as function 
arguments.

diff -r 5f6f6189a239 -r f29e88d85ca2 source/CMakeLists.txt
--- a/source/CMakeLists.txt Thu Jan 04 13:56:07 2018 +0530
+++ b/source/CMakeLists.txt Thu Jan 04 15:16:06 2018 +0530
@@ -29,7 +29,7 @@
 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 150)
+set(X265_BUILD 151)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 5f6f6189a239 -r f29e88d85ca2 source/encoder/api.cpp
--- a/source/encoder/api.cppThu Jan 04 13:56:07 2018 +0530
+++ b/source/encoder/api.cppThu Jan 04 15:16:06 2018 +0530
@@ -312,7 +312,9 @@
 Encoder *encoder = static_cast<Encoder*>(enc);
 x265_stats stats;
 encoder->fetchStats(, sizeof(stats));
-x265_csvlog_encode(enc, , argc, argv);
+int padx = encoder->m_sps.conformanceWindow.rightOffset;
+int pady = encoder->m_sps.conformanceWindow.bottomOffset;
+x265_csvlog_encode(encoder->m_param, , padx, pady, argc, argv);
 }
 }
 
@@ -868,45 +870,38 @@
 fflush(stderr);
 }
 
-void x265_csvlog_encode(x265_encoder *enc, const x265_stats* stats, int argc, 
char** argv)
+void x265_csvlog_encode(const x265_param *p, const x265_stats *stats, int 
padx, int pady, int argc, char** argv)
 {
-if (enc)
+if (p && p->csvfpt)
 {
-Encoder *encoder = static_cast<Encoder*>(enc);
-int padx = encoder->m_sps.conformanceWindow.rightOffset;
-int pady = encoder->m_sps.conformanceWindow.bottomOffset;
 const x265_api * api = x265_api_get(0);
 
-if (!encoder->m_param->csvfpt)
-return;
-
-if (encoder->m_param->csvLogLevel)
+if (p->csvLogLevel)
 {
 // adding summary to a per-frame csv log file, so it needs a 
summary header
-fprintf(encoder->m_param->csvfpt, "\nSummary\n");
-fputs(summaryCSVHeader, encoder->m_param->csvfpt);
+fprintf(p->csvfpt, "\nSummary\n");
+fputs(summaryCSVHeader, p->csvfpt);
 }
 
 // CLI arguments or other
 if (argc)
 {
-fputc('"', encoder->m_param->csvfpt);
+fputc('"', p->csvfpt);
 for (int i = 1; i < argc; i++)
 {
-fputc(' ', encoder->m_param->csvfpt);
-fputs(argv[i], encoder->m_param->csvfpt);
+fputc(' ', p->csvfpt);
+fputs(argv[i], p->csvfpt);
 }
-fputc('"', encoder->m_param->csvfpt);
+fputc('"', p->csvfpt);
 }
 else
 {
-const x265_param* paramTemp = encoder->m_param;
-char *opts = x265_param2string((x265_param*)paramTemp, padx, pady);
+char *opts = x265_param2string((x265_param*)p, padx, pady);
 if (opts)
 {
-fputc('"', encoder->m_param->csvfpt);
-fputs(opts, encoder->m_param->csvfpt);
-fputc('"', encoder->m_param->csvfpt);
+fputc('"', p->csvfpt);
+fputs(opts, p->csvfpt);
+fputc('"', p->csvfpt);
 }
 }
 
@@ -917,70 +912,71 @@
 timeinfo = localtime();
 char buffer[200];
 strftime(buffer, 128, "%c", timeinfo);
-fprintf(encoder->m_param->csvfpt, ", %s, ", buffer);
+fprintf(p->csvfpt, ", %s, ", buffer);
 
 // elapsed time, fps, bitrate
-fprintf(encoder->m_param->csvfpt, "%.2f, %.2f, %.2f,",
+fprintf(p->csvfpt, "%.2f, %.2f, %.2f,",
 stats->elapsedEncodeTime, stats->encodedPictureCount / 
stats->elapsedEncodeTime, stats->bitrate);
 
-if (encoder->m_param->bEnablePsnr)
-fprintf(encoder->m_param->csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",
+if (p->bEnablePsnr)
+fprintf(p->csvfpt, " %.3lf, %.3lf, %.3lf, %.3lf,",
 stats->globalPsnrY / stats->encodedPictureCount, 
stats->globalPsnrU / stats->encodedPictureCount,
 stats->globalPsnrV / stats->encodedPictur

Re: [x265] [PATCH] encoder: expose BREF slice type in pic_out sliceType

2017-11-20 Thread Aarthi Priya Thirumalai
In finishFrameStats, the pic_out->frameData->sliceType is getting set as
I/P/B. For this, we combine the B/BREF from lowres.sliceType and set it as
'B'
But the pic_out->sliceType is set to lowres.sliceType which is an enum with
5 values.
I can see the lowres.sliceTypes able to differentiate between BREF(4) and
B(5).

Can you pls provide your test cli if you are not able to see this in
lowres.sliceType. Since we use it in other places as well, this can be a
bigger problem if lowres.sliceType
does not indicate BREF.


Aarthi Priya Thirumalai
Technical Lead, UHDkit
Multicoreware Inc

On Mon, Nov 20, 2017 at 9:12 PM, John Stebbins <stebb...@jetheaddev.com>
wrote:

> BREF is not set in lowres.SliceType. Only B slice type is getting set in
> pic_out sliceType.  A similar test is already performed in finishFrameStats
> because lowres.sliceType does not distinguish.
>
> On 11/19/2017 10:15 PM, Aarthi Priya Thirumalai wrote:
>
> I think this change is not necessary since the sliceType in pic_out is
> already set from m_lowres.sliceType.
> So, if the B frame is a B_REF, this is reflected from the lowres.sliceType
> already.
>
> Is there any reason, you are explicitly setting it again?
>
> On Fri, Nov 17, 2017 at 4:41 AM, John Stebbins <stebb...@jetheaddev.com>
> wrote:
>
>> # HG changeset patch
>> # User John Stebbins <jstebbins...@gmail.com>
>> # Date 1510861637 28800
>> #  Thu Nov 16 11:47:17 2017 -0800
>> # Branch stable
>> # Node ID 5b61fc79bfa2d2bf85f8796001d711e5eed1fa1c
>> # Parent  0b3ba15b33eaed5681f639697024525e9460bb31
>> encoder: expose BREF slice type in pic_out sliceType
>>
>> The AppleTV 4K requires accurate frame dependency information in the
>> mp4 sdtp box in order to play 2160p60 content.
>>
>> diff -r 0b3ba15b33ea -r 5b61fc79bfa2 source/encoder/encoder.cpp
>> --- a/source/encoder/encoder.cppTue Sep 05 11:21:24 2017 +0530
>> +++ b/source/encoder/encoder.cppThu Nov 16 11:47:17 2017 -0800
>> @@ -857,6 +857,9 @@
>>  pic_out->pts = outFrame->m_pts;
>>  pic_out->dts = outFrame->m_dts;
>>  pic_out->sliceType = outFrame->m_lowres.sliceType;
>> +if (pic_out->sliceType == X265_TYPE_B &&
>> +IS_REFERENCED(outFrame))
>> +pic_out->sliceType = X265_TYPE_BREF;
>>  pic_out->planes[0] = recpic->m_picOrg[0];
>>  pic_out->stride[0] = (int)(recpic->m_stride *
>> sizeof(pixel));
>>  if (m_param->internalCsp != X265_CSP_I400)
>> ___
>> x265-devel mailing list
>> x265-devel@videolan.org
>> https://mailman.videolan.org/listinfo/x265-devel
>>
>
>
>
> ___
> x265-devel mailing 
> listx265-devel@videolan.orghttps://mailman.videolan.org/listinfo/x265-devel
>
>
> --
> John  GnuPG fingerprint: D0EC B3DB C372 D1F1 0B01  83F0 49F1 D7B2 60D4 
> D0F7
>
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] encoder: expose BREF slice type in pic_out sliceType

2017-11-19 Thread Aarthi Priya Thirumalai
I think this change is not necessary since the sliceType in pic_out is
already set from m_lowres.sliceType.
So, if the B frame is a B_REF, this is reflected from the lowres.sliceType
already.

Is there any reason, you are explicitly setting it again?

On Fri, Nov 17, 2017 at 4:41 AM, John Stebbins 
wrote:

> # HG changeset patch
> # User John Stebbins 
> # Date 1510861637 28800
> #  Thu Nov 16 11:47:17 2017 -0800
> # Branch stable
> # Node ID 5b61fc79bfa2d2bf85f8796001d711e5eed1fa1c
> # Parent  0b3ba15b33eaed5681f639697024525e9460bb31
> encoder: expose BREF slice type in pic_out sliceType
>
> The AppleTV 4K requires accurate frame dependency information in the
> mp4 sdtp box in order to play 2160p60 content.
>
> diff -r 0b3ba15b33ea -r 5b61fc79bfa2 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cppTue Sep 05 11:21:24 2017 +0530
> +++ b/source/encoder/encoder.cppThu Nov 16 11:47:17 2017 -0800
> @@ -857,6 +857,9 @@
>  pic_out->pts = outFrame->m_pts;
>  pic_out->dts = outFrame->m_dts;
>  pic_out->sliceType = outFrame->m_lowres.sliceType;
> +if (pic_out->sliceType == X265_TYPE_B &&
> +IS_REFERENCED(outFrame))
> +pic_out->sliceType = X265_TYPE_BREF;
>  pic_out->planes[0] = recpic->m_picOrg[0];
>  pic_out->stride[0] = (int)(recpic->m_stride *
> sizeof(pixel));
>  if (m_param->internalCsp != X265_CSP_I400)
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] api.cpp: fix warnings in x265_encoder_reconfig

2017-07-23 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1500872870 -19800
#  Mon Jul 24 10:37:50 2017 +0530
# Node ID ab80975559be17eed12f4e90f82390321435f65d
# Parent  01a981f509eaf98461b719dcc9fdd5a9bed05b6e
api.cpp: fix warnings in x265_encoder_reconfig

diff -r 01a981f509ea -r ab80975559be source/encoder/api.cpp
--- a/source/encoder/api.cppThu Jul 13 19:37:37 2017 +0530
+++ b/source/encoder/api.cppMon Jul 24 10:37:50 2017 +0530
@@ -191,7 +191,7 @@
 if (encoder->m_latestParam->forceFlush != param_in->forceFlush)
 return encoder->reconfigureParam(encoder->m_latestParam, param_in);
 bool isReconfigureRc = encoder->isReconfigureRc(encoder->m_latestParam, 
param_in);
-if (encoder->m_reconfigure && !isReconfigureRc || encoder->m_reconfigureRc 
&& isReconfigureRc) /* Reconfigure in progress */
+if ((encoder->m_reconfigure && !isReconfigureRc) || 
(encoder->m_reconfigureRc && isReconfigureRc)) /* Reconfigure in progress */
 return 1;
 memcpy(, encoder->m_latestParam, sizeof(x265_param));
 int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in);
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] Add dynamic rate-control reconfiguration

2017-04-06 Thread Aarthi Priya Thirumalai
On Tue, Apr 4, 2017 at 6:34 PM,  wrote:

> # HG changeset patch
> # User Aruna Matheswaran 
> # Date 1487757265 -19800
> #  Wed Feb 22 15:24:25 2017 +0530
> # Node ID 576ad673d9b352c45853b7ffeeacce7d23268bb8
> # Parent  08a05ca9fd16c9f5efb1ce4d8389bda8a63f5f7d
> Add dynamic rate-control reconfiguration
>
> diff -r 08a05ca9fd16 -r 576ad673d9b3 source/common/frame.cpp
> --- a/source/common/frame.cpp   Mon Mar 27 12:35:20 2017 +0530
> +++ b/source/common/frame.cpp   Wed Feb 22 15:24:25 2017 +0530
> @@ -47,6 +47,7 @@
>  memset(_lowres, 0, sizeof(m_lowres));
>  m_rcData = NULL;
>  m_encodeStartTime = 0;
> +m_reconfigureRc = false;
>  }
>
>  bool Frame::create(x265_param *param, float* quantOffsets)
> diff -r 08a05ca9fd16 -r 576ad673d9b3 source/common/frame.h
> --- a/source/common/frame.h Mon Mar 27 12:35:20 2017 +0530
> +++ b/source/common/frame.h Wed Feb 22 15:24:25 2017 +0530
> @@ -84,6 +84,7 @@
>  Lowres m_lowres;
>  bool   m_lowresInit; // lowres init complete
> (pre-analysis)
>  bool   m_bChromaExtended;// orig chroma planes
> motion extended for weight analysis
> +bool   m_reconfigureRc;
>
>  float* m_quantOffsets;   // points to
> quantOffsets in x265_picture
>  x265_sei   m_userSEI;
> diff -r 08a05ca9fd16 -r 576ad673d9b3 source/encoder/api.cpp
> --- a/source/encoder/api.cppMon Mar 27 12:35:20 2017 +0530
> +++ b/source/encoder/api.cppWed Feb 22 15:24:25 2017 +0530
> @@ -171,7 +171,7 @@
>
>  x265_param save;
>  Encoder* encoder = static_cast(enc);
> -if (encoder->m_reconfigure) /* Reconfigure in progress */
> +if (encoder->m_reconfigure || encoder->m_reconfigureRc) /*
> Reconfigure in progress */
>  return 1;
>  memcpy(, encoder->m_latestParam, sizeof(x265_param));
>  int ret = encoder->reconfigureParam(encoder->m_latestParam,
> param_in);
> @@ -197,7 +197,22 @@
>  return -1;
>  }
>  }
> -encoder->m_reconfigure = true;
> +if (encoder->m_reconfigureRc)
> +{
> +VPS saveVPS;
> +memcpy(, >m_vps.ptl,
> sizeof(saveVPS.ptl));
> +determineLevel(*encoder->m_latestParam, encoder->m_vps);
> +if (saveVPS.ptl.profileIdc != encoder->m_vps.ptl.profileIdc
> || saveVPS.ptl.levelIdc != encoder->m_vps.ptl.levelIdc
> +|| saveVPS.ptl.tierFlag != encoder->m_vps.ptl.tierFlag)
> +{
> +x265_log(encoder->m_param, X265_LOG_WARNING,
> "Profile/Level/Tier has changed from %d/%d/%s to %d/%d/%s.Cannot
> reconfigure rate-control.\n",
> + saveVPS.ptl.profileIdc, saveVPS.ptl.levelIdc,
> saveVPS.ptl.tierFlag ? "High" : "Main", encoder->m_vps.ptl.profileIdc,
> + encoder->m_vps.ptl.levelIdc,
> encoder->m_vps.ptl.tierFlag ? "High" : "Main");
> +encoder->m_reconfigureRc = false;
> +}
> +}
> +else
> +encoder->m_reconfigure = true;
>
why set only m_reconfigure as true,  where are you setting m_reconfigureRc
to true?

>  encoder->printReconfigureParams();
>  }
>  return ret;
> diff -r 08a05ca9fd16 -r 576ad673d9b3 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cppMon Mar 27 12:35:20 2017 +0530
> +++ b/source/encoder/encoder.cppWed Feb 22 15:24:25 2017 +0530
> @@ -56,6 +56,7 @@
>  {
>  m_aborted = false;
>  m_reconfigure = false;
> +m_reconfigureRc = false;
>  m_encodedFrameNum = 0;
>  m_pocLast = -1;
>  m_curEncoder = 0;
> @@ -607,7 +608,7 @@
>  {
>  inFrame = new Frame;
>  inFrame->m_encodeStartTime = x265_mdate();
> -x265_param* p = m_reconfigure ? m_latestParam : m_param;
>
no need for this change - when reconfigureRc is true, m_reconfigure will
also be true..so dont need to change these

> +x265_param* p = (m_reconfigure || m_reconfigureRc) ?
> m_latestParam : m_param;
>  if (inFrame->create(p, pic_in->quantOffsets))
>  {
>  /* the first PicYuv created is asked to generate the CU
> and block unit offset
> @@ -674,7 +675,7 @@
>  inFrame->m_userData  = pic_in->userData;
>  inFrame->m_pts   = pic_in->pts;
>  inFrame->m_forceqp   = pic_in->forceqp;
> -inFrame->m_param = m_reconfigure ? m_latestParam : m_param;
>
same as above. for any reconfigure, set m_reconfigure to true,
additionally, set m_reconfigureRc to true for
Rate control reconfigure changes. no need for the above change then

> +inFrame->m_param = (m_reconfigure || m_reconfigureRc) ?
> m_latestParam : m_param;
>
>  if (pic_in->userSEI.numPayloads)
>  {
> @@ -740,6 +741,8 @@
>  inFrame->m_lowres.bScenecut = !!inFrame->m_analysisData.
> 

[x265] [PATCH] cmake: fix bugs in Cmake to compile M30 in UNIX

2017-03-01 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1488352996 -19800
#  Wed Mar 01 12:53:16 2017 +0530
# Branch hybrid
# Node ID 94a68f3c27e87c70dfea8240522b919824927a69
# Parent  56e3e5f58ae5f7958a4d46423b7a78fe448adf45
cmake: fix bugs in Cmake to compile M30 in UNIX

diff -r 56e3e5f58ae5 -r 94a68f3c27e8 source/CMakeLists.txt
--- a/source/CMakeLists.txt Tue Feb 28 08:04:33 2017 +0530
+++ b/source/CMakeLists.txt Wed Mar 01 12:53:16 2017 +0530
@@ -25,29 +25,49 @@
 source_group(gop-parallel FILES ${GopParallelFiles})
 source_group(cappedvbr FILES ${CappedVbrFiles})
 
-if(GCC)
-include_directories( m30/)
-file(GLOB M30Encoder m30/*.cpp m30/*.h)
-source_group(m30Encoder FILES ${M30Encoder})
-endif(GCC)
+if(UNIX)
+include_directories( m30/)
+file(GLOB M30Encoder m30/*.cpp m30/*.h)
+source_group(m30Encoder FILES ${M30Encoder})
+endif(UNIX)
 
 list(APPEND VFLAGS "-DUHDKIT_VERSION=${UHDKIT_VERSION}")
 string(REPLACE ";" " " VERSION_FLAGS "${VFLAGS}")
 set_source_files_properties(version.cpp PROPERTIES COMPILE_FLAGS 
${VERSION_FLAGS})
-add_library(uhdkit-api OBJECT 
-   ../uhdkit.h uhdkit-encoder.h
-   uhdkit-param.cpp uhdkit-param.h
-   api-uhdkit.cpp 
-version.cpp
-uhdkit-preprocess.cpp uhdkit-preprocess.h
-uhdkit-sharpentext.cpp uhdkit-sharpentext.h
-../uhdkit-extras.cpp ../uhdkit-extras.h
-   uhdkit-scalinglistgenerator.cpp uhdkit-scalinglistgenerator.h
-   ${PCSFiles}
-   ${MultiencoderFiles}
-${GopParallelFiles}
-${CappedVbrFiles}
-   )
+
+if(UNIX)
+add_library(uhdkit-api OBJECT 
+../uhdkit.h uhdkit-encoder.h
+uhdkit-param.cpp uhdkit-param.h
+api-uhdkit.cpp 
+version.cpp
+uhdkit-preprocess.cpp uhdkit-preprocess.h
+uhdkit-sharpentext.cpp uhdkit-sharpentext.h
+../uhdkit-extras.cpp ../uhdkit-extras.h
+uhdkit-scalinglistgenerator.cpp uhdkit-scalinglistgenerator.h
+${PCSFiles}
+${MultiencoderFiles}
+${GopParallelFiles}
+${CappedVbrFiles}
+${M30Encoder}
+)
+else()
+add_library(uhdkit-api OBJECT 
+../uhdkit.h uhdkit-encoder.h
+uhdkit-param.cpp uhdkit-param.h
+api-uhdkit.cpp 
+version.cpp
+uhdkit-preprocess.cpp uhdkit-preprocess.h
+uhdkit-sharpentext.cpp uhdkit-sharpentext.h
+../uhdkit-extras.cpp ../uhdkit-extras.h
+uhdkit-scalinglistgenerator.cpp uhdkit-scalinglistgenerator.h
+${PCSFiles}
+${MultiencoderFiles}
+${GopParallelFiles}
+${CappedVbrFiles}
+)
+endif(UNIX)
+
 if(TEXT_DETECTOR AND UNIX)
 add_definitions(-DTEXT_DETECTOR=1)
 endif()
# HG changeset patch
# User Aarthi Thirumalai
# Date 1488352996 -19800
#  Wed Mar 01 12:53:16 2017 +0530
# Branch hybrid
# Node ID 94a68f3c27e87c70dfea8240522b919824927a69
# Parent  56e3e5f58ae5f7958a4d46423b7a78fe448adf45
cmake: fix bugs in Cmake to compile M30 in UNIX

diff -r 56e3e5f58ae5 -r 94a68f3c27e8 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue Feb 28 08:04:33 2017 +0530
+++ b/source/CMakeLists.txt	Wed Mar 01 12:53:16 2017 +0530
@@ -25,29 +25,49 @@
 source_group(gop-parallel FILES ${GopParallelFiles})
 source_group(cappedvbr FILES ${CappedVbrFiles})
 
-if(GCC)
-include_directories( m30/)
-file(GLOB M30Encoder m30/*.cpp m30/*.h)
-source_group(m30Encoder FILES ${M30Encoder})
-endif(GCC)
+if(UNIX)
+include_directories( m30/)
+file(GLOB M30Encoder m30/*.cpp m30/*.h)
+source_group(m30Encoder FILES ${M30Encoder})
+endif(UNIX)
 
 list(APPEND VFLAGS "-DUHDKIT_VERSION=${UHDKIT_VERSION}")
 string(REPLACE ";" " " VERSION_FLAGS "${VFLAGS}")
 set_source_files_properties(version.cpp PROPERTIES COMPILE_FLAGS ${VERSION_FLAGS})
-add_library(uhdkit-api OBJECT 
-	../uhdkit.h uhdkit-encoder.h
-	uhdkit-param.cpp uhdkit-param.h
-	api-uhdkit.cpp 
-version.cpp
-uhdkit-preprocess.cpp uhdkit-preprocess.h
-uhdkit-sharpentext.cpp uhdkit-sharpentext.h
-../uhdkit-extras.cpp ../uhdkit-extras.h
-	uhdkit-scalinglistgenerator.cpp uhdkit-scalinglistgenerator.h
-	${PCSFiles}
-	${MultiencoderFiles}
-${GopParallelFiles}
-${CappedVbrFiles}
-	)
+
+if(UNIX)
+add_library(uhdkit-api OBJECT 
+../uhdkit.h uhdkit-encoder.h
+uhdkit-param.cpp uhdkit-param.h
+api-uhdkit.cpp 
+version.cpp
+uhdkit-preprocess.cpp uhdkit-preprocess.h
+uhdkit-sharpentext.cpp uhdkit-sharpentext.h
+../uhdkit-extras.cpp ../uhdkit-extras.h
+uhdkit-scalinglistgenerator.cpp uhdkit-scalinglistgenerator.h
+${PCSFiles}
+${MultiencoderFiles}
+${GopParallelFiles}
+${CappedVbrFiles}
+${M30Encoder}
+)
+else()
+add_library(uhdkit-api OBJECT 
+../uhdkit.h uhdkit-encoder.h
+uhdkit-param.cpp uhdkit-param.h
+api-uhdkit.cpp 
+version.cpp
+uhdkit-preprocess.cpp uhdkit-prep

Re: [x265] [PATCH] Set frame as keyint if scalinglist reconfigure

2016-12-20 Thread Aarthi Priya Thirumalai
On Wed, Dec 21, 2016 at 10:15 AM,  wrote:

> # HG changeset patch
> # User Vignesh Vijayakumar 
> # Date 1482232112 -19800
> #  Tue Dec 20 16:38:32 2016 +0530
> # Node ID 97d011cd7fe2b7dc1ecd2cebb887e1536b810052
> # Parent  88285bf550a4f88bb09ff5b49ec46b81140a025d
> Set frame as keyint if scalinglist reconfigure
>
> diff -r 88285bf550a4 -r 97d011cd7fe2 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cppTue Dec 20 16:35:53 2016 +0530
> +++ b/source/encoder/encoder.cppTue Dec 20 16:38:32 2016 +0530
> @@ -78,6 +78,7 @@
>  m_iPPSQpMinus26 = 0;
>  m_iLastSliceQp = 0;
>  m_rpsInSpsCount = 0;
> +m_reconfigureScalingLists = false;
>  for (int i = 0; i < X265_MAX_FRAME_THREADS; i++)
>  m_frameEncoder[i] = NULL;
>
> @@ -842,6 +843,12 @@
>  frameEnc = m_lookahead->getDecidedPicture();
>  if (frameEnc && !pass)
>  {
>
You can't make it a keyframe this way. A keyframe can't be of any
slicetype. It needs to be IDR. You need to change the slicetype as well.
You need to set the m_reconfigureScalingLists to true  while you are
reconfiguring the scaling List inside the x265_encoder_reconfig()
and based on this, you need to set the next incoming frame's slice type to
I/IDR and set it as keyframe during the slicetype analysis of that frame.
It will in turn change the slice types of the following frames accordingly.

Else, reconfigure scaling list only at every keyframe interval - this is
what I would recommend.

+if (m_param->bRepeatHeaders && m_reconfigure && m_latestParam
> != NULL && (m_latestParam->scalingLists != m_param->scalingLists) &&
> !m_reconfigureScalingLists)
> +{
> +frameEnc->m_lowres.bKeyframe = true;
> +m_reconfigureScalingLists = true;
> +}
> +
>  if (curEncoder->m_reconfigure)
>  {
>  /* One round robin cycle of FE reconfigure is complete */
> diff -r 88285bf550a4 -r 97d011cd7fe2 source/encoder/encoder.h
> --- a/source/encoder/encoder.h  Tue Dec 20 16:35:53 2016 +0530
> +++ b/source/encoder/encoder.h  Tue Dec 20 16:38:32 2016 +0530
> @@ -150,6 +150,7 @@
>  bool   m_bZeroLatency; // x265_encoder_encode()
> returns NALs for the input picture, zero lag
>  bool   m_aborted;  // fatal error detected
>  bool   m_reconfigure;  // Encoder reconfigure in
> progress
> +bool   m_reconfigureScalingLists;// Change in
> scalinglists
>
>  /* Begin intra refresh when one not in progress or else begin one as
> soon as the current
>   * one is done. Requires bIntraRefresh to be set.*/
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] Set up separate threadpool for lookahead

2016-12-15 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
# Date 1481274360 -19800
#  Fri Dec 09 14:36:00 2016 +0530
# Node ID e8152da7aa0e03a27f01a2a95aedf914248fe577
# Parent  78e1e1354a25d287f17359ed489833e46bf177f1
Set up separate threadpool for lookahead

The user can allocate specific number of threads for lookahead by specifying 
--lookahead-threads ,
creating a separate lookahead pool for these threads. This will improve 
performance when lookahead
becomes a bottle neck. THe threads for lookahead must be ideally less than half 
the total number
of available worker threads.

diff -r 78e1e1354a25 -r e8152da7aa0e doc/reST/cli.rst
--- a/doc/reST/cli.rst  Fri Dec 09 10:45:12 2016 +0530
+++ b/doc/reST/cli.rst  Fri Dec 09 14:36:00 2016 +0530
@@ -1227,8 +1227,18 @@
 Default: 8 for ultrafast, superfast, faster, fast, medium
  4 for slow, slower
  disabled for veryslow, slower
+
+.. option:: --lookahead-threads 
 
+Use multiple worker threads dedicated to doing only lookahead instead of 
sharing
+the worker threads with frame Encoders. A dedicated lookahead threadpool 
is created with the
+specified number of worker threads. This can range from 0 upto half the
+hardware threads available for encoding. Using too many threads for 
lookahead can starve
+resources for frame Encoder and can harm performance. Default is 0 - 
disabled, Lookahead 
+   shares worker threads with other FrameEncoders . 
 
+**Values:** 0 - disabled(default). Max - Half of available hardware 
threads.
+   
 .. option:: --b-adapt 
 
Set the level of effort in determining B frame placement.
diff -r 78e1e1354a25 -r e8152da7aa0e source/CMakeLists.txt
--- a/source/CMakeLists.txt Fri Dec 09 10:45:12 2016 +0530
+++ b/source/CMakeLists.txt Fri Dec 09 14:36:00 2016 +0530
@@ -28,9 +28,8 @@
 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 102)
+set(X265_BUILD 103)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 78e1e1354a25 -r e8152da7aa0e source/common/param.cpp
--- a/source/common/param.cpp   Fri Dec 09 10:45:12 2016 +0530
+++ b/source/common/param.cpp   Fri Dec 09 14:36:00 2016 +0530
@@ -149,8 +149,8 @@
 param->bBPyramid = 1;
 param->scenecutThreshold = 40; /* Magic number pulled in from x264 */
 param->lookaheadSlices = 8;
+param->lookaheadThreads = 0;
 param->scenecutBias = 5.0;
-
 /* Intra Coding Tools */
 param->bEnableConstrainedIntra = 0;
 param->bEnableStrongIntraSmoothing = 1;
@@ -919,7 +919,7 @@
 OPT("opt-ref-list-length-pps") p->bOptRefListLengthPPS = 
atobool(value);
 OPT("multi-pass-opt-rps") p->bMultiPassOptRPS = atobool(value);
 OPT("scenecut-bias") p->scenecutBias = atof(value);
-
+OPT("lookahead-threads") p->lookaheadThreads = atoi(value);
 else
 return X265_PARAM_BAD_NAME;
 }
@@ -1412,6 +1412,7 @@
 TOOLOPT(param->bEnableFastIntra, "fast-intra");
 TOOLOPT(param->bEnableStrongIntraSmoothing, "strong-intra-smoothing");
 TOOLVAL(param->lookaheadSlices, "lslices=%d");
+TOOLVAL(param->lookaheadThreads, "lthreads=%d")
 if (param->maxSlices > 1)
 TOOLVAL(param->maxSlices, "slices=%d");
 if (param->bEnableLoopFilter)
diff -r 78e1e1354a25 -r e8152da7aa0e source/common/threadpool.cpp
--- a/source/common/threadpool.cpp  Fri Dec 09 10:45:12 2016 +0530
+++ b/source/common/threadpool.cpp  Fri Dec 09 14:36:00 2016 +0530
@@ -244,8 +244,7 @@
 
 return bondCount;
 }
-
-ThreadPool* ThreadPool::allocThreadPools(x265_param* p, int& numPools)
+ThreadPool* ThreadPool::allocThreadPools(x265_param* p, int& numPools, bool 
isThreadsReserved)
 {
 enum { MAX_NODE_NUM = 127 };
 int cpusPerNode[MAX_NODE_NUM + 1];
@@ -397,17 +396,32 @@
 x265_log(p, X265_LOG_DEBUG, "Reducing number of thread pools for frame 
thread count\n");
 numPools = X265_MAX(p->frameNumThreads / 2, 1);
 }
-
+if (isThreadsReserved)
+numPools = 1;
 ThreadPool *pools = new ThreadPool[numPools];
 if (pools)
 {
-int maxProviders = (p->frameNumThreads + numPools - 1) / numPools + 1; 
/* +1 is Lookahead, always assigned to threadpool 0 */
+int maxProviders = (p->frameNumThreads + numPools - 1) / numPools + 
!isThreadsReserved; /* +1 is Lookahead, always assigned to threadpool 0 */
 int node = 0;

[x265] [PATCH] rcStats: add more fields to rcStats

2016-07-11 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
# Date 1468235606 -19800
#  Mon Jul 11 16:43:26 2016 +0530
# Node ID b8c3278330fdd67dc2d3d6ea32ec2b6b8bebe00b
# Parent  a932b4366235ab6597c8d124c1569dade6ff790a
rcStats: add more fields to rcStats

diff -r a932b4366235 -r b8c3278330fd source/common/frame.h
--- a/source/common/frame.h Mon Jul 04 21:25:59 2016 +0530
+++ b/source/common/frame.h Mon Jul 11 16:43:26 2016 +0530
@@ -49,6 +49,9 @@
 double   pCuCount;
 double   skipCuCount;
 double   qScale;
+double   cumulativePQp;
+double   cumulativePNorm;
+double   lastQScaleFor[3];
 int  mvBits;
 int  miscBits;
 int  coeffBits;
diff -r a932b4366235 -r b8c3278330fd source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Jul 04 21:25:59 2016 +0530
+++ b/source/encoder/encoder.cppMon Jul 11 16:43:26 2016 +0530
@@ -777,7 +777,7 @@
 if (m_rateControl->writeRateControlFrameStats(outFrame, 
>m_rce))
 m_aborted = true;
 
-if (pic_out && m_param->rc.bStatWrite)
+if (pic_out)
 {
 /* m_rcData is allocated for every frame */
 pic_out->rcData = outFrame->m_rcData;
diff -r a932b4366235 -r b8c3278330fd source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Jul 04 21:25:59 2016 +0530
+++ b/source/encoder/ratecontrol.cppMon Jul 11 16:43:26 2016 +0530
@@ -1223,6 +1223,10 @@
 /* copy value of lastRceq into thread local rce struct *to be used in 
RateControlEnd() */
 rce->qRceq = m_lastRceq;
 accumPQpUpdate();
+curFrame->m_rcData->cumulativePQp = m_accumPQp;
+curFrame->m_rcData->cumulativePNorm = m_accumPNorm;
+for (int i = 0; i < 3; i++)
+curFrame->m_rcData->lastQScaleFor[i] = m_lastQScaleFor[i];
 }
 else // CQP
 {
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] fix warnings in sao

2016-06-24 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
# Date 1466746115 -19800
#  Fri Jun 24 10:58:35 2016 +0530
# Node ID 9b1ef8bf4ec4cbeb19cbc15b584893310bbed2e2
# Parent  626fcbac7ffba723dabd3a9f0507c4c80f3e7bc9
fix warnings in sao

diff -r 626fcbac7ffb -r 9b1ef8bf4ec4 source/encoder/sao.cpp
--- a/source/encoder/sao.cppThu Jun 16 12:57:38 2016 +0530
+++ b/source/encoder/sao.cppFri Jun 24 10:58:35 2016 +0530
@@ -1398,7 +1398,7 @@
 while (offset != 0)
 {
 // Calculate the bits required for signalling the offset
-int rate = (typeIdx == SAO_BO) ? (abs(offset) + 2) : (abs(offset) + 1);
+uint32_t rate = (typeIdx == SAO_BO) ? (abs(offset) + 2) : (abs(offset) 
+ 1);
 if (abs(offset) == OFFSET_THRESH - 1)
 rate--;
 
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] Birthday off today

2016-06-20 Thread Aarthi Priya Thirumalai
Hi all,

I will be taking the day off on the occasion of my birthday.
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 2] rc: fix tune grain to adapt to scene changes and preserve quality

2016-03-10 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1454673880 -19800
#  Fri Feb 05 17:34:40 2016 +0530
# Node ID 61ab64ab9d8c645134fc2f6ec347f1bedb4ce205
# Parent  d9d9e5f94a995d6939e52d543e0c091838da992f
rc: fix tune grain to adapt to scene changes and preserve quality

diff -r d9d9e5f94a99 -r 61ab64ab9d8c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Mar 04 11:12:38 2016 +0530
+++ b/source/encoder/ratecontrol.cppFri Feb 05 17:34:40 2016 +0530
@@ -297,7 +297,7 @@
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
-#define ABR_INIT_QP_GRAIN_MAX (32)
+#define ABR_INIT_QP_GRAIN_MAX (33)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -378,9 +378,12 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
-m_isGrainEnabled = false;
-if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
-m_isGrainEnabled = true;
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b frame 
sizes
+m_isGrainEnabled = true;
+for (int i = 0; i < 3; i++)
+m_lastQScaleFor[i] = x265_qp2qScale(m_param->rc.rateControlMode == 
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
+m_avgPFrameQp = 0 ;
 
 /* 720p videos seem to be a good cutoff for cplxrSum */
 double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
@@ -1493,17 +1496,17 @@
 
 double RateControl::tuneQScaleForGrain(double rcOverflow)
 {
-double qpstepBy1 = pow(2, 0.5 / 6.0);
+double qpstep = rcOverflow > 1.1 ? rcOverflow : m_lstep;
 double qScaleAvg = x265_qp2qScale(m_avgPFrameQp);
 double  q = m_lastQScaleFor[P_SLICE];
 int curQp = int (x265_qScale2qp(m_lastQScaleFor[P_SLICE]) + 0.5);
 double curBitrate = m_qpToEncodedBits[curQp] * int(m_fps + 0.5);
-int newQp = rcOverflow > 1 ? curQp + 1 : curQp - 1 ;
+int newQp = rcOverflow > 1.1 ? curQp + 2 : rcOverflow > 1 ? curQp + 1 : 
curQp - 1 ;
 double projectedBitrate =  int(m_fps + 0.5) * m_qpToEncodedBits[newQp];
 if (curBitrate > 0 && projectedBitrate > 0)
 q =  abs(projectedBitrate - m_bitrate) < abs (curBitrate - m_bitrate) 
? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
 else
-q = rcOverflow > 1 ? qScaleAvg * qpstepBy1 : rcOverflow < 1 ?  
qScaleAvg / qpstepBy1 : m_lastQScaleFor[P_SLICE];
+q = rcOverflow > 1 ? qScaleAvg * qpstep : rcOverflow < 1 ?  qScaleAvg 
/ qpstep : m_lastQScaleFor[P_SLICE];
 return q;
 }
 
@@ -1651,7 +1654,14 @@
 
 rce->newQScale = qScale;
 if(rce->bLastMiniGopBFrame)
+{
+if (m_isFirstMiniGop && m_isGrainEnabled)
+{
+m_avgPFrameQp = (m_avgPFrameQp + rce->qpNoVbv) / 2;
+m_lastQScaleFor[P_SLICE] = x265_qp2qScale(m_avgPFrameQp);
+}
 m_isFirstMiniGop = false;
+}
 return qScale;
 }
 else
@@ -1751,10 +1761,13 @@
 bool isEncodeEnd = (m_param->totalFrames && 
 m_framesDone > 0.75 * m_param->totalFrames) ? 1 : 0;
 bool isEncodeBeg = m_framesDone < (int)(m_fps + 0.5);
-if(m_isGrainEnabled && m_sliceType!= I_SLICE && !isEncodeEnd &&
-((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+if (m_isGrainEnabled)
 {
-q = tuneQScaleForGrain(overflow);
+if(m_sliceType!= I_SLICE && m_framesDone && !isEncodeEnd &&
+((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+{
+q = tuneQScaleForGrain(overflow);
+}
 }
 }
 if (m_sliceType == I_SLICE && m_param->keyframeMax > 1
@@ -1771,7 +1784,7 @@
 {
 lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
 lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
-if (!m_partialResidualFrames)
+if (!m_partialResidualFrames || m_isGrainEnabled)
 {
 if (overflow > 1.1 && m_framesDone > 3)
 lqmax *= m_lstep;
@@ -1788,18 +1801,9 @@
 else if (m_framesDone == 0 && !m_isVbv && 
m_param->rc.rateControlMode == X265_RC_ABR)
 {
 /* for ABR alone, clip the first I frame qp */
-if (m_isGrainEnabled)
-{
-/* to maintain grain uniformity, set I f

[x265] [PATCH 1 of 2] rc: fix Rate Control for grainy content

2016-03-10 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1457070158 -19800
#  Fri Mar 04 11:12:38 2016 +0530
# Node ID d9d9e5f94a995d6939e52d543e0c091838da992f
# Parent  3bebe9f8aa3c8303c3d65fc0f96ac6a1de754869
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent grain 
loss

diff -r 3bebe9f8aa3c -r d9d9e5f94a99 doc/reST/cli.rst
--- a/doc/reST/cli.rst  Tue Mar 08 18:30:15 2016 +0530
+++ b/doc/reST/cli.rst  Fri Mar 04 11:12:38 2016 +0530
@@ -1416,7 +1416,16 @@
 
The maximum single adjustment in QP allowed to rate control. Default
4
+   
+.. option:: --rc-grain, --no-rc-grain
 
+   Enables a specialised ratecontrol algorithm for film grain content. This 
+   parameter strictly minimises QP fluctuations within and across frames 
+   and removes pulsing of grain. By default, it is disabled. 
+   Turned on when --tune grain is applied. 
+   It is highly recommended that this is used through the tune grain feature
+   where other param options are also tuned to improve the grains.
+   
 .. option:: --qblur 
 
Temporally blur quants. Default 0.5
diff -r 3bebe9f8aa3c -r d9d9e5f94a99 source/CMakeLists.txt
--- a/source/CMakeLists.txt Tue Mar 08 18:30:15 2016 +0530
+++ b/source/CMakeLists.txt Fri Mar 04 11:12:38 2016 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 81)
+set(X265_BUILD 82)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 3bebe9f8aa3c -r d9d9e5f94a99 source/common/param.cpp
--- a/source/common/param.cpp   Tue Mar 08 18:30:15 2016 +0530
+++ b/source/common/param.cpp   Fri Mar 04 11:12:38 2016 +0530
@@ -222,6 +222,7 @@
 param->rc.zones = NULL;
 param->rc.bEnableSlowFirstPass = 0;
 param->rc.bStrictCbr = 0;
+param->rc.bEnableGrain = 0;
 
 /* Video Usability Information (VUI) */
 param->vui.aspectRatioIdc = 0;
@@ -454,16 +455,12 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
+param->rc.bEnableGrain = 1;
 }
 else
 return -1;
@@ -759,6 +756,7 @@
 p->rc.qp = atoi(value);
 p->rc.rateControlMode = X265_RC_CQP;
 }
+OPT("rc-grain") p->rc.bEnableGrain = atobool(value);
 OPT("zones")
 {
 p->rc.zoneCount = 1;
diff -r 3bebe9f8aa3c -r d9d9e5f94a99 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppTue Mar 08 18:30:15 2016 +0530
+++ b/source/encoder/encoder.cppFri Mar 04 11:12:38 2016 +0530
@@ -1773,12 +1773,20 @@
 x265_log(p, X265_LOG_WARNING, "Analysis load/save options incompatible 
with pmode/pme, Disabling pmode/pme\n");
 p->bDistributeMotionEstimation = p->bDistributeModeAnalysis = 0;
 }
+
 if (p->analysisMode && p->rc.cuTree)
 {
 x265_log(p, X265_LOG_WARNING, "Analysis load/save options works only 
with cu-tree off, Disabling cu-tree\n");
 p->rc.cuTree = 0;
 }
 
+if (p->rc.bEnableGrain)
+{
+x265_log(p, X265_LOG_WARNING, "Rc Grain removes qp fluctuations caused 
by aq/cutree, Disabling aq,cu-tree\n");
+p->rc.cuTree = 0;
+p->rc.aqMode = 0;
+}
+
 if (p->bDistributeModeAnalysis && (p->limitReferences >> 1) && 1)
 {
 x265_log(p, X265_LOG_WARNING, "Limit reference options 2 and 3 are not 
supported with pmode. Disabling limit reference\n");
diff -r 3bebe9f8aa3c -r d9d9e5f94a99 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Mar 08 18:30:15 2016 +0530
+++ b/source/encoder/ratecontrol.cppFri Mar 04 11:12:38 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -289,9 +291,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor)

[x265] [PATCH 2 of 2] rc: fix tune grain to adapt to scene changes and preserve quality

2016-03-04 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1454673880 -19800
#  Fri Feb 05 17:34:40 2016 +0530
# Node ID 811fb256d70db1816f4b011fcac387f9b4498c64
# Parent  e31a161a481e1fb97e06efce4af5886e74308298
rc: fix tune grain to adapt to scene changes and preserve quality

diff -r e31a161a481e -r 811fb256d70d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Mar 04 11:12:38 2016 +0530
+++ b/source/encoder/ratecontrol.cppFri Feb 05 17:34:40 2016 +0530
@@ -297,7 +297,7 @@
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
-#define ABR_INIT_QP_GRAIN_MAX (32)
+#define ABR_INIT_QP_GRAIN_MAX (33)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -378,9 +378,12 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
-m_isGrainEnabled = false;
-if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
-m_isGrainEnabled = true;
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b frame 
sizes
+m_isGrainEnabled = true;
+for (int i = 0; i < 3; i++)
+m_lastQScaleFor[i] = x265_qp2qScale(m_param->rc.rateControlMode == 
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
+m_avgPFrameQp = 0 ;
 
 /* 720p videos seem to be a good cutoff for cplxrSum */
 double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
@@ -1493,17 +1496,17 @@
 
 double RateControl::tuneQScaleForGrain(double rcOverflow)
 {
-double qpstepBy1 = pow(2, 0.5 / 6.0);
+double qpstep = rcOverflow > 1.1 ? rcOverflow : m_lstep;
 double qScaleAvg = x265_qp2qScale(m_avgPFrameQp);
 double  q = m_lastQScaleFor[P_SLICE];
 int curQp = int (x265_qScale2qp(m_lastQScaleFor[P_SLICE]) + 0.5);
 double curBitrate = m_qpToEncodedBits[curQp] * int(m_fps + 0.5);
-int newQp = rcOverflow > 1 ? curQp + 1 : curQp - 1 ;
+int newQp = rcOverflow > 1.1 ? curQp + 2 : rcOverflow > 1 ? curQp + 1 : 
curQp - 1 ;
 double projectedBitrate =  int(m_fps + 0.5) * m_qpToEncodedBits[newQp];
 if (curBitrate > 0 && projectedBitrate > 0)
 q =  abs(projectedBitrate - m_bitrate) < abs (curBitrate - m_bitrate) 
? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
 else
-q = rcOverflow > 1 ? qScaleAvg * qpstepBy1 : rcOverflow < 1 ?  
qScaleAvg / qpstepBy1 : m_lastQScaleFor[P_SLICE];
+q = rcOverflow > 1 ? qScaleAvg * qpstep : rcOverflow < 1 ?  qScaleAvg 
/ qpstep : m_lastQScaleFor[P_SLICE];
 return q;
 }
 
@@ -1651,7 +1654,14 @@
 
 rce->newQScale = qScale;
 if(rce->bLastMiniGopBFrame)
+{
+if (m_isFirstMiniGop && m_isGrainEnabled)
+{
+m_avgPFrameQp = (m_avgPFrameQp + rce->qpNoVbv) / 2;
+m_lastQScaleFor[P_SLICE] = x265_qp2qScale(m_avgPFrameQp);
+}
 m_isFirstMiniGop = false;
+}
 return qScale;
 }
 else
@@ -1751,10 +1761,13 @@
 bool isEncodeEnd = (m_param->totalFrames && 
 m_framesDone > 0.75 * m_param->totalFrames) ? 1 : 0;
 bool isEncodeBeg = m_framesDone < (int)(m_fps + 0.5);
-if(m_isGrainEnabled && m_sliceType!= I_SLICE && !isEncodeEnd &&
-((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+if (m_isGrainEnabled)
 {
-q = tuneQScaleForGrain(overflow);
+if(m_sliceType!= I_SLICE && m_framesDone && !isEncodeEnd &&
+((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+{
+q = tuneQScaleForGrain(overflow);
+}
 }
 }
 if (m_sliceType == I_SLICE && m_param->keyframeMax > 1
@@ -1771,7 +1784,7 @@
 {
 lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
 lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
-if (!m_partialResidualFrames)
+if (!m_partialResidualFrames || m_isGrainEnabled)
 {
 if (overflow > 1.1 && m_framesDone > 3)
 lqmax *= m_lstep;
@@ -1788,18 +1801,9 @@
 else if (m_framesDone == 0 && !m_isVbv && 
m_param->rc.rateControlMode == X265_RC_ABR)
 {
 /* for ABR alone, clip the first I frame qp */
-if (m_isGrainEnabled)
-{
-/* to maintain grain uniformity, set I f

[x265] [PATCH 1 of 2] rc: fix Rate Control for grainy content

2016-03-04 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1457070158 -19800
#  Fri Mar 04 11:12:38 2016 +0530
# Node ID e31a161a481e1fb97e06efce4af5886e74308298
# Parent  9cc9920bf82be1b43efd2a3628e28a3a78ab3b2f
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent grain 
loss

diff -r 9cc9920bf82b -r e31a161a481e source/CMakeLists.txt
--- a/source/CMakeLists.txt Wed Mar 02 17:26:11 2016 +0530
+++ b/source/CMakeLists.txt Fri Mar 04 11:12:38 2016 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 81)
+set(X265_BUILD 82)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 9cc9920bf82b -r e31a161a481e source/common/param.cpp
--- a/source/common/param.cpp   Wed Mar 02 17:26:11 2016 +0530
+++ b/source/common/param.cpp   Fri Mar 04 11:12:38 2016 +0530
@@ -222,6 +222,7 @@
 param->rc.zones = NULL;
 param->rc.bEnableSlowFirstPass = 0;
 param->rc.bStrictCbr = 0;
+param->rc.bEnableGrain = 0;
 
 /* Video Usability Information (VUI) */
 param->vui.aspectRatioIdc = 0;
@@ -454,16 +455,12 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
+param->rc.bEnableGrain = 1;
 }
 else
 return -1;
diff -r 9cc9920bf82b -r e31a161a481e source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Mar 02 17:26:11 2016 +0530
+++ b/source/encoder/ratecontrol.cppFri Mar 04 11:12:38 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -289,9 +291,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor);
 
+for (int i = 0; i < QP_MAX_MAX; i++)
+m_qpToEncodedBits[i] = 0;
+
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_INIT_QP_GRAIN_MAX (32)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -362,6 +368,7 @@
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param->totalFrames / 2;
 }
+
 for (int i = 0; i < s_slidingWindowFrames; i++)
 {
 m_satdCostWindow[i] = 0;
@@ -371,15 +378,19 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
+m_isGrainEnabled = true;
+
 /* 720p videos seem to be a good cutoff for cplxrSum */
-double tuneCplxFactor = (m_param->rc.cuTree && m_ncu > 3600) ? 2.5 : 1;
-
+double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
 /* estimated ratio that produces a reasonable QP for the first I-frame */
 m_cplxrSum = .01 * pow(7.0e5, m_qCompress) * pow(m_ncu, 0.5) * 
tuneCplxFactor;
 m_wantedBitsWindow = m_bitrate * m_frameDuration;
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
+
 /* Frame Predictors used in vbv */
 initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite || m_param->rc.bStatRead))
@@ -1069,12 +1080,12 @@
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
 m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+if (m_isGrainEnabled) // when tuned for grain 
 {
 m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.5;
-m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 

[x265] [PATCH 1 of 2] rc: fix Rate Control for grainy content

2016-02-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1452501832 -19800
#  Mon Jan 11 14:13:52 2016 +0530
# Node ID 81d4a8d5428d4bb2f193e4227da75be955a6d465
# Parent  8e093e85b9ab4ae9af0a5240ee06ff1842d70fb1
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent grain 
loss

diff -r 8e093e85b9ab -r 81d4a8d5428d source/CMakeLists.txt
--- a/source/CMakeLists.txt Fri Feb 05 10:50:24 2016 +0530
+++ b/source/CMakeLists.txt Mon Jan 11 14:13:52 2016 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 80)
+set(X265_BUILD 81)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 8e093e85b9ab -r 81d4a8d5428d source/common/param.cpp
--- a/source/common/param.cpp   Fri Feb 05 10:50:24 2016 +0530
+++ b/source/common/param.cpp   Mon Jan 11 14:13:52 2016 +0530
@@ -222,6 +222,7 @@
 param->rc.zones = NULL;
 param->rc.bEnableSlowFirstPass = 0;
 param->rc.bStrictCbr = 0;
+param->rc.bEnableGrain = 0;
 
 /* Video Usability Information (VUI) */
 param->vui.aspectRatioIdc = 0;
@@ -454,16 +455,12 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
+param->rc.bEnableGrain = 1;
 }
 else
 return -1;
diff -r 8e093e85b9ab -r 81d4a8d5428d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Feb 05 10:50:24 2016 +0530
+++ b/source/encoder/ratecontrol.cppMon Jan 11 14:13:52 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -288,9 +290,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor);
 
+for (int i = 0; i < QP_MAX_MAX; i++)
+m_qpToEncodedBits[i] = 0;
+
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_INIT_QP_GRAIN_MAX (32)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -361,6 +367,7 @@
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param->totalFrames / 2;
 }
+
 for (int i = 0; i < s_slidingWindowFrames; i++)
 {
 m_satdCostWindow[i] = 0;
@@ -370,15 +377,19 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
+m_isGrainEnabled = true;
+
 /* 720p videos seem to be a good cutoff for cplxrSum */
-double tuneCplxFactor = (m_param->rc.cuTree && m_ncu > 3600) ? 2.5 : 1;
-
+double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
 /* estimated ratio that produces a reasonable QP for the first I-frame */
 m_cplxrSum = .01 * pow(7.0e5, m_qCompress) * pow(m_ncu, 0.5) * 
tuneCplxFactor;
 m_wantedBitsWindow = m_bitrate * m_frameDuration;
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
+
 /* Frame Predictors used in vbv */
 initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite || m_param->rc.bStatRead))
@@ -1049,12 +1060,12 @@
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
 m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+if (m_isGrainEnabled) // when tuned for grain 
 {
 m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.5;
-m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 

[x265] [PATCH 2 of 2] rc: fix tune grain to adapt to scene changes and preserve quality

2016-02-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1454673880 -19800
#  Fri Feb 05 17:34:40 2016 +0530
# Node ID 6031538bfefb79b56061b97a2ba30334cd207ee4
# Parent  81d4a8d5428d4bb2f193e4227da75be955a6d465
rc: fix tune grain to adapt to scene changes and preserve quality

diff -r 81d4a8d5428d -r 6031538bfefb source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Jan 11 14:13:52 2016 +0530
+++ b/source/encoder/ratecontrol.cppFri Feb 05 17:34:40 2016 +0530
@@ -296,7 +296,7 @@
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
-#define ABR_INIT_QP_GRAIN_MAX (32)
+#define ABR_INIT_QP_GRAIN_MAX (33)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -377,9 +377,12 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
-m_isGrainEnabled = false;
-if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
-m_isGrainEnabled = true;
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b frame 
sizes
+m_isGrainEnabled = true;
+for (int i = 0; i < 3; i++)
+m_lastQScaleFor[i] = x265_qp2qScale(m_param->rc.rateControlMode == 
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
+m_avgPFrameQp = 0 ;
 
 /* 720p videos seem to be a good cutoff for cplxrSum */
 double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
@@ -1472,17 +1475,17 @@
 
 double RateControl::tuneQScaleForGrain(double rcOverflow)
 {
-double qpstepBy1 = pow(2, 0.5 / 6.0);
+double qpstep = rcOverflow > 1.1 ? rcOverflow : m_lstep;
 double qScaleAvg = x265_qp2qScale(m_avgPFrameQp);
 double  q = m_lastQScaleFor[P_SLICE];
 int curQp = int (x265_qScale2qp(m_lastQScaleFor[P_SLICE]) + 0.5);
 double curBitrate = m_qpToEncodedBits[curQp] * int(m_fps + 0.5);
-int newQp = rcOverflow > 1 ? curQp + 1 : curQp - 1 ;
+int newQp = rcOverflow > 1.1 ? curQp + 2 : rcOverflow > 1 ? curQp + 1 : 
curQp - 1 ;
 double projectedBitrate =  int(m_fps + 0.5) * m_qpToEncodedBits[newQp];
 if (curBitrate > 0 && projectedBitrate > 0)
 q =  abs(projectedBitrate - m_bitrate) < abs (curBitrate - m_bitrate) 
? x265_qp2qScale(newQp) : m_lastQScaleFor[P_SLICE];
 else
-q = rcOverflow > 1 ? qScaleAvg * qpstepBy1 : rcOverflow < 1 ?  
qScaleAvg / qpstepBy1 : m_lastQScaleFor[P_SLICE];
+q = rcOverflow > 1 ? qScaleAvg * qpstep : rcOverflow < 1 ?  qScaleAvg 
/ qpstep : m_lastQScaleFor[P_SLICE];
 return q;
 }
 
@@ -1630,7 +1633,14 @@
 
 rce->newQScale = qScale;
 if(rce->bLastMiniGopBFrame)
+{
+if (m_isFirstMiniGop && m_isGrainEnabled)
+{
+m_avgPFrameQp = (m_avgPFrameQp + rce->qpNoVbv) / 2;
+m_lastQScaleFor[P_SLICE] = x265_qp2qScale(m_avgPFrameQp);
+}
 m_isFirstMiniGop = false;
+}
 return qScale;
 }
 else
@@ -1730,10 +1740,13 @@
 bool isEncodeEnd = (m_param->totalFrames && 
 m_framesDone > 0.75 * m_param->totalFrames) ? 1 : 0;
 bool isEncodeBeg = m_framesDone < (int)(m_fps + 0.5);
-if(m_isGrainEnabled && m_sliceType!= I_SLICE && !isEncodeEnd &&
-((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+if (m_isGrainEnabled)
 {
-q = tuneQScaleForGrain(overflow);
+if(m_sliceType!= I_SLICE && m_framesDone && !isEncodeEnd &&
+((overflow < 1.05 && overflow > 0.95) || isEncodeBeg))
+{
+q = tuneQScaleForGrain(overflow);
+}
 }
 }
 if (m_sliceType == I_SLICE && m_param->keyframeMax > 1
@@ -1750,7 +1763,7 @@
 {
 lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
 lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
-if (!m_partialResidualFrames)
+if (!m_partialResidualFrames || m_isGrainEnabled)
 {
 if (overflow > 1.1 && m_framesDone > 3)
 lqmax *= m_lstep;
@@ -1767,18 +1780,9 @@
 else if (m_framesDone == 0 && !m_isVbv && 
m_param->rc.rateControlMode == X265_RC_ABR)
 {
 /* for ABR alone, clip the first I frame qp */
-if (m_isGrainEnabled)
-{
-/* to maintain grain uniformity, set I f

[x265] [PATCH] rc: fix Rate Control for grainy content

2016-01-29 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1452501832 -19800
#  Mon Jan 11 14:13:52 2016 +0530
# Node ID 334a54367f3140512b9cc67ca49c0bb08c8d
# Parent  f548abe8eae8fb75513a85d1b09233e706c7b5ba
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent grain 
loss

diff -r f548abe8eae8 -r 334a5436 source/CMakeLists.txt
--- a/source/CMakeLists.txt Wed Jan 20 18:27:42 2016 +0530
+++ b/source/CMakeLists.txt Mon Jan 11 14:13:52 2016 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 80)
+set(X265_BUILD 81)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r f548abe8eae8 -r 334a5436 source/common/param.cpp
--- a/source/common/param.cpp   Wed Jan 20 18:27:42 2016 +0530
+++ b/source/common/param.cpp   Mon Jan 11 14:13:52 2016 +0530
@@ -222,6 +222,7 @@
 param->rc.zones = NULL;
 param->rc.bEnableSlowFirstPass = 0;
 param->rc.bStrictCbr = 0;
+param->rc.bEnableGrain = 0;
 
 /* Video Usability Information (VUI) */
 param->vui.aspectRatioIdc = 0;
@@ -454,16 +455,12 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
+param->rc.bEnableGrain = 1;
 }
 else
 return -1;
diff -r f548abe8eae8 -r 334a5436 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Jan 20 18:27:42 2016 +0530
+++ b/source/encoder/ratecontrol.cppMon Jan 11 14:13:52 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -288,9 +290,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor);
 
+for (int i = 0; i < QP_MAX_MAX; i++)
+m_qpToEncodedBits[i] = 0;
+
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_INIT_QP_GRAIN_MAX (32)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -361,6 +367,7 @@
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param->totalFrames / 2;
 }
+
 for (int i = 0; i < s_slidingWindowFrames; i++)
 {
 m_satdCostWindow[i] = 0;
@@ -370,15 +377,19 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
+m_isGrainEnabled = true;
+
 /* 720p videos seem to be a good cutoff for cplxrSum */
-double tuneCplxFactor = (m_param->rc.cuTree && m_ncu > 3600) ? 2.5 : 1;
-
+double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
 /* estimated ratio that produces a reasonable QP for the first I-frame */
 m_cplxrSum = .01 * pow(7.0e5, m_qCompress) * pow(m_ncu, 0.5) * 
tuneCplxFactor;
 m_wantedBitsWindow = m_bitrate * m_frameDuration;
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
+
 /* Frame Predictors used in vbv */
 initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite || m_param->rc.bStatRead))
@@ -1049,12 +1060,12 @@
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
 m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+if (m_isGrainEnabled) // when tuned for grain 
 {
 m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.5;
-m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 

[x265] [PATCH] rc: fix Rate Control for grainy content

2016-01-29 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1452501832 -19800
#  Mon Jan 11 14:13:52 2016 +0530
# Node ID 2e414814c585867eda65b8c7ada434f05533d50a
# Parent  f548abe8eae8fb75513a85d1b09233e706c7b5ba
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent grain 
loss

diff -r f548abe8eae8 -r 2e414814c585 source/common/param.cpp
--- a/source/common/param.cpp   Wed Jan 20 18:27:42 2016 +0530
+++ b/source/common/param.cpp   Mon Jan 11 14:13:52 2016 +0530
@@ -222,6 +222,7 @@
 param->rc.zones = NULL;
 param->rc.bEnableSlowFirstPass = 0;
 param->rc.bStrictCbr = 0;
+param->rc.bEnableGrain = 0;
 
 /* Video Usability Information (VUI) */
 param->vui.aspectRatioIdc = 0;
@@ -454,16 +455,12 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
+param->rc.bEnableGrain = 1;
 }
 else
 return -1;
diff -r f548abe8eae8 -r 2e414814c585 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Jan 20 18:27:42 2016 +0530
+++ b/source/encoder/ratecontrol.cppMon Jan 11 14:13:52 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -288,9 +290,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor);
 
+for (int i = 0; i < QP_MAX_MAX; i++)
+m_qpToEncodedBits[i] = 0;
+
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_INIT_QP_GRAIN_MAX (32)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -361,6 +367,7 @@
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param->totalFrames / 2;
 }
+
 for (int i = 0; i < s_slidingWindowFrames; i++)
 {
 m_satdCostWindow[i] = 0;
@@ -370,15 +377,19 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;
 
+m_isGrainEnabled = false;
+if(m_param->rc.bEnableGrain) // tune for grainy content OR equal p-b 
frame sizes
+m_isGrainEnabled = true;
+
 /* 720p videos seem to be a good cutoff for cplxrSum */
-double tuneCplxFactor = (m_param->rc.cuTree && m_ncu > 3600) ? 2.5 : 1;
-
+double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 : 
m_isGrainEnabled ? 1.9 : 1;
 /* estimated ratio that produces a reasonable QP for the first I-frame */
 m_cplxrSum = .01 * pow(7.0e5, m_qCompress) * pow(m_ncu, 0.5) * 
tuneCplxFactor;
 m_wantedBitsWindow = m_bitrate * m_frameDuration;
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
+
 /* Frame Predictors used in vbv */
 initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite || m_param->rc.bStatRead))
@@ -1049,12 +1060,12 @@
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
 m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+if (m_isGrainEnabled) // when tuned for grain 
 {
 m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.5;
-m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
 }
 }
 
@@ -1089,10 +1100,12 @@
 }
 rce->isActive = true;
 bool isRefFrameScenecut = m_sliceType!= I_SLICE && 
m_curSlice->m_refFrameList[0][0]->m_lowres.bScenecut;
+m_isFirstMiniGop = m_sliceType == I_SLICE ? true : m_isFirstMiniGop;
 if (curFrame->m_lowres.bScenecut)
 {
 m_isSceneTransition = true;
 m_lastPredictorReset = rce->encodeOrder;
+
 initFramePredictors();
 }
 else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
@@ -1197,7 +1210,7 @@
 double q = x2

Re: [x265] [PATCH] rc: fix Rate Control for grainy content

2016-01-26 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Thirumalai
# Date 1452501832 -19800
#  Mon Jan 11 14:13:52 2016 +0530
# Node ID cee55e38a09310c1c3384ee72e548bd72a00a4e7
# Parent  f548abe8eae8fb75513a85d1b09233e706c7b5ba
rc: fix Rate Control for grainy content

optimize params for tune grain, reduce frequent qp fluctions to prevent
grain loss

diff -r f548abe8eae8 -r cee55e38a093 source/common/param.cpp
--- a/source/common/param.cpp Wed Jan 20 18:27:42 2016 +0530
+++ b/source/common/param.cpp Mon Jan 11 14:13:52 2016 +0530
@@ -454,16 +454,11 @@
 }
 else if (!strcmp(tune, "grain"))
 {
-param->deblockingFilterBetaOffset = -2;
-param->deblockingFilterTCOffset = -2;
-param->bIntraInBFrames = 0;
-param->rdoqLevel = 2;
-param->psyRdoq = 10.0;
-param->psyRd = 0.5;
 param->rc.ipFactor = 1.1;
-param->rc.pbFactor = 1.1;
-param->rc.aqStrength = 0.3;
-param->rc.qCompress = 0.8;
+param->rc.pbFactor = 1.0;
+param->rc.cuTree = 0;
+param->rc.aqMode = 0;
+param->rc.qpStep = 1.0;
 }
 else
 return -1;
diff -r f548abe8eae8 -r cee55e38a093 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Wed Jan 20 18:27:42 2016 +0530
+++ b/source/encoder/ratecontrol.cpp Mon Jan 11 14:13:52 2016 +0530
@@ -190,6 +190,8 @@
 m_numEntries = 0;
 m_isSceneTransition = false;
 m_lastPredictorReset = 0;
+m_avgPFrameQp = 0;
+m_isFirstMiniGop = false;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -288,9 +290,13 @@
 m_ipOffset = 6.0 * X265_LOG2(m_param->rc.ipFactor);
 m_pbOffset = 6.0 * X265_LOG2(m_param->rc.pbFactor);

+for (int i = 0; i < QP_MAX_MAX; i++)
+m_qpToEncodedBits[i] = 0;
+
 /* Adjust the first frame in order to stabilize the quality level
compared to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_INIT_QP_GRAIN_MAX (32)
 #define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param->rc.rfConstant
 for (int i = 0; i < 3; i++)
@@ -361,6 +367,7 @@
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param->totalFrames / 2;
 }
+
 for (int i = 0; i < s_slidingWindowFrames; i++)
 {
 m_satdCostWindow[i] = 0;
@@ -370,15 +377,19 @@
 m_isPatternPresent = false;
 m_numBframesInPattern = 0;

+m_isGrainEnabled = false;
+if(m_param->rc.pbFactor <= 1.1 && !m_param->rc.cuTree) // tune for
grainy content OR equal p-b frame sizes
+m_isGrainEnabled = true;
+
 /* 720p videos seem to be a good cutoff for cplxrSum */
-double tuneCplxFactor = (m_param->rc.cuTree && m_ncu > 3600) ? 2.5 : 1;
-
+double tuneCplxFactor = (m_ncu > 3600 && m_param->rc.cuTree) ? 2.5 :
m_isGrainEnabled ? 1.9 : 1;
 /* estimated ratio that produces a reasonable QP for the first I-frame
*/
 m_cplxrSum = .01 * pow(7.0e5, m_qCompress) * pow(m_ncu, 0.5) *
tuneCplxFactor;
 m_wantedBitsWindow = m_bitrate * m_frameDuration;
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP
: ABR_INIT_QP_MIN) * m_accumPNorm;

+
 /* Frame Predictors used in vbv */
 initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite ||
m_param->rc.bStatRead))
@@ -1049,12 +1060,12 @@
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
 m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain
+if (m_isGrainEnabled) // when tuned for grain
 {
 m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.5;
-m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
 }
 }

@@ -1089,10 +1100,12 @@
 }
 rce->isActive = true;
 bool isRefFrameScenecut = m_sliceType!= I_SLICE &&
m_curSlice->m_refFrameList[0][0]->m_lowres.bScenecut;
+m_isFirstMiniGop = m_sliceType == I_SLICE ? true : m_isFirstMiniGop;
 if (curFrame->m_lowres.bScenecut)
 {
 m_isSceneTransition = true;
 m_lastPredictorReset = rce->encodeOrder;
+
 initFramePredictors();
 }
 else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
@@ -1197,7 +1210,7 @@
 double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
 q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
 m_qp = int(q + 0.5);
-rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = q;
+rce->qpaRc = curEncData.m_avgQpRc = curEnc

[x265] [PATCH] rc: fix rate factor values recorded in csv

2015-12-11 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
# Date 1449763621 -19800
#  Thu Dec 10 21:37:01 2015 +0530
# Node ID c401ace41d5d8d2eef8f82d625465de7f9b47b0e
# Parent  d72c79721e88cbd6e471d50351b46111918871ba
rc: fix rate factor values recorded in csv

diff -r d72c79721e88 -r c401ace41d5d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppThu Dec 10 10:07:17 2015 +0530
+++ b/source/encoder/ratecontrol.cppThu Dec 10 21:37:01 2015 +0530
@@ -144,6 +144,7 @@
 rce->sliceType = rce2Pass->sliceType;
 rce->qpNoVbv = rce2Pass->qpNoVbv;
 rce->newQp = rce2Pass->newQp;
+rce->qRceq = rce2Pass->qRceq;
 }
 }  // end anonymous namespace
 /* Returns the zone for the current frame */
@@ -517,7 +518,7 @@
 char picType;
 int e;
 char *next;
-double qpRc, qpAq, qNoVbv;
+double qpRc, qpAq, qNoVbv, qRceq;
 next = strstr(p, ";");
 if (next)
 *next++ = 0;
@@ -529,8 +530,8 @@
 }
 rce = _rce2Pass[encodeOrder];
 m_encOrder[frameNumber] = encodeOrder;
-e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
-   , , , , >coeffBits,
+e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf q-Rceq:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
+   , , , , , 
>coeffBits,
>mvBits, >miscBits, >iCuCount, 
>pCuCount,
>skipCuCount);
 rce->keptAsRef = true;
@@ -554,6 +555,7 @@
 rce->qpNoVbv = qNoVbv;
 rce->qpaRc = qpRc;
 rce->qpAq = qpAq;
+rce->qRceq = qRceq;
 p = next;
 }
 X265_FREE(statsBuf);
@@ -1142,6 +1144,7 @@
 }
 if (!m_isAbr && m_2pass && m_param->rc.rateControlMode == X265_RC_CRF)
 {
+rce->qpPrev = x265_qScale2qp(rce->qScale);
 rce->qScale = rce->newQScale;
 rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = 
x265_qScale2qp(rce->newQScale);
 m_qp = int(rce->qpaRc + 0.5);
@@ -2347,20 +2350,31 @@
 {
 if (m_param->rc.rateControlMode == X265_RC_ABR && 
!m_param->rc.bStatRead)
 checkAndResetABR(rce, true);
-
-if (m_param->rc.rateControlMode == X265_RC_CRF)
+}
+if (m_param->rc.rateControlMode == X265_RC_CRF)
+{
+double crfVal, qpRef = curEncData.m_avgQpRc;
+bool is2passCrfChange = false;
+if (m_2pass)
 {
-if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
-curEncData.m_rateFactor = m_rateFactorConstant;
-else
+if (abs(curEncData.m_avgQpRc - rce->qpPrev) > 0.1)
 {
-/* If vbv changed the frame QP recalculate the rate-factor */
-double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
-double mbtree_offset = m_param->rc.cuTree ? (1.0 - 
m_param->rc.qCompress) * 13.5 : 0;
-curEncData.m_rateFactor = pow(baseCplx, 1 - m_qCompress) /
-x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) + 
mbtree_offset);
+qpRef = rce->qpPrev;
+is2passCrfChange = true;
 }
 }
+if (is2passCrfChange || abs(qpRef - rce->qpNoVbv) > 0.5)
+{
+double crfFactor = rce->qRceq /x265_qp2qScale(qpRef);
+double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
+double mbtree_offset = m_param->rc.cuTree ? (1.0 - 
m_param->rc.qCompress) * 13.5 : 0;
+crfVal = x265_qScale2qp(pow(baseCplx, 1 - m_qCompress) / 
crfFactor) - mbtree_offset;
+}
+else
+crfVal = rce->sliceType == I_SLICE ? m_param->rc.rfConstant - 
m_ipOffset : 
+(rce->sliceType == B_SLICE ? m_param->rc.rfConstant + m_pbOffset : 
m_param->rc.rfConstant);
+
+curEncData.m_rateFactor = crfVal;
 }
 
 if (m_isAbr && !m_isAbrReset)
@@ -2454,10 +2468,10 @@
 : rce->sliceType == P_SLICE ? 'P'
 : IS_REFERENCED(curFrame) ? 'B' : 'b';
 if (fprintf(m_statFileOut,
-"in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f tex:%d 
mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
+"in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f 
q-Rceq:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
 rce->poc, rce->encodeOrder,
 cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
-rce->qpNoVbv,
+  

Re: [x265] [PATCH] rc: fix rate factor values recorded in csv

2015-12-11 Thread Aarthi Priya Thirumalai
pls ignore.. sending revised patch for this

On Thu, Dec 10, 2015 at 10:48 PM, Aarthi Priya Thirumalai <
aar...@multicorewareinc.com> wrote:

> # HG changeset patch
> # User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
> # Date 1449763621 -19800
> #  Thu Dec 10 21:37:01 2015 +0530
> # Node ID 721d60a7988b85083f72832b58e5e98f42d5a678
> # Parent  33d04da2f68830ac51151cfbda8f38fb9a7e8bb9
> rc: fix rate factor values recorded in csv
>
> diff -r 33d04da2f688 -r 721d60a7988b source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cppWed Dec 09 22:24:25 2015 +0530
> +++ b/source/encoder/ratecontrol.cppThu Dec 10 21:37:01 2015 +0530
> @@ -142,6 +142,7 @@
>  rce->expectedVbv = rce2Pass->expectedVbv;
>  rce->blurredComplexity = rce2Pass->blurredComplexity;
>  rce->sliceType = rce2Pass->sliceType;
> +rce->qRceq = rce2Pass->qRceq;
>  }
>
>  }  // end anonymous namespace
> @@ -509,7 +510,7 @@
>  char picType;
>  int e;
>  char *next;
> -double qpRc, qpAq, qNoVbv;
> +double qpRc, qpAq, qNoVbv, qRceq;
>  next = strstr(p, ";");
>  if (next)
>  *next++ = 0;
> @@ -520,8 +521,8 @@
>  return false;
>  }
>  rce = _rce2Pass[frameNumber];
> -e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf
> q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
> -   , , , , >coeffBits,
> +e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf
> q-noVbv:%lf q-Rceq:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
> +   , , , , ,
> >coeffBits,
> >mvBits, >miscBits, >iCuCount,
> >pCuCount,
> >skipCuCount);
>  rce->keptAsRef = true;
> @@ -545,6 +546,7 @@
>  rce->qpNoVbv = qNoVbv;
>  rce->qpaRc = qpRc;
>  rce->qpAq = qpAq;
> +rce->qRceq = qRceq;
>  p = next;
>  }
>  X265_FREE(statsBuf);
> @@ -2239,20 +2241,32 @@
>  {
>  if (m_param->rc.rateControlMode == X265_RC_ABR &&
> !m_param->rc.bStatRead)
>  checkAndResetABR(rce, true);
> +}
> +if (m_param->rc.rateControlMode == X265_RC_CRF)
> +{
> +double crfVal;
> +if (m_2pass || abs(curEncData.m_avgQpRc - rce->qpNoVbv) > 0.5)
> +{
> +double qpRef = curEncData.m_avgQpRc;
> +if (m_2pass)
> +{
> +double qpPrev = x265_qScale2qp(rce->qScale);
> +qpRef = abs(curEncData.m_avgQpRc - qpPrev) > 0.1 ?
> curEncData.m_avgQpRc : qpPrev;
> +}
> +double crfFactor = rce->qRceq /x265_qp2qScale(qpRef);
> +if(rce->sliceType == I_SLICE)
> +crfFactor /= m_param->rc.ipFactor;
> +else if (rce->sliceType == B_SLICE)
> +crfFactor *= m_param->rc.pbFactor;
> +double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
> +double mbtree_offset = m_param->rc.cuTree ? (1.0 -
> m_param->rc.qCompress) * 13.5 : 0;
> +crfVal = x265_qScale2qp(pow(baseCplx, 1 - m_qCompress) /
> crfFactor) - mbtree_offset;
> +}
> +else
> +crfVal = rce->sliceType == I_SLICE ? m_param->rc.rfConstant -
> m_ipOffset :
> +(rce->sliceType == B_SLICE ? m_param->rc.rfConstant +
> m_pbOffset : m_param->rc.rfConstant);
>
> -if (m_param->rc.rateControlMode == X265_RC_CRF)
> -{
> -if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
> -curEncData.m_rateFactor = m_rateFactorConstant;
> -else
> -{
> -/* If vbv changed the frame QP recalculate the
> rate-factor */
> -double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
> -double mbtree_offset = m_param->rc.cuTree ? (1.0 -
> m_param->rc.qCompress) * 13.5 : 0;
> -curEncData.m_rateFactor = pow(baseCplx, 1 - m_qCompress) /
> -x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) +
> mbtree_offset);
> -}
> -}
> +curEncData.m_rateFactor = crfVal;
>  }
>
>  if (m_isAbr && !m_isAbrReset)
> @@ -2346,10 +2360,10 @@
>  : rce->sliceType == P_SLICE ? 'P'
>  : IS_REFE

Re: [x265] [PATCH] rc: fix rate factor values recorded in csv

2015-12-11 Thread Aarthi Priya Thirumalai
CRF is right now printed as a RateFactor value that is used internally in
the calculation of Rate Control, that is  not in the same scale as the user
inputs. We are changing the crf printed in teh csv to reflect the scale of
(0-51) -> what the user selects in the cli.

In case of VBV changing the qp from whatever is decided for the given CRF,
we recompute the CRF corresponding to the updated qp at the end and print
it out. Similarly, for 2 pass when qp is changed from 1st pass, we
recompute the CRF and print it out in the csv.



On Fri, Dec 11, 2015 at 8:25 PM, Deepthi Nandakumar <
deep...@multicorewareinc.com> wrote:

> Thanks Aarthi. Can you quickly jog my memory on what we discussed about
> CRF calculations?
>
> On Fri, Dec 11, 2015 at 8:17 PM, Aarthi Priya Thirumalai <
> aar...@multicorewareinc.com> wrote:
>
>> # HG changeset patch
>> # User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
>> # Date 1449763621 -19800
>> #  Thu Dec 10 21:37:01 2015 +0530
>> # Node ID c401ace41d5d8d2eef8f82d625465de7f9b47b0e
>> # Parent  d72c79721e88cbd6e471d50351b46111918871ba
>> rc: fix rate factor values recorded in csv
>>
>> diff -r d72c79721e88 -r c401ace41d5d source/encoder/ratecontrol.cpp
>> --- a/source/encoder/ratecontrol.cppThu Dec 10 10:07:17 2015 +0530
>> +++ b/source/encoder/ratecontrol.cppThu Dec 10 21:37:01 2015 +0530
>> @@ -144,6 +144,7 @@
>>  rce->sliceType = rce2Pass->sliceType;
>>  rce->qpNoVbv = rce2Pass->qpNoVbv;
>>  rce->newQp = rce2Pass->newQp;
>> +rce->qRceq = rce2Pass->qRceq;
>>  }
>>  }  // end anonymous namespace
>>  /* Returns the zone for the current frame */
>> @@ -517,7 +518,7 @@
>>  char picType;
>>  int e;
>>  char *next;
>> -double qpRc, qpAq, qNoVbv;
>> +double qpRc, qpAq, qNoVbv, qRceq;
>>  next = strstr(p, ";");
>>  if (next)
>>  *next++ = 0;
>> @@ -529,8 +530,8 @@
>>  }
>>  rce = _rce2Pass[encodeOrder];
>>  m_encOrder[frameNumber] = encodeOrder;
>> -e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf
>> q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
>> -   , , , , >coeffBits,
>> +e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf
>> q-noVbv:%lf q-Rceq:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
>> +   , , , , ,
>> >coeffBits,
>> >mvBits, >miscBits, >iCuCount,
>> >pCuCount,
>> >skipCuCount);
>>  rce->keptAsRef = true;
>> @@ -554,6 +555,7 @@
>>  rce->qpNoVbv = qNoVbv;
>>  rce->qpaRc = qpRc;
>>  rce->qpAq = qpAq;
>> +rce->qRceq = qRceq;
>>  p = next;
>>  }
>>  X265_FREE(statsBuf);
>> @@ -1142,6 +1144,7 @@
>>  }
>>  if (!m_isAbr && m_2pass && m_param->rc.rateControlMode ==
>> X265_RC_CRF)
>>  {
>> +rce->qpPrev = x265_qScale2qp(rce->qScale);
>>  rce->qScale = rce->newQScale;
>>  rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq =
>> x265_qScale2qp(rce->newQScale);
>>  m_qp = int(rce->qpaRc + 0.5);
>> @@ -2347,20 +2350,31 @@
>>  {
>>  if (m_param->rc.rateControlMode == X265_RC_ABR &&
>> !m_param->rc.bStatRead)
>>  checkAndResetABR(rce, true);
>> -
>> -if (m_param->rc.rateControlMode == X265_RC_CRF)
>> +}
>> +if (m_param->rc.rateControlMode == X265_RC_CRF)
>> +{
>> +double crfVal, qpRef = curEncData.m_avgQpRc;
>> +bool is2passCrfChange = false;
>> +if (m_2pass)
>>  {
>> -if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
>> -curEncData.m_rateFactor = m_rateFactorConstant;
>> -else
>> +if (abs(curEncData.m_avgQpRc - rce->qpPrev) > 0.1)
>>  {
>> -/* If vbv changed the frame QP recalculate the
>> rate-factor */
>> -double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
>> -double mbtree_offset = m_param->rc.cuTree ? (1.0 -
>> m_param->rc.qCompress) * 13.5 : 0;
>>

[x265] [PATCH] rc: fix rate factor values recorded in csv

2015-12-10 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Priya Thirumalai <aar...@multicorewareinc.com>
# Date 1449763621 -19800
#  Thu Dec 10 21:37:01 2015 +0530
# Node ID 721d60a7988b85083f72832b58e5e98f42d5a678
# Parent  33d04da2f68830ac51151cfbda8f38fb9a7e8bb9
rc: fix rate factor values recorded in csv

diff -r 33d04da2f688 -r 721d60a7988b source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Dec 09 22:24:25 2015 +0530
+++ b/source/encoder/ratecontrol.cppThu Dec 10 21:37:01 2015 +0530
@@ -142,6 +142,7 @@
 rce->expectedVbv = rce2Pass->expectedVbv;
 rce->blurredComplexity = rce2Pass->blurredComplexity;
 rce->sliceType = rce2Pass->sliceType;
+rce->qRceq = rce2Pass->qRceq;
 }
 
 }  // end anonymous namespace
@@ -509,7 +510,7 @@
 char picType;
 int e;
 char *next;
-double qpRc, qpAq, qNoVbv;
+double qpRc, qpAq, qNoVbv, qRceq;
 next = strstr(p, ";");
 if (next)
 *next++ = 0;
@@ -520,8 +521,8 @@
 return false;
 }
 rce = _rce2Pass[frameNumber];
-e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
-   , , , , >coeffBits,
+e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf q-Rceq:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
+   , , , , , 
>coeffBits,
>mvBits, >miscBits, >iCuCount, 
>pCuCount,
>skipCuCount);
 rce->keptAsRef = true;
@@ -545,6 +546,7 @@
 rce->qpNoVbv = qNoVbv;
 rce->qpaRc = qpRc;
 rce->qpAq = qpAq;
+rce->qRceq = qRceq;
 p = next;
 }
 X265_FREE(statsBuf);
@@ -2239,20 +2241,32 @@
 {
 if (m_param->rc.rateControlMode == X265_RC_ABR && 
!m_param->rc.bStatRead)
 checkAndResetABR(rce, true);
+}
+if (m_param->rc.rateControlMode == X265_RC_CRF)
+{
+double crfVal;
+if (m_2pass || abs(curEncData.m_avgQpRc - rce->qpNoVbv) > 0.5)
+{
+double qpRef = curEncData.m_avgQpRc;
+if (m_2pass)
+{
+double qpPrev = x265_qScale2qp(rce->qScale);
+qpRef = abs(curEncData.m_avgQpRc - qpPrev) > 0.1 ? 
curEncData.m_avgQpRc : qpPrev;
+}
+double crfFactor = rce->qRceq /x265_qp2qScale(qpRef);
+if(rce->sliceType == I_SLICE)
+crfFactor /= m_param->rc.ipFactor;
+else if (rce->sliceType == B_SLICE)
+crfFactor *= m_param->rc.pbFactor;
+double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
+double mbtree_offset = m_param->rc.cuTree ? (1.0 - 
m_param->rc.qCompress) * 13.5 : 0;
+crfVal = x265_qScale2qp(pow(baseCplx, 1 - m_qCompress) / 
crfFactor) - mbtree_offset;
+}
+else
+crfVal = rce->sliceType == I_SLICE ? m_param->rc.rfConstant - 
m_ipOffset : 
+(rce->sliceType == B_SLICE ? m_param->rc.rfConstant + m_pbOffset : 
m_param->rc.rfConstant);
 
-if (m_param->rc.rateControlMode == X265_RC_CRF)
-{
-if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
-curEncData.m_rateFactor = m_rateFactorConstant;
-else
-{
-/* If vbv changed the frame QP recalculate the rate-factor */
-double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
-double mbtree_offset = m_param->rc.cuTree ? (1.0 - 
m_param->rc.qCompress) * 13.5 : 0;
-curEncData.m_rateFactor = pow(baseCplx, 1 - m_qCompress) /
-x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) + 
mbtree_offset);
-}
-}
+curEncData.m_rateFactor = crfVal;
 }
 
 if (m_isAbr && !m_isAbrReset)
@@ -2346,10 +2360,10 @@
 : rce->sliceType == P_SLICE ? 'P'
 : IS_REFERENCED(curFrame) ? 'B' : 'b';
 if (fprintf(m_statFileOut,
-"in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f tex:%d 
mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
+"in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f 
q-Rceq:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
 rce->poc, rce->encodeOrder,
 cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
-rce->qpNoVbv,
+rce->qpNoVbv, rce->qRceq,
 curFrame->m_encData->m_frameStats.coeffBits,
 curFrame->m_encData->m_frameStats.mvBits,
 curFrame->m_encData->m_frameStats.miscBits,
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] rc: record RF details in csv for 2 pass CRF

2015-11-25 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1448384595 -19800
#  Tue Nov 24 22:33:15 2015 +0530
# Node ID 7b84524dc44236071ba33f5858a6c38a909162d2
# Parent  e90c2d74de88459dd18837765a310a462d9679ec
rc: record RF details in csv for 2 pass CRF

diff -r e90c2d74de88 -r 7b84524dc442 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Nov 23 12:26:45 2015 +0530
+++ b/source/encoder/ratecontrol.cpp Tue Nov 24 22:33:15 2015 +0530
@@ -2239,10 +2239,11 @@
 {
 if (m_param->rc.rateControlMode == X265_RC_ABR &&
!m_param->rc.bStatRead)
 checkAndResetABR(rce, true);
+}

-if (m_param->rc.rateControlMode == X265_RC_CRF)
+ if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
-if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
+if (curEncData.m_avgQpRc - rce->qpNoVbv < 1)
 curEncData.m_rateFactor = m_rateFactorConstant;
 else
 {
@@ -2253,7 +2254,6 @@
 x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) +
mbtree_offset);
 }
 }
-}

 if (m_isAbr && !m_isAbrReset)
 {


On Wed, Nov 25, 2015 at 12:33 PM, Deepthi Nandakumar <
deep...@multicorewareinc.com> wrote:

> can you resend this patch, conflicts with your earlier one.
>
> On Tue, Nov 24, 2015 at 11:47 PM, <aar...@multicorewareinc.com> wrote:
>
>> # HG changeset patch
>> # User Aarthi Thirumalai <aar...@multicorewareinc.com>
>> # Date 1448384595 -19800
>> #  Tue Nov 24 22:33:15 2015 +0530
>> # Branch stable
>> # Node ID d17f491e06152f4627152a36169c272651bd5e3d
>> # Parent  0c49c9cc75e4c1ef9534a28b49b97b9107636f5d
>> rc: record RF details in csv for 2 pass CRF
>>
>> diff -r 0c49c9cc75e4 -r d17f491e0615 source/encoder/ratecontrol.cpp
>> --- a/source/encoder/ratecontrol.cppMon Nov 23 14:06:10 2015 +0530
>> +++ b/source/encoder/ratecontrol.cppTue Nov 24 22:33:15 2015 +0530
>> @@ -1141,6 +1141,7 @@
>>  }
>>  if (!m_isAbr && m_2pass && m_param->rc.rateControlMode ==
>> X265_RC_CRF)
>>  {
>> +rce->oldQScale = rce->qScale;
>>  rce->qScale = rce->newQScale;
>>  rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq =
>> x265_qScale2qp(rce->newQScale);
>>  m_qp = int(rce->qpaRc + 0.5);
>> @@ -1704,6 +1705,7 @@
>>  bool isFrameAfterScenecut = m_sliceType!= I_SLICE &&
>> m_curSlice->m_refPicList[0][0]->m_lowres.bScenecut;
>>  if (!m_2pass && m_isVbv && isFrameAfterScenecut)
>>  q = x265_clip3(lqmin, lqmax, q);
>> +rce->qScale = q;
>>  }
>>  m_lastQScaleFor[m_sliceType] = q;
>>  if ((m_curSlice->m_poc == 0 || m_lastQScaleFor[P_SLICE] < q) &&
>> !(m_2pass && !m_isVbv))
>> @@ -2337,10 +2339,12 @@
>>  {
>>  if (m_param->rc.rateControlMode == X265_RC_ABR &&
>> !m_param->rc.bStatRead)
>>  checkAndResetABR(rce, true);
>> +}
>>
>> -if (m_param->rc.rateControlMode == X265_RC_CRF)
>> + if (m_param->rc.rateControlMode == X265_RC_CRF)
>>  {
>> -if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
>> +if ((int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp &&
>> !m_2pass) ||
>> +(rce->oldQScale == rce->qScale))
>>  curEncData.m_rateFactor = m_rateFactorConstant;
>>  else
>>  {
>> @@ -2351,7 +2355,6 @@
>>  x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) +
>> mbtree_offset);
>>  }
>>  }
>> -}
>>
>>  if (m_isAbr && !m_isAbrReset)
>>  {
>> diff -r 0c49c9cc75e4 -r d17f491e0615 source/encoder/ratecontrol.h
>> --- a/source/encoder/ratecontrol.h  Mon Nov 23 14:06:10 2015 +0530
>> +++ b/source/encoder/ratecontrol.h  Tue Nov 24 22:33:15 2015 +0530
>> @@ -101,6 +101,7 @@
>>  double   qScale;
>>  double   newQScale;
>>  double   newQp;
>> +double   oldQScale;
>>  int  mvBits;
>>  int  miscBits;
>>  int  coeffBits;
>> ___
>> x265-devel mailing list
>> x265-devel@videolan.org
>> https://mailman.videolan.org/listinfo/x265-devel
>>
>
>
>
> --
> Deepthi Nandakumar
> Engineering Manager, x265
> Multicoreware, Inc
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: record RF details in csv for 2 pass CRF

2015-11-24 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai <aar...@multicorewareinc.com>
# Date 1448384595 -19800
#  Tue Nov 24 22:33:15 2015 +0530
# Branch stable
# Node ID d17f491e06152f4627152a36169c272651bd5e3d
# Parent  0c49c9cc75e4c1ef9534a28b49b97b9107636f5d
rc: record RF details in csv for 2 pass CRF

diff -r 0c49c9cc75e4 -r d17f491e0615 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Nov 23 14:06:10 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Nov 24 22:33:15 2015 +0530
@@ -1141,6 +1141,7 @@
 }
 if (!m_isAbr && m_2pass && m_param->rc.rateControlMode == X265_RC_CRF)
 {
+rce->oldQScale = rce->qScale;
 rce->qScale = rce->newQScale;
 rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = 
x265_qScale2qp(rce->newQScale);
 m_qp = int(rce->qpaRc + 0.5);
@@ -1704,6 +1705,7 @@
 bool isFrameAfterScenecut = m_sliceType!= I_SLICE && 
m_curSlice->m_refPicList[0][0]->m_lowres.bScenecut;
 if (!m_2pass && m_isVbv && isFrameAfterScenecut)
 q = x265_clip3(lqmin, lqmax, q);
+rce->qScale = q;
 }
 m_lastQScaleFor[m_sliceType] = q;
 if ((m_curSlice->m_poc == 0 || m_lastQScaleFor[P_SLICE] < q) && 
!(m_2pass && !m_isVbv))
@@ -2337,10 +2339,12 @@
 {
 if (m_param->rc.rateControlMode == X265_RC_ABR && 
!m_param->rc.bStatRead)
 checkAndResetABR(rce, true);
+}
 
-if (m_param->rc.rateControlMode == X265_RC_CRF)
+ if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
-if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
+if ((int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp && 
!m_2pass) ||
+(rce->oldQScale == rce->qScale))
 curEncData.m_rateFactor = m_rateFactorConstant;
 else
 {
@@ -2351,7 +2355,6 @@
 x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) + 
mbtree_offset);
 }
 }
-}
 
 if (m_isAbr && !m_isAbrReset)
 {
diff -r 0c49c9cc75e4 -r d17f491e0615 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Mon Nov 23 14:06:10 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Nov 24 22:33:15 2015 +0530
@@ -101,6 +101,7 @@
 double   qScale;
 double   newQScale;
 double   newQp;
+double   oldQScale;
 int  mvBits;
 int  miscBits;
 int  coeffBits;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: record RF details in csv for 2 pass CRF

2015-11-24 Thread aarthi
# HG changeset patch
# User Divya Manivannan 
# Date 1448384595 -19800
#  Tue Nov 24 22:33:15 2015 +0530
# Branch stable
# Node ID 08156f38d64e054b7f4a12c8eb9577b50dec1c33
# Parent  0c49c9cc75e4c1ef9534a28b49b97b9107636f5d
rc: record RF details in csv for 2 pass CRF

diff -r 0c49c9cc75e4 -r 08156f38d64e source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Nov 23 14:06:10 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Nov 24 22:33:15 2015 +0530
@@ -1141,6 +1141,7 @@
 }
 if (!m_isAbr && m_2pass && m_param->rc.rateControlMode == X265_RC_CRF)
 {
+rce->oldQScale = rce->qScale;
 rce->qScale = rce->newQScale;
 rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = 
x265_qScale2qp(rce->newQScale);
 m_qp = int(rce->qpaRc + 0.5);
@@ -2337,10 +2338,12 @@
 {
 if (m_param->rc.rateControlMode == X265_RC_ABR && 
!m_param->rc.bStatRead)
 checkAndResetABR(rce, true);
+}
 
-if (m_param->rc.rateControlMode == X265_RC_CRF)
+ if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
-if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)
+if ((int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp && 
!m_2pass) ||
+(rce->oldQScale == rce->qScale))
 curEncData.m_rateFactor = m_rateFactorConstant;
 else
 {
@@ -2351,7 +2354,6 @@
 x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) + 
mbtree_offset);
 }
 }
-}
 
 if (m_isAbr && !m_isAbrReset)
 {
diff -r 0c49c9cc75e4 -r 08156f38d64e source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Mon Nov 23 14:06:10 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Nov 24 22:33:15 2015 +0530
@@ -101,6 +101,7 @@
 double   qScale;
 double   newQScale;
 double   newQp;
+double   oldQScale;
 int  mvBits;
 int  miscBits;
 int  coeffBits;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 2 of 2] rc: implement 2 pass CRF, when vbv is enabled

2015-11-23 Thread Aarthi Priya Thirumalai
pls ignore the previous patch. It has a few bugs while merging.
here is the fixed one :


# HG changeset patch
# User Divya Manivannan 
# Date 1448267770 -19800
#  Mon Nov 23 14:06:10 2015 +0530
# Branch stable
# Node ID 0c49c9cc75e4c1ef9534a28b49b97b9107636f5d
# Parent  6b308775b6f065ea5002a76a40aa6f5d81e8ee50
rc: implement 2 pass CRF, when vbv is enabled.

Allow CRF with VBV in 2nd pass to increase the quality of capped CRF in the
first pass.

diff -r 6b308775b6f0 -r 0c49c9cc75e4 source/common/param.cpp
--- a/source/common/param.cpp Mon Nov 23 12:26:45 2015 +0530
+++ b/source/common/param.cpp Mon Nov 23 14:06:10 2015 +0530
@@ -1170,7 +1170,7 @@
 CHECK(0 > param->noiseReductionIntra || param->noiseReductionIntra
> 2000, "Valid noise reduction range 0 - 2000");
 if (param->noiseReductionInter)
 CHECK(0 > param->noiseReductionInter || param->noiseReductionInter
> 2000, "Valid noise reduction range 0 - 2000");
-CHECK(param->rc.rateControlMode == X265_RC_CRF && param->rc.bStatRead,
+CHECK(param->rc.rateControlMode == X265_RC_CRF && param->rc.bStatRead
&& param->rc.vbvMaxBitrate == 0,
   "Constant rate-factor is incompatible with 2pass");
 CHECK(param->rc.rateControlMode == X265_RC_CQP && param->rc.bStatRead,
   "Constant QP is incompatible with 2pass");
diff -r 6b308775b6f0 -r 0c49c9cc75e4 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Nov 23 12:26:45 2015 +0530
+++ b/source/encoder/ratecontrol.cpp Mon Nov 23 14:06:10 2015 +0530
@@ -142,6 +142,8 @@
 rce->expectedVbv = rce2Pass->expectedVbv;
 rce->blurredComplexity = rce2Pass->blurredComplexity;
 rce->sliceType = rce2Pass->sliceType;
+rce->qpNoVbv = rce2Pass->qpNoVbv;
+rce->newQp = rce2Pass->newQp;
 }

 }  // end anonymous namespace
@@ -205,7 +207,7 @@
 m_rateFactorMaxDecrement = m_param->rc.rfConstant -
m_param->rc.rfConstantMin;
 }
 m_isAbr = m_param->rc.rateControlMode != X265_RC_CQP &&
!m_param->rc.bStatRead;
-m_2pass = m_param->rc.rateControlMode == X265_RC_ABR &&
m_param->rc.bStatRead;
+m_2pass = (m_param->rc.rateControlMode == X265_RC_ABR ||
m_param->rc.vbvMaxBitrate > 0) && m_param->rc.bStatRead;
 m_bitrate = m_param->rc.bitrate * 1000;
 m_frameDuration = (double)m_param->fpsDenom / m_param->fpsNum;
 m_qp = m_param->rc.qp;
@@ -488,6 +490,12 @@
  x265_log(m_param, X265_LOG_ERROR, "Rce Entries for 2 pass
cannot be allocated\n");
  return false;
 }
+m_encOrder = X265_MALLOC(int, m_numEntries);
+if (!m_encOrder)
+{
+x265_log(m_param, X265_LOG_ERROR, "Encode order for 2 pass
cannot be allocated\n");
+return false;
+}
 /* init all to skipped p frames */
 for (int i = 0; i < m_numEntries; i++)
 {
@@ -504,6 +512,7 @@
 {
 RateControlEntry *rce;
 int frameNumber;
+int encodeOrder;
 char picType;
 int e;
 char *next;
@@ -511,13 +520,14 @@
 next = strstr(p, ";");
 if (next)
 *next++ = 0;
-e = sscanf(p, " in:%d ", );
+e = sscanf(p, " in:%d out:%d", , );
 if (frameNumber < 0 || frameNumber >= m_numEntries)
 {
 x265_log(m_param, X265_LOG_ERROR, "bad frame number
(%d) at stats line %d\n", frameNumber, i);
 return false;
 }
-rce = _rce2Pass[frameNumber];
+rce = _rce2Pass[encodeOrder];
+m_encOrder[frameNumber] = encodeOrder;
 e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf
q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
, , , , >coeffBits,
>mvBits, >miscBits, >iCuCount,
>pCuCount,
@@ -538,7 +548,7 @@
 x265_log(m_param, X265_LOG_ERROR, "statistics are
damaged at line %d, parser out=%d\n", i, e);
 return false;
 }
-rce->qScale = x265_qp2qScale(qpRc);
+rce->qScale = rce->newQScale = x265_qp2qScale(qpRc);
 totalQpAq += qpAq;
 rce->qpNoVbv = qNoVbv;
 rce->qpaRc = qpRc;
@@ -546,8 +556,7 @@
 p = next;
 }
 X265_FREE(statsBuf);
-
-if (m_param->rc.rateControlMode == X265_RC_ABR)
+if (m_param->rc.rateControlMode == X265_RC_ABR ||
m_param->rc.vbvMaxBitrate > 0)
 {
 if (!initPass2())
 return false;
@@ -630,11 +639,8 @@

 #undef MAX_DURATION
 }
-
-bool RateControl::initPass2()
+bool RateControl::analyseABR2Pass(int startIndex, int endIndex, uint64_t
allAvailableBits)
 {
-uint64_t allConstBits = 0;
-uint64_t 

[x265] [PATCH 1 of 2] rc: record one more field in 1st pass stats

2015-11-23 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1448261805 -19800
#  Mon Nov 23 12:26:45 2015 +0530
# Branch stable
# Node ID 6b308775b6f065ea5002a76a40aa6f5d81e8ee50
# Parent  1f0d4dee7e3b3c34dd6b8c3305c61fa79b03b9ce
rc: record one more field in 1st pass stats

diff -r 1f0d4dee7e3b -r 6b308775b6f0 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Oct 12 15:51:23 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Nov 23 12:26:45 2015 +0530
@@ -507,7 +507,7 @@
 char picType;
 int e;
 char *next;
-double qpRc, qpAq;
+double qpRc, qpAq, qNoVbv;
 next = strstr(p, ";");
 if (next)
 *next++ = 0;
@@ -518,8 +518,8 @@
 return false;
 }
 rce = _rce2Pass[frameNumber];
-e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf tex:%d 
mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
-   , , , >coeffBits,
+e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
+   , , , , >coeffBits,
>mvBits, >miscBits, >iCuCount, 
>pCuCount,
>skipCuCount);
 rce->keptAsRef = true;
@@ -540,6 +540,9 @@
 }
 rce->qScale = x265_qp2qScale(qpRc);
 totalQpAq += qpAq;
+rce->qpNoVbv = qNoVbv;
+rce->qpaRc = qpRc;
+rce->qpAq = qpAq;
 p = next;
 }
 X265_FREE(statsBuf);
@@ -2325,9 +2328,10 @@
 : rce->sliceType == P_SLICE ? 'P'
 : IS_REFERENCED(curFrame) ? 'B' : 'b';
 if (fprintf(m_statFileOut,
-"in:%d out:%d type:%c q:%.2f q-aq:%.2f tex:%d mv:%d misc:%d 
icu:%.2f pcu:%.2f scu:%.2f ;\n",
+"in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f tex:%d 
mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
 rce->poc, rce->encodeOrder,
 cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
+rce->qpNoVbv,
 curFrame->m_encData->m_frameStats.coeffBits,
 curFrame->m_encData->m_frameStats.mvBits,
 curFrame->m_encData->m_frameStats.miscBits,
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 2] rc: implement 2 pass CRF, when vbv is enabled

2015-11-23 Thread aarthi
# HG changeset patch
# User Divya Manivannan 
# Date 1448267770 -19800
#  Mon Nov 23 14:06:10 2015 +0530
# Branch stable
# Node ID ffb0111298cdfcf6fe77d143089144c23b644b2d
# Parent  6b308775b6f065ea5002a76a40aa6f5d81e8ee50
rc: implement 2 pass CRF, when vbv is enabled.

Allow CRF with VBV in 2nd pass to increase the quality of capped CRF in the 
first pass.

diff -r 6b308775b6f0 -r ffb0111298cd source/common/param.cpp
--- a/source/common/param.cpp   Mon Nov 23 12:26:45 2015 +0530
+++ b/source/common/param.cpp   Mon Nov 23 14:06:10 2015 +0530
@@ -1170,7 +1170,7 @@
 CHECK(0 > param->noiseReductionIntra || param->noiseReductionIntra > 
2000, "Valid noise reduction range 0 - 2000");
 if (param->noiseReductionInter)
 CHECK(0 > param->noiseReductionInter || param->noiseReductionInter > 
2000, "Valid noise reduction range 0 - 2000");
-CHECK(param->rc.rateControlMode == X265_RC_CRF && param->rc.bStatRead,
+CHECK(param->rc.rateControlMode == X265_RC_CRF && param->rc.bStatRead && 
param->rc.vbvMaxBitrate == 0,
   "Constant rate-factor is incompatible with 2pass");
 CHECK(param->rc.rateControlMode == X265_RC_CQP && param->rc.bStatRead,
   "Constant QP is incompatible with 2pass");
diff -r 6b308775b6f0 -r ffb0111298cd source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Nov 23 12:26:45 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Nov 23 14:06:10 2015 +0530
@@ -142,6 +142,8 @@
 rce->expectedVbv = rce2Pass->expectedVbv;
 rce->blurredComplexity = rce2Pass->blurredComplexity;
 rce->sliceType = rce2Pass->sliceType;
+rce->qpNoVbv = rce2Pass->qpNoVbv;
+rce->newQp = rce2Pass->newQp;
 }
 
 }  // end anonymous namespace
@@ -205,7 +207,7 @@
 m_rateFactorMaxDecrement = m_param->rc.rfConstant - 
m_param->rc.rfConstantMin;
 }
 m_isAbr = m_param->rc.rateControlMode != X265_RC_CQP && 
!m_param->rc.bStatRead;
-m_2pass = m_param->rc.rateControlMode == X265_RC_ABR && 
m_param->rc.bStatRead;
+m_2pass = (m_param->rc.rateControlMode == X265_RC_ABR || 
m_param->rc.vbvMaxBitrate > 0) && m_param->rc.bStatRead;
 m_bitrate = m_param->rc.bitrate * 1000;
 m_frameDuration = (double)m_param->fpsDenom / m_param->fpsNum;
 m_qp = m_param->rc.qp;
@@ -488,6 +490,12 @@
  x265_log(m_param, X265_LOG_ERROR, "Rce Entries for 2 pass 
cannot be allocated\n");
  return false;
 }
+m_encOrder = X265_MALLOC(int, m_numEntries);
+if (!m_encOrder)
+{
+x265_log(m_param, X265_LOG_ERROR, "Encode order for 2 pass 
cannot be allocated\n");
+return false;
+}
 /* init all to skipped p frames */
 for (int i = 0; i < m_numEntries; i++)
 {
@@ -504,6 +512,7 @@
 {
 RateControlEntry *rce;
 int frameNumber;
+int encodeOrder;
 char picType;
 int e;
 char *next;
@@ -511,13 +520,14 @@
 next = strstr(p, ";");
 if (next)
 *next++ = 0;
-e = sscanf(p, " in:%d ", );
+e = sscanf(p, " in:%d out:%d", , );
 if (frameNumber < 0 || frameNumber >= m_numEntries)
 {
 x265_log(m_param, X265_LOG_ERROR, "bad frame number (%d) 
at stats line %d\n", frameNumber, i);
 return false;
 }
-rce = _rce2Pass[frameNumber];
+rce = _rce2Pass[encodeOrder];
+m_encOrder[frameNumber] = encodeOrder;
 e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf 
q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",
, , , , >coeffBits,
>mvBits, >miscBits, >iCuCount, 
>pCuCount,
@@ -546,8 +556,7 @@
 p = next;
 }
 X265_FREE(statsBuf);
-
-if (m_param->rc.rateControlMode == X265_RC_ABR)
+if (m_param->rc.rateControlMode == X265_RC_ABR || 
m_param->rc.vbvMaxBitrate > 0)
 {
 if (!initPass2())
 return false;
@@ -630,11 +639,8 @@
 
 #undef MAX_DURATION
 }
-
-bool RateControl::initPass2()
+bool RateControl::analyseABR2Pass(int startIndex, int endIndex, uint64_t 
allAvailableBits)
 {
-uint64_t allConstBits = 0;
-uint64_t allAvailableBits = uint64_t(m_param->rc.bitrate * 1000. * 
m_numEntries * m_frameDuration);
 double rateFactor, stepMult;
 double qBlur = m_param->rc.qblur;
 double cplxBlur = m_param->rc.complexityBlur;
@@ -643,30 +649,19 @@
 double *qScale, *blurredQscale;
 double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);
 double clippedDuration = CLIP_DURATION(m_frameDuration) / 
BASE_FRAME_DURATION;
-
-/* find total/average complexity & const_bits */
-for 

[x265] [PATCH 1 of 2] rc: correctly update the intra row predictors for B frames

2015-11-12 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1447239250 -19800
#  Wed Nov 11 16:24:10 2015 +0530
# Node ID ca5137a54613304a6351a31c022806686898a52a
# Parent  45ea73c63c12c66e5e5e777e80853c8b3cadf101
rc: correctly update the intra row predictors for B frames

diff -r 45ea73c63c12 -r ca5137a54613 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Nov 06 11:55:27 2015 +0530
+++ b/source/encoder/ratecontrol.cppWed Nov 11 16:24:10 2015 +0530
@@ -1969,7 +1969,7 @@
 }
 rowSatdCost >>= X265_DEPTH - 8;
 updatePredictor(rce->rowPred[0], qScaleVbv, (double)rowSatdCost, 
encodedBits);
-if (curEncData.m_slice->m_sliceType == P_SLICE)
+if (curEncData.m_slice->m_sliceType != I_SLICE)
 {
 Frame* refFrame = curEncData.m_slice->m_refFrameList[0][0];
 if (qpVbv < refFrame->m_encData->m_rowStat[row].diagQp)
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 2] rc: change the predictors update algorithm

2015-11-12 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1447240285 -19800
#  Wed Nov 11 16:41:25 2015 +0530
# Node ID 44c08c1f5d3c88cf9cb3dd85cd9e2c4904cebb16
# Parent  ca5137a54613304a6351a31c022806686898a52a
rc: change the predictors update algorithm

diff -r ca5137a54613 -r 44c08c1f5d3c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Nov 11 16:24:10 2015 +0530
+++ b/source/encoder/ratecontrol.cppWed Nov 11 16:41:25 2015 +0530
@@ -928,16 +928,20 @@
 /* Frame Predictors used in vbv */
 for (int i = 0; i < 4; i++)
 {
+m_pred[i].coeffMin = 1.0 / 4;
 m_pred[i].coeff = 1.0;
 m_pred[i].count = 1.0;
 m_pred[i].decay = 0.5;
 m_pred[i].offset = 0.0;
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.75 / 4;
 if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
 {
+m_pred[1].coeffMin = 0.75 / 4;
 m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.50;
+m_pred[0].coeff = m_pred[3].coeff = 0.5;
+m_pred[0].coeffMin = m_pred[3].coeffMin = 0.5 / 4;
 }
 }
 
@@ -997,6 +1001,7 @@
 {
 for (int j = 0; j < 2; j++)
 {
+rce->rowPreds[i][j].coeffMin = 0.25 / 4;
 rce->rowPreds[i][j].coeff = 0.25;
 rce->rowPreds[i][j].count = 1.0;
 rce->rowPreds[i][j].decay = 0.5;
@@ -2149,7 +2154,8 @@
 return;
 const double range = 2;
 double old_coeff = p->coeff / p->count;
-double new_coeff = bits * q / var;
+double old_offset = p->offset / p->count;
+double new_coeff = X265_MAX((bits * q - old_offset) / var, p->coeffMin );
 double new_coeff_clipped = x265_clip3(old_coeff / range, old_coeff * 
range, new_coeff);
 double new_offset = bits * q - new_coeff_clipped * var;
 if (new_offset >= 0)
diff -r ca5137a54613 -r 44c08c1f5d3c source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Wed Nov 11 16:24:10 2015 +0530
+++ b/source/encoder/ratecontrol.h  Wed Nov 11 16:41:25 2015 +0530
@@ -48,6 +48,7 @@
 
 struct Predictor
 {
+double coeffMin;
 double coeff;
 double count;
 double decay;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] rc: improve loop in clipQscale

2015-11-10 Thread Aarthi Priya Thirumalai
LGTM
On Nov 6, 2015 1:41 PM, "Ximing Cheng"  wrote:

> # HG changeset patch
> # User Ximing Cheng 
> # Date 1446797063 -28800
> #  Fri Nov 06 16:04:23 2015 +0800
> # Node ID f11b17b4656a85a15dc82fd04485fbf920848e4d
> # Parent  45ea73c63c12c66e5e5e777e80853c8b3cadf101
> rc: improve loop in clipQscale
>
> diff -r 45ea73c63c12 -r f11b17b4656a source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cppFri Nov 06 11:55:27 2015 +0530
> +++ b/source/encoder/ratecontrol.cppFri Nov 06 16:04:23 2015 +0800
> @@ -1756,6 +1756,7 @@
>  * is in a reasonable state by the end of the lookahead. */
>  int loopTerminate = 0;
>  /* Avoid an infinite loop. */
> +double pSliceFactor = m_sliceType == I_SLICE ?
> m_param->rc.ipFactor : (m_sliceType == B_SLICE ? 1 / m_param->rc.pbFactor :
> 1);
>  for (int iterations = 0; iterations < 1000 && loopTerminate
> != 3; iterations++)
>  {
>  double frameQ[3];
> @@ -1764,7 +1765,7 @@
>  double bufferFillCur = m_bufferFill - curBits;
>  double targetFill;
>  double totalDuration = m_frameDuration;
> -frameQ[P_SLICE] = m_sliceType == I_SLICE ? q *
> m_param->rc.ipFactor : (m_sliceType == B_SLICE ? q / m_param->rc.pbFactor :
> q);
> +frameQ[P_SLICE] = q * pSliceFactor;
>  frameQ[B_SLICE] = frameQ[P_SLICE] * m_param->rc.pbFactor;
>  frameQ[I_SLICE] = frameQ[P_SLICE] / m_param->rc.ipFactor;
>  /* Loop over the planned future frames. */
> @@ -1798,12 +1799,15 @@
>  continue;
>  }
>  /* Try to get the buffer not more than 80% filled, but
> don't set an impossible goal. */
> -targetFill = x265_clip3(m_bufferSize * (1 - 0.2 *
> finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
> -if (m_isCbr && bufferFillCur > targetFill &&
> !m_isSceneTransition)
> +if (m_isCbr && !m_isSceneTransition)
>  {
> -q /= 1.01;
> -loopTerminate |= 2;
> -continue;
> +targetFill = x265_clip3(m_bufferSize * (1 - 0.2 *
> finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
> +if (bufferFillCur > targetFill)
> +{
> +q /= 1.01;
> +loopTerminate |= 2;
> +continue;
> +}
>  }
>  break;
>  }
> @@ -1857,7 +1861,7 @@
>  if (m_rateFactorMaxIncrement)
>  {
>  double qpNoVbv = x265_qScale2qp(q0);
> -double qmax = X265_MIN(MAX_MAX_QPSCALE,x265_qp2qScale(qpNoVbv
> + m_rateFactorMaxIncrement));
> +double qmax = X265_MIN(MAX_MAX_QPSCALE,
> x265_qp2qScale(qpNoVbv + m_rateFactorMaxIncrement));
>  return x265_clip3(MIN_QPSCALE, qmax, q);
>  }
>  }
>
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] entropy: fix bugs in accumulation of misc bits in 1st pass

2015-10-27 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1445948071 -19800
#  Tue Oct 27 17:44:31 2015 +0530
# Node ID 773d56aede9ef60f20aa8bd4cb86b436d76f31fe
# Parent  6563218ce342c30bfd4f9bc172a1dab510e6e55b
entropy: fix bugs in accumulation of misc bits in 1st pass

diff -r 6563218ce342 -r 773d56aede9e source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp   Mon Oct 26 12:13:53 2015 +0530
+++ b/source/encoder/analysis.cpp   Tue Oct 27 17:44:31 2015 +0530
@@ -2020,7 +2020,6 @@
 mode.contexts.resetBits();
 mode.contexts.codeSplitFlag(mode.cu, 0, depth);
 uint32_t bits = mode.contexts.getNumberOfWrittenBits();
-mode.mvBits += bits;
 mode.totalBits += bits;
 updateModeCost(mode);
 }
@@ -2031,7 +2030,6 @@
 }
 else
 {
-mode.mvBits++;
 mode.totalBits++;
 updateModeCost(mode);
 }
diff -r 6563218ce342 -r 773d56aede9e source/encoder/search.cpp
--- a/source/encoder/search.cpp Mon Oct 26 12:13:53 2015 +0530
+++ b/source/encoder/search.cpp Tue Oct 27 17:44:31 2015 +0530
@@ -1177,21 +1177,23 @@
 if (m_slice->m_pps->bTransquantBypassEnabled)
 m_entropyCoder.codeCUTransquantBypassFlag(cu.m_tqBypass[0]);
 
+int skipFlagBits = 0;
 if (!m_slice->isIntra())
 {
 m_entropyCoder.codeSkipFlag(cu, 0);
+skipFlagBits = m_entropyCoder.getNumberOfWrittenBits();
 m_entropyCoder.codePredMode(cu.m_predMode[0]);
 }
 
 m_entropyCoder.codePartSize(cu, 0, cuGeom.depth);
 m_entropyCoder.codePredInfo(cu, 0);
-intraMode.mvBits = m_entropyCoder.getNumberOfWrittenBits();
+intraMode.mvBits = m_entropyCoder.getNumberOfWrittenBits() - skipFlagBits;
 
 bool bCodeDQP = m_slice->m_pps->bUseDQP;
 m_entropyCoder.codeCoeff(cu, 0, bCodeDQP, tuDepthRange);
 m_entropyCoder.store(intraMode.contexts);
 intraMode.totalBits = m_entropyCoder.getNumberOfWrittenBits();
-intraMode.coeffBits = intraMode.totalBits - intraMode.mvBits;
+intraMode.coeffBits = intraMode.totalBits - intraMode.mvBits - 
skipFlagBits;
 if (m_rdCost.m_psyRd)
 {
 const Yuv* fencYuv = intraMode.fencYuv;
@@ -1395,16 +1397,17 @@
 if (m_slice->m_pps->bTransquantBypassEnabled)
 m_entropyCoder.codeCUTransquantBypassFlag(cu.m_tqBypass[0]);
 m_entropyCoder.codeSkipFlag(cu, 0);
+int skipFlagBits = m_entropyCoder.getNumberOfWrittenBits();
 m_entropyCoder.codePredMode(cu.m_predMode[0]);
 m_entropyCoder.codePartSize(cu, 0, cuGeom.depth);
 m_entropyCoder.codePredInfo(cu, 0);
-intraMode.mvBits += m_entropyCoder.getNumberOfWrittenBits();
+intraMode.mvBits = m_entropyCoder.getNumberOfWrittenBits() - skipFlagBits;
 
 bool bCodeDQP = m_slice->m_pps->bUseDQP;
 m_entropyCoder.codeCoeff(cu, 0, bCodeDQP, tuDepthRange);
 
 intraMode.totalBits = m_entropyCoder.getNumberOfWrittenBits();
-intraMode.coeffBits = intraMode.totalBits - intraMode.mvBits;
+intraMode.coeffBits = intraMode.totalBits - intraMode.mvBits - 
skipFlagBits;
 if (m_rdCost.m_psyRd)
 {
 const Yuv* fencYuv = intraMode.fencYuv;
@@ -2519,11 +2522,11 @@
 if (m_slice->m_pps->bTransquantBypassEnabled)
 m_entropyCoder.codeCUTransquantBypassFlag(cu.m_tqBypass[0]);
 m_entropyCoder.codeSkipFlag(cu, 0);
+int skipFlagBits = m_entropyCoder.getNumberOfWrittenBits();
 m_entropyCoder.codeMergeIndex(cu, 0);
-
-interMode.mvBits = m_entropyCoder.getNumberOfWrittenBits();
+interMode.mvBits = m_entropyCoder.getNumberOfWrittenBits() - skipFlagBits;
 interMode.coeffBits = 0;
-interMode.totalBits = interMode.mvBits;
+interMode.totalBits = interMode.mvBits + skipFlagBits;
 if (m_rdCost.m_psyRd)
 interMode.psyEnergy = m_rdCost.psyCost(part, fencYuv->m_buf[0], 
fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
 interMode.resEnergy = primitives.cu[part].sse_pp(fencYuv->m_buf[0], 
fencYuv->m_size, predYuv->m_buf[0], predYuv->m_size);
@@ -2599,30 +2602,33 @@
 if (m_slice->m_pps->bTransquantBypassEnabled)
 m_entropyCoder.codeCUTransquantBypassFlag(tqBypass);
 
-uint32_t coeffBits, bits;
+uint32_t coeffBits, bits, mvBits;
 if (cu.m_mergeFlag[0] && cu.m_partSize[0] == SIZE_2Nx2N && 
!cu.getQtRootCbf(0))
 {
 cu.setPredModeSubParts(MODE_SKIP);
 
 /* Merge/Skip */
+coeffBits = mvBits = 0;
 m_entropyCoder.codeSkipFlag(cu, 0);
+int skipFlagBits = m_entropyCoder.getNumberOfWrittenBits();
 m_entropyCoder.codeMergeIndex(cu, 0);
-coeffBits = 0;
-bits = m_entropyCoder.getNumberOfWrittenBits();
+mvBits = m_entropyCoder.getNumberOfWrittenBits() - skipFlagBits;
+bits = mvBits + skipFlagBits;
 }
 else
 {
 m_entropyCoder.codeSkipFlag(cu, 0);
+int skipFlagBits = m_entropyCoder.getNumberOfWrittenBits();
 m_entropyC

Re: [x265] P-frames referencing B-frames, Generalised B-frames in HEVC

2015-10-25 Thread Aarthi Priya Thirumalai
Hi,

When b-pyramid is on, then b slices can refer to both B , P and I slices.
We are creating a hierarchy among B frames, that is some B frames can be
used as reference for other b frames.

Regards
Aarthi
On Oct 26, 2015 3:23 AM, "Roshantha Mendis" <hrm...@york.ac.uk> wrote:

> Hi,
>
> When --b-pyramid  is set to true, can P-SLICES refer to B-SLICES ?
>
> I haven't come across a video sequence that this happens, but just want to
> know if this can happen.
>
> Also if this situation can occur, then is it valid according to the HEVC
> specs ?
>
> Many thanks
>
> --
> Rosh Mendis
> Research Student - EngD in LSCITS
> Dept. of Computer Science
> University of York
>
> Disclaimer: http://www.york.ac.uk/docs/disclaimer/email.htm
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] Under VBV rc mode , increasing the vbv-maxrate or vbv-bufsize has no or very little effect on the final result

2015-10-20 Thread Aarthi Priya Thirumalai
Adding to Mario's points, changing the vbv-maxrate and vbv-bufsize , while
keeping the target bitrate the same - will have a heavier impact on the
moving average bitrate rather than the overall bitrate.
Increasing the vbv buffer, while keeping the rest constant roughly means
the buffer can handle a larger fluctuation in the per second bitrate.
Similary, decreasing the vbv buffer size will drive the encoder to a stick
to a constant bitrate for every second. At this point the vbv restrictions
will kick in to decrease the bitrate hikes in between,
and the quality for that portion of scene might go down.

So, I suggest you plot the distribution of bitrates for each of your test
case to see the impact .

Regards
Aarthi


On Tue, Oct 20, 2015 at 11:53 AM, Mario *LigH* Rohkrämer <cont...@ligh.de>
wrote:

> I believe the reason is the relation between the three values. You can
> fill the buffer faster than the video target bitrate, so it needs only few
> seconds to fill a previously empty buffer, and even less if the buffer was
> already pre-filled. And then you compare it to a case where you can fill it
> even faster than before, so there is even less problem; the encoder is
> almost unrestricted by the VBV, only restricted by the target bitrate.
>
> You will certainly see a difference in cases where filling the buffer
> would take longer, and the video bitrate would exceed this fill rate for a
> longer duration if it was not limited by the fill rate: Then the encoder
> needs to reduce its target bitrate and spend less than the optimum for the
> desired quality.
>
> From my experience as DVD Video author, we had cases of close to optimum
> utilizations of videos just even rejected by the authoring tool, where the
> analysis of the scene in question revealed per GOP spikes of 13-14 Mbps
> (VBV max fill rate of DVD Video is 9.8 Mbps) which the VBV simulator of the
> encoder found acceptable, but the VBV simulator in the authoring tool could
> not accept (possibly due to an unfortunate burst of subtitles). Agerage
> bitrates tell little, their distribution over the VBV filling duration
> makes the difference.
>
> One of the most demanding scenes ever was the beginning of "Cruel
> Intentions" with a flight over a graveyard, filmed downwards: Several
> seconds of heavy motion right at the start. It revealed a few rare DVD
> player models which possibly had less than the specified 224 KB of decoding
> buffer built in.
>
>
>
> Am 20.10.2015, 04:59 Uhr, schrieb fangzhen <wintelx...@163.com>:
>
> Recently, I am testing the x265 codes  and mostly on VBV rc mode.\
>> But, I find an strange problem. For instance, I set up the following test
>> circumstance:
>> resolution: 1920x1080
>> bitrate=1000kbps, vbv-bufsize=3000kbit
>> when I set vbv-maxbitrate>1250kbps, I get almost the same result, like
>> the same psnr, the almost same bitrate.
>> I get the same result for vbv-bufsize where the vbv-maxbitrate is fixed,
>> like 3000kbps.
>> So I wonder why this situation exists? Can anybody give me some
>> explanation? Thanks so much in advance.
>>
>
>
> --
>
> Fun and success!
> Mario *LigH* Rohkrämer
> mailto:cont...@ligh.de
>
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 2 of 2] rc: Remove the redundant calculation on slidingWindow

2015-10-16 Thread Aarthi Priya Thirumalai
On Fri, Oct 16, 2015 at 1:50 PM, Ximing Cheng 
wrote:

> This patch reduce the calculation by saving the SATD moving sum last
> time (frame), then the next frame can calculate its SATD moving sum by
> the last moving sum and the replaced value in the slidingWindow, so
> that each frame in rate ctrl does not need to do a loop for at most
> s_slidingWindowFrames times to calculate its SATD moving sum.
>
> Suppose slidingWindow size is 6, value is x y z a b c
>
> rc frame (m_sliderPos)moving sum
> 0   0
> 1   0.5x
> 2   0.5^2x+0.5y
> 3   0.5^3x+0.5^2y+0.5z
> 4   0.5^4x+0.5^3y+0.5^2z+0.5a
> 5
>  0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b
> 6
> 0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b+c
> 7   0.5
> (0.5^4y+0.5^3z+0.5^2a+0.5b+c)+x_1   == 0.5
> (0.5^5x+0.5^4y+0.5^3z+0.5^2a+0.5b+c -  0.5^5x) + x_1
>
> which x_1 is the replaced value of x
>
> On Mon, Oct 12, 2015 at 10:26 AM, Ximing Cheng
>  wrote:
> > # HG changeset patch
> > # User Ximing Cheng 
> > # Date 1444616617 -28800
> > #  Mon Oct 12 10:23:37 2015 +0800
> > # Node ID 0d1cfbb2716edcf9ba5b8ccc8b0fd585f4de59d7
> > # Parent  667253981f61f18c36bf5c7f607fbf6ea8cc6474
> > rc: Remove the redundant calculation on slidingWindow
> >
> > diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.cpp
> > --- a/source/encoder/ratecontrol.cppMon Oct 12 10:18:55 2015 +0800
> > +++ b/source/encoder/ratecontrol.cppMon Oct 12 10:23:37 2015 +0800
> > @@ -219,6 +219,7 @@
> >  m_cutreeStatFileOut = m_cutreeStatFileIn = NULL;
> >  m_rce2Pass = NULL;
> >  m_lastBsliceSatdCost = 0;
> > +m_movingAvgSum = 0.0;
> >
> >  // vbv initialization
> >  m_param->rc.vbvBufferSize = x265_clip3(0, 200,
> m_param->rc.vbvBufferSize);
> > @@ -1347,18 +1348,28 @@
> >  {
> >  if (m_isAbr)
> >  {
> > -double slidingWindowCplxSum = 0;
> > -int start = m_sliderPos > s_slidingWindowFrames ?
> m_sliderPos : 0;
> > -for (int cnt = 0; cnt < s_slidingWindowFrames; cnt++,
> start++)
> > +int pos = m_sliderPos % s_slidingWindowFrames;
> > +int addPos = (pos + s_slidingWindowFrames - 1) %
> s_slidingWindowFrames;
> > +if (m_sliderPos > s_slidingWindowFrames)
> >  {
> > -int pos = start % s_slidingWindowFrames;
> > -slidingWindowCplxSum *= 0.5;
> > -if (!m_satdCostWindow[pos])
> > -break;
> > -slidingWindowCplxSum += m_satdCostWindow[pos];
> > +const static double base = pow(0.5,
> s_slidingWindowFrames - 1);
> > +m_movingAvgSum -= m_lastRemovedSatdCost * base;
> > +m_movingAvgSum *= 0.5;
> > +m_movingAvgSum += m_satdCostWindow[addPos];
> >  }
> > -rce->movingAvgSum = slidingWindowCplxSum;
> > -m_satdCostWindow[m_sliderPos % s_slidingWindowFrames] =
> rce->lastSatd;
> > +else if (m_sliderPos == s_slidingWindowFrames)
> > +{
> > +m_movingAvgSum += m_satdCostWindow[addPos];
> > +}
> > +else if (m_sliderPos > 0)
> > +{
> > +m_movingAvgSum += m_satdCostWindow[addPos];
> > +m_movingAvgSum *= 0.5;
> > +}
> > +
> > +rce->movingAvgSum = m_movingAvgSum;
> > +m_lastRemovedSatdCost = m_satdCostWindow[pos];
> > +m_satdCostWindow[pos] = rce->lastSatd;
> >  m_sliderPos++;
> >  }
> >  }
>
should the m_lastRemovedSatdCost be taken after incrementing the
m_sliderPos  ?
because at the position = s_slidingWindowFrames, it should delete the data
written in m_satdCostWindow
but the lastRemovedSatdCost would not be pointing to that yet - can you
check this once.

> diff -r 667253981f61 -r 0d1cfbb2716e source/encoder/ratecontrol.h
> > --- a/source/encoder/ratecontrol.h  Mon Oct 12 10:18:55 2015 +0800
> > +++ b/source/encoder/ratecontrol.h  Mon Oct 12 10:23:37 2015 +0800
> > @@ -167,6 +167,8 @@
> >  int64_t m_satdCostWindow[50];
> >  int64_t m_encodedBitsWindow[50];
> >  int m_sliderPos;
> > +int64_t m_lastRemovedSatdCost;
> > +double  m_movingAvgSum;
> >
> >  /* To detect a pattern of low detailed static frames in single pass
> ABR using satdcosts */
> >  int64_t m_lastBsliceSatdCost;
> >
> >
> > ___
> > x265-devel mailing list
> > x265-devel@videolan.org
> > https://mailman.videolan.org/listinfo/x265-devel
> ___
> x265-devel mailing list
> x265-devel@videolan.org
> 

[x265] [PATCH] slicetype: allow scenecut engine independent of adaptive bframe option

2015-10-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1444296492 -19800
#  Thu Oct 08 14:58:12 2015 +0530
# Branch stable
# Node ID 232c387fc7242c3cca6565e2094672082834ec29
# Parent  af9a5476502c7f8bb814b6dfd79eaadb3304a805
slicetype: allow scenecut engine independent of adaptive bframe option

diff -r af9a5476502c -r 232c387fc724 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Thu Oct 08 11:05:42 2015 +0530
+++ b/source/encoder/slicetype.cpp  Thu Oct 08 14:58:12 2015 +0530
@@ -1254,16 +1254,12 @@
 
 int numBFrames = 0;
 int numAnalyzed = numFrames;
-
-if (m_param->bFrameAdaptive)
+bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);
+/* When scenecut threshold is set, use scenecut detection for I frame 
placements */
+if (m_param->scenecutThreshold && isScenecut)
 {
-bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);
-/* When scenecut threshold is set, use scenecut detection for I frame 
placements */
-if (m_param->scenecutThreshold && isScenecut)
-{
-frames[1]->sliceType = X265_TYPE_I;
-return;
-}
+frames[1]->sliceType = X265_TYPE_I;
+return;
 }
 
 if (m_param->bframes)
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: bug fix to avoid vbv predictor misprediction errors at scenecut

2015-10-01 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1443713129 -19800
#  Thu Oct 01 20:55:29 2015 +0530
# Branch stable
# Node ID 13cfec40af4fe67c3a82e3d82ea9d289822a4fbc
# Parent  33218e324fec6c0ea04499ebd6ac3b25d7dd91d1
rc: bug fix to avoid vbv predictor misprediction errors at scenecut

diff -r 33218e324fec -r 13cfec40af4f source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Sep 22 13:41:11 2015 +0530
+++ b/source/encoder/ratecontrol.cppThu Oct 01 20:55:29 2015 +0530
@@ -1583,8 +1583,9 @@
 rce->qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
- * mispredictions by initial frame size predictors */
-if (!m_2pass && m_isVbv && m_pred[m_predType].count == 1)
+ * mispredictions by initial frame size predictors, after each 
scenecut */
+bool isFrameAfterScenecut = m_sliceType!= I_SLICE && 
m_curSlice->m_refPicList[0][0]->m_lowres.bScenecut;
+if (!m_2pass && m_isVbv && isFrameAfterScenecut)
 q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 1 of 2] rc: don't update predictors from previous frames, after reset at scenecut

2015-09-28 Thread Aarthi Priya Thirumalai
No.
We will re init vbv predictors and apply the scenecut transition related
controls from the scene that begins the scene change which is signaled by
bScenecut flag.
and revert the operation at the next mini-gop.


On Mon, Sep 28, 2015 at 5:03 PM, Deepthi Nandakumar <
deep...@multicorewareinc.com> wrote:

>
>
> On Thu, Sep 24, 2015 at 1:56 PM, <aar...@multicorewareinc.com> wrote:
>
>> # HG changeset patch
>> # User Aarthi Thirumalai
>> # Date 1442909407 -19800
>> #  Tue Sep 22 13:40:07 2015 +0530
>> # Branch stable
>> # Node ID c44b32bc7c906456ad242dd237831ec96c1f5c3d
>> # Parent  69d55d4c53ebff6d98e4431e0f8fe6103705b8ec
>> rc: don't update predictors from previous frames, after reset at scenecut.
>>
>> diff -r 69d55d4c53eb -r c44b32bc7c90 source/encoder/ratecontrol.cpp
>> --- a/source/encoder/ratecontrol.cppTue Sep 22 13:33:13 2015 +0530
>> +++ b/source/encoder/ratecontrol.cppTue Sep 22 13:40:07 2015 +0530
>> @@ -182,6 +182,7 @@
>>  m_finalFrameCount = 0;
>>  m_numEntries = 0;
>>  m_isSceneTransition = false;
>> +m_lastPredictorReset = 0;
>>  if (m_param->rc.rateControlMode == X265_RC_CRF)
>>  {
>>  m_param->rc.qp = (int)m_param->rc.rfConstant;
>> @@ -370,20 +371,8 @@
>>  m_accumPNorm = .01;
>>  m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ?
>> CRF_INIT_QP : ABR_INIT_QP_MIN) * m_accumPNorm;
>>
>> -/* Frame Predictors and Row predictors used in vbv */
>> -for (int i = 0; i < 4; i++)
>> -{
>> -m_pred[i].coeff = 1.0;
>> -m_pred[i].count = 1.0;
>> -m_pred[i].decay = 0.5;
>> -m_pred[i].offset = 0.0;
>> -}
>> -m_pred[0].coeff = m_pred[3].coeff = 0.75;
>> -if (m_param->rc.qCompress >= 0.8) // when tuned for grain
>> -{
>> -m_pred[1].coeff = 0.75;
>> -m_pred[0].coeff = m_pred[3].coeff = 0.50;
>> -}
>> +/* Frame Predictors used in vbv */
>> +initFramePredictors();
>>  if (!m_statFileOut && (m_param->rc.bStatWrite ||
>> m_param->rc.bStatRead))
>>  {
>>  /* If the user hasn't defined the stat filename, use the default
>> value */
>> @@ -932,6 +921,24 @@
>>  return X265_TYPE_AUTO;
>>  }
>>
>> +void RateControl::initFramePredictors()
>> +{
>> +/* Frame Predictors used in vbv */
>> +for (int i = 0; i < 4; i++)
>> +{
>> +m_pred[i].coeff = 1.0;
>> +m_pred[i].count = 1.0;
>> +m_pred[i].decay = 0.5;
>> +m_pred[i].offset = 0.0;
>> +}
>> +m_pred[0].coeff = m_pred[3].coeff = 0.75;
>> +if (m_param->rc.qCompress >= 0.8) // when tuned for grain
>> +{
>> +m_pred[1].coeff = 0.75;
>> +m_pred[0].coeff = m_pred[3].coeff = 0.50;
>> +}
>> +}
>> +
>>  int RateControl::rateControlStart(Frame* curFrame, RateControlEntry*
>> rce, Encoder* enc)
>>  {
>>  int orderValue = m_startEndOrder.get();
>> @@ -961,23 +968,21 @@
>>  copyRceData(rce, _rce2Pass[rce->poc]);
>>  }
>>  rce->isActive = true;
>> -bool isframeAfterKeyframe = m_sliceType != I_SLICE &&
>> m_curSlice->m_refPicList[0][0]->m_encData->m_slice->m_sliceType == I_SLICE;
>> +bool isRefFrameScenecut = m_sliceType!= I_SLICE &&
>> m_curSlice->m_refPicList[0][0]->m_lowres.bScenecut == 1;
>>  if (curFrame->m_lowres.bScenecut)
>>  {
>>
>
> This should be if (isRefFrameScenecut)?
>
>
>>  m_isSceneTransition = true;
>> -/* Frame Predictors and Row predictors used in vbv */
>> -for (int i = 0; i < 4; i++)
>> -{
>> -m_pred[i].coeff = 1.0;
>> -m_pred[i].count = 1.0;
>> -m_pred[i].decay = 0.5;
>> -m_pred[i].offset = 0.0;
>> -}
>> -m_pred[0].coeff = m_pred[3].coeff = 0.75;
>> +m_lastPredictorReset = rce->encodeOrder;
>> +initFramePredictors();
>>  }
>> -else if (m_sliceType != B_SLICE && !isframeAfterKeyframe)
>> +else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
>>  m_isSceneTransition = false;
>>
>> +if (rce->encodeOrder < m_lastPredictorReset +
>> m_param->frameNumThreads)
>> +{
>> +rce->rowPreds[0][0].count = 0;
>> +}
>> +
>>  rce->bLastMin

[x265] [PATCH 1 of 2] rc: don't update predictors from previous frames, after reset at scenecut

2015-09-24 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1442909407 -19800
#  Tue Sep 22 13:40:07 2015 +0530
# Branch stable
# Node ID c44b32bc7c906456ad242dd237831ec96c1f5c3d
# Parent  69d55d4c53ebff6d98e4431e0f8fe6103705b8ec
rc: don't update predictors from previous frames, after reset at scenecut.

diff -r 69d55d4c53eb -r c44b32bc7c90 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Sep 22 13:40:07 2015 +0530
@@ -182,6 +182,7 @@
 m_finalFrameCount = 0;
 m_numEntries = 0;
 m_isSceneTransition = false;
+m_lastPredictorReset = 0;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -370,20 +371,8 @@
 m_accumPNorm = .01;
 m_accumPQp = (m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
-/* Frame Predictors and Row predictors used in vbv */
-for (int i = 0; i < 4; i++)
-{
-m_pred[i].coeff = 1.0;
-m_pred[i].count = 1.0;
-m_pred[i].decay = 0.5;
-m_pred[i].offset = 0.0;
-}
-m_pred[0].coeff = m_pred[3].coeff = 0.75;
-if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
-{
-m_pred[1].coeff = 0.75;
-m_pred[0].coeff = m_pred[3].coeff = 0.50;
-}
+/* Frame Predictors used in vbv */
+initFramePredictors();
 if (!m_statFileOut && (m_param->rc.bStatWrite || m_param->rc.bStatRead))
 {
 /* If the user hasn't defined the stat filename, use the default value 
*/
@@ -932,6 +921,24 @@
 return X265_TYPE_AUTO;
 }
 
+void RateControl::initFramePredictors()
+{
+/* Frame Predictors used in vbv */
+for (int i = 0; i < 4; i++)
+{
+m_pred[i].coeff = 1.0;
+m_pred[i].count = 1.0;
+m_pred[i].decay = 0.5;
+m_pred[i].offset = 0.0;
+}
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+{
+m_pred[1].coeff = 0.75;
+m_pred[0].coeff = m_pred[3].coeff = 0.50;
+}
+}
+
 int RateControl::rateControlStart(Frame* curFrame, RateControlEntry* rce, 
Encoder* enc)
 {
 int orderValue = m_startEndOrder.get();
@@ -961,23 +968,21 @@
 copyRceData(rce, _rce2Pass[rce->poc]);
 }
 rce->isActive = true;
-bool isframeAfterKeyframe = m_sliceType != I_SLICE && 
m_curSlice->m_refPicList[0][0]->m_encData->m_slice->m_sliceType == I_SLICE;
+bool isRefFrameScenecut = m_sliceType!= I_SLICE && 
m_curSlice->m_refPicList[0][0]->m_lowres.bScenecut == 1;
 if (curFrame->m_lowres.bScenecut)
 {
 m_isSceneTransition = true;
-/* Frame Predictors and Row predictors used in vbv */
-for (int i = 0; i < 4; i++)
-{
-m_pred[i].coeff = 1.0;
-m_pred[i].count = 1.0;
-m_pred[i].decay = 0.5;
-m_pred[i].offset = 0.0;
-}
-m_pred[0].coeff = m_pred[3].coeff = 0.75;
+m_lastPredictorReset = rce->encodeOrder;
+initFramePredictors();
 }
-else if (m_sliceType != B_SLICE && !isframeAfterKeyframe)
+else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
 m_isSceneTransition = false;
 
+if (rce->encodeOrder < m_lastPredictorReset + m_param->frameNumThreads)
+{
+rce->rowPreds[0][0].count = 0;
+}
+
 rce->bLastMiniGopBFrame = curFrame->m_lowres.bLastMiniGopBFrame;
 rce->bufferRate = m_bufferRate;
 rce->rowCplxrSum = 0.0;
@@ -2149,7 +2154,7 @@
 {
 int predType = rce->sliceType;
 predType = rce->sliceType == B_SLICE && rce->keptAsRef ? 3 : predType;
-if (rce->lastSatd >= m_ncu)
+if (rce->lastSatd >= m_ncu && rce->encodeOrder >= m_lastPredictorReset)
 updatePredictor(_pred[predType], x265_qp2qScale(rce->qpaRc), 
(double)rce->lastSatd, (double)bits);
 if (!m_isVbv)
 return;
diff -r 69d55d4c53eb -r c44b32bc7c90 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Tue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Sep 22 13:40:07 2015 +0530
@@ -173,6 +173,7 @@
 int m_numBframesInPattern;
 boolm_isPatternPresent;
 boolm_isSceneTransition;
+int m_lastPredictorReset;
 
 /* a common variable on which rateControlStart, rateControlEnd and 
rateControUpdateStats waits to
  * sync the calls to these functions. For example
@@ -257,6 +258,7 @@
 void   checkAndResetABR(RateControlEntry* rce, bool isFrameDone);
 double predictRowsSizeSum(Frame* pic, RateControlEntry* rce, double qpm, 
int32_t& encodedBits);
 bool   initPass2();
+void   initFramePredictors();
 double getDiffLimitedQScale(RateControlEntry *rce, double q);
 double countExp

[x265] [PATCH 2 of 2] rc: scale down intra costs to predict bits when bitdepth > 8

2015-09-24 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1442909471 -19800
#  Tue Sep 22 13:41:11 2015 +0530
# Branch stable
# Node ID 2f296fbb7f8a688024653db39f89861c9f232c80
# Parent  c44b32bc7c906456ad242dd237831ec96c1f5c3d
rc: scale down intra costs to predict bits when bitdepth > 8.

diff -r c44b32bc7c90 -r 2f296fbb7f8a source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Sep 22 13:40:07 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Sep 22 13:41:11 2015 +0530
@@ -1928,6 +1928,7 @@
 else if (picType == P_SLICE)
 {
 intraCostForPendingCus = 
curEncData.m_rowStat[row].intraSatdForVbv - 
curEncData.m_rowStat[row].diagIntraSatd;
+intraCostForPendingCus >>= X265_DEPTH - 8;
 /* Our QP is lower than the reference! */
 double pred_intra = predictSize(rce->rowPred[1], qScale, 
intraCostForPendingCus);
 /* Sum: better to overestimate than underestimate by using 
only one of the two predictors. */
@@ -1963,7 +1964,7 @@
 uint64_t intraRowSatdCost = 
curEncData.m_rowStat[row].diagIntraSatd;
 if (row == 1)
 intraRowSatdCost += curEncData.m_rowStat[0].diagIntraSatd;
-
+intraRowSatdCost >>= X265_DEPTH - 8;
 updatePredictor(rce->rowPred[1], qScaleVbv, 
(double)intraRowSatdCost, encodedBits);
 }
 }
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 1 of 3] slicetype: identify and mark scenecuts as P slices when scenecutThreshold is 0

2015-09-22 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1442908993 -19800
#  Tue Sep 22 13:33:13 2015 +0530
# Node ID 819f8cf72d15c6a3dba77383881b8f4c1140542c
# Parent  acc2394e34ef7b203a5337d12c926b42bfd8740a
slicetype: identify and mark scenecuts as P slices when scenecutThreshold is 0

When scenecut threshold is 0, there is no I frame placements for scene changes,
still the scenecuts are identified and tagged to be used by Ratecontrol.

diff -r acc2394e34ef -r 819f8cf72d15 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Mon Sep 21 18:48:46 2015 -0500
+++ b/source/encoder/slicetype.cpp  Tue Sep 22 13:33:13 2015 +0530
@@ -1364,7 +1364,7 @@
 /* Check scenecut on the first minigop. */
 for (int j = 1; j < numBFrames + 1; j++)
 {
-if (m_param->scenecutThreshold && scenecut(frames, j, j + 1, 
false, origNumFrames))
+if (scenecut(frames, j - 1, j, false, origNumFrames))
 {
 frames[j]->sliceType = X265_TYPE_P;
 numAnalyzed = j;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 3] rc: don't update predictors from previous frames, after reset at scenecut

2015-09-22 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1442909407 -19800
#  Tue Sep 22 13:40:07 2015 +0530
# Node ID 5a3c92b92a049f49e7712ad3d2ba458937e0c55d
# Parent  819f8cf72d15c6a3dba77383881b8f4c1140542c
rc: don't update predictors from previous frames, after reset at scenecut.

diff -r 819f8cf72d15 -r 5a3c92b92a04 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Sep 22 13:40:07 2015 +0530
@@ -182,6 +182,7 @@
 m_finalFrameCount = 0;
 m_numEntries = 0;
 m_isSceneTransition = false;
+m_lastPredictorReset = 0;
 if (m_param->rc.rateControlMode == X265_RC_CRF)
 {
 m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -961,10 +962,11 @@
 copyRceData(rce, _rce2Pass[rce->poc]);
 }
 rce->isActive = true;
-bool isframeAfterKeyframe = m_sliceType != I_SLICE && 
m_curSlice->m_refFrameList[0][0]->m_encData->m_slice->m_sliceType == I_SLICE;
+bool isRefFrameScenecut = m_sliceType!= I_SLICE && 
m_curSlice->m_refFrameList[0][0]->m_lowres.bScenecut == 1;
 if (curFrame->m_lowres.bScenecut)
 {
 m_isSceneTransition = true;
+m_lastPredictorReset = rce->encodeOrder;
 /* Frame Predictors and Row predictors used in vbv */
 for (int i = 0; i < 4; i++)
 {
@@ -974,10 +976,20 @@
 m_pred[i].offset = 0.0;
 }
 m_pred[0].coeff = m_pred[3].coeff = 0.75;
+if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+{
+m_pred[1].coeff = 0.75;
+m_pred[0].coeff = m_pred[3].coeff = 0.50;
+}
 }
-else if (m_sliceType != B_SLICE && !isframeAfterKeyframe)
+else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
 m_isSceneTransition = false;
 
+if (rce->encodeOrder < m_lastPredictorReset + m_param->frameNumThreads)
+{
+rce->rowPreds[0][0].count = 0;
+}
+
 rce->bLastMiniGopBFrame = curFrame->m_lowres.bLastMiniGopBFrame;
 rce->bufferRate = m_bufferRate;
 rce->rowCplxrSum = 0.0;
@@ -2149,7 +2161,7 @@
 {
 int predType = rce->sliceType;
 predType = rce->sliceType == B_SLICE && rce->keptAsRef ? 3 : predType;
-if (rce->lastSatd >= m_ncu)
+if (rce->lastSatd >= m_ncu && rce->encodeOrder >= m_lastPredictorReset)
 updatePredictor(_pred[predType], x265_qp2qScale(rce->qpaRc), 
(double)rce->lastSatd, (double)bits);
 if (!m_isVbv)
 return;
@@ -2205,6 +2217,7 @@
 }
 else
 curEncData.m_avgQpAq = curEncData.m_avgQpRc;
+rce->qpAq = curEncData.m_avgQpAq;
 }
 
 if (m_isAbr)
diff -r 819f8cf72d15 -r 5a3c92b92a04 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Tue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Sep 22 13:40:07 2015 +0530
@@ -173,6 +173,7 @@
 int m_numBframesInPattern;
 boolm_isPatternPresent;
 boolm_isSceneTransition;
+int m_lastPredictorReset;
 
 /* a common variable on which rateControlStart, rateControlEnd and 
rateControUpdateStats waits to
  * sync the calls to these functions. For example
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 3 of 3] rc: scale down intra costs to predict bits when bitdepth > 8

2015-09-22 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1442909471 -19800
#  Tue Sep 22 13:41:11 2015 +0530
# Node ID 8557bc303897a88e34b3ebb8ed4f9b16cfc68234
# Parent  5a3c92b92a049f49e7712ad3d2ba458937e0c55d
rc: scale down intra costs to predict bits when bitdepth > 8.

diff -r 5a3c92b92a04 -r 8557bc303897 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Sep 22 13:40:07 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Sep 22 13:41:11 2015 +0530
@@ -1935,6 +1935,7 @@
 else if (picType == P_SLICE)
 {
 intraCostForPendingCus = 
curEncData.m_rowStat[row].intraSatdForVbv - 
curEncData.m_rowStat[row].diagIntraSatd;
+intraCostForPendingCus >>= X265_DEPTH - 8;
 /* Our QP is lower than the reference! */
 double pred_intra = predictSize(rce->rowPred[1], qScale, 
intraCostForPendingCus);
 /* Sum: better to overestimate than underestimate by using 
only one of the two predictors. */
@@ -1970,7 +1971,7 @@
 uint64_t intraRowSatdCost = 
curEncData.m_rowStat[row].diagIntraSatd;
 if (row == 1)
 intraRowSatdCost += curEncData.m_rowStat[0].diagIntraSatd;
-
+intraRowSatdCost >>= X265_DEPTH - 8;
 updatePredictor(rce->rowPred[1], qScaleVbv, 
(double)intraRowSatdCost, encodedBits);
 }
 }
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 1 of 2] slicetype: Modify Scenecut algorithm to detect scene transition points

2015-08-17 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Thirumalai
# Date 1437505166 -19800
#  Wed Jul 22 00:29:26 2015 +0530
# Node ID cea0ce5bf57d5decc14743aa69234a1dfe84996b
# Parent  d56b2466c04459205287e1581d8a36eebf372ba6
slicetype: Modify Scenecut algorithm to detect scene transition points
to improve Rate Control (refs #160).

identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the
flag bSceneCut
in Lowres structure. This flag will be used by RateControl to adjust the qp
during scene cuts.

diff -r d56b2466c044 -r cea0ce5bf57d source/common/lowres.cpp
--- a/source/common/lowres.cpp Wed Aug 12 18:12:20 2015 +0530
+++ b/source/common/lowres.cpp Wed Jul 22 00:29:26 2015 +0530
@@ -126,7 +126,7 @@
 void Lowres::init(PicYuv *origPic, int poc)
 {
 bLastMiniGopBFrame = false;
-bScenecut = true;  // could be a scene-cut, until ruled out by flash
detection
+bScenecut = false;  // could be a scene-cut, until ruled out by flash
detection
 bKeyframe = false; // Not a keyframe unless identified by lookahead
 frameNum = poc;
 leadingBframes = 0;
diff -r d56b2466c044 -r cea0ce5bf57d source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Wed Aug 12 18:12:20 2015 +0530
+++ b/source/encoder/slicetype.cpp Wed Jul 22 00:29:26 2015 +0530
@@ -483,6 +483,7 @@
 m_pool  = pool;

 m_lastNonB = NULL;
+m_isSceneTransition = false;
 m_scratch  = NULL;
 m_tld  = NULL;
 m_filled   = false;
@@ -1267,10 +1268,16 @@

 int numBFrames = 0;
 int numAnalyzed = numFrames;
-if (m_param-scenecutThreshold  scenecut(frames, 0, 1, true,
origNumFrames, maxSearch))
+
+if (m_param-bFrameAdaptive)
 {
-frames[1]-sliceType = X265_TYPE_I;
-return;
+bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);
+/* When scenecut threshold is set, use scenecut detection for I
frame placements */
+if (!m_param-scenecutThreshold  isScenecut)
+{
+frames[1]-sliceType = X265_TYPE_I;
+return;
+}
 }

 if (m_param-bframes)
@@ -1357,14 +1364,13 @@
 /* Check scenecut on the first minigop. */
 for (int j = 1; j  numBFrames + 1; j++)
 {
-if (m_param-scenecutThreshold  scenecut(frames, j, j + 1,
false, origNumFrames, maxSearch))
+if (m_param-scenecutThreshold  scenecut(frames, j, j + 1,
false, origNumFrames))
 {
 frames[j]-sliceType = X265_TYPE_P;
 numAnalyzed = j;
 break;
 }
 }
-
 resetStart = bKeyframe ? 1 : X265_MIN(numBFrames + 2, numAnalyzed
+ 1);
 }
 else
@@ -1388,46 +1394,94 @@
 if (bIsVbvLookahead)
 vbvLookahead(frames, numFrames, bKeyframe);

+ int maxp1 = X265_MIN(m_param-bframes + 1, origNumFrames);
 /* Restore frame types for all frames that haven't actually been
decided yet. */
 for (int j = resetStart; j = numFrames; j++)
+{
 frames[j]-sliceType = X265_TYPE_AUTO;
+/* If any frame marked as scenecut is being restarted for
sliceDecision,
+ * undo scene Transition flag */
+if (j = maxp1  frames[j]-bScenecut  m_isSceneTransition)
+m_isSceneTransition = false;
+}
 }

-bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool
bRealScenecut, int numFrames, int maxSearch)
+bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool
bRealScenecut, int numFrames)
 {
 /* Only do analysis during a normal scenecut check. */
 if (bRealScenecut  m_param-bframes)
 {
 int origmaxp1 = p0 + 1;
 /* Look ahead to avoid coding short flashes as scenecuts. */
-if (m_param-bFrameAdaptive == X265_B_ADAPT_TRELLIS)
-/* Don't analyse any more frames than the trellis would have
covered. */
-origmaxp1 += m_param-bframes;
-else
-origmaxp1++;
+origmaxp1 += m_param-bframes;
 int maxp1 = X265_MIN(origmaxp1, numFrames);
-
+bool fluctuate = false;
+bool noScenecuts = false;
+int64_t avgSatdCost = 0;
+if (frames[0]-costEst[1][0]  -1)
+avgSatdCost = frames[0]-costEst[1][0];
+int cnt = 1;
 /* Where A and B are scenes: AABBBAA
  * If BBB is shorter than (maxp1-p0), it is detected as a flash
  * and not considered a scenecut. */
 for (int cp1 = p1; cp1 = maxp1; cp1++)
 {
 if (!scenecutInternal(frames, p0, cp1, false))
+{
 /* Any frame in between p0 and cur_p1 cannot be a real
scenecut. */
 for (int i = cp1; i  p0; i--)
+{
 frames[i]-bScenecut = false;
+noScenecuts = false;
+}
+}
+else if (scenecutInternal(frames, cp1 - 1, cp1, false))
+{
+/* If current frame is a Scenecut from p0 frame as well as
Scenecut from

Re: [x265] [PATCH 2 of 2] rc: adjust qp for scene transitions and fade ins to avoid quality loss with vbv

2015-08-17 Thread Aarthi Priya Thirumalai
ignore the previous patch - contains a build error. Sending the corrected
version here:

# HG changeset patch
# User Aarthi Thirumalai
# Date 1439287054 -19800
#  Tue Aug 11 15:27:34 2015 +0530
# Node ID 4f5109967676d983d8ccc4f5f410f96f5f30a5cb
# Parent  cea0ce5bf57d5decc14743aa69234a1dfe84996b
rc: adjust qp for scene transitions and fade ins to avoid quality loss with
vbv

diff -r cea0ce5bf57d -r 4f5109967676 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Wed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.cpp Tue Aug 11 15:27:34 2015 +0530
@@ -181,6 +181,7 @@
 m_bTerminated = false;
 m_finalFrameCount = 0;
 m_numEntries = 0;
+m_isSceneTransition = false;
 if (m_param-rc.rateControlMode == X265_RC_CRF)
 {
 m_param-rc.qp = (int)m_param-rc.rfConstant;
@@ -273,7 +274,6 @@
 if(m_param-rc.bStrictCbr)
 m_rateTolerance = 0.7;

-m_leadingBframes = m_param-bframes;
 m_bframeBits = 0;
 m_leadingNoBSatd = 0;
 m_ipOffset = 6.0 * X265_LOG2(m_param-rc.ipFactor);
@@ -282,6 +282,7 @@
 /* Adjust the first frame in order to stabilize the quality level
compared to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param-rc.rfConstant
 for (int i = 0; i  3; i++)
 m_lastQScaleFor[i] = x265_qp2qScale(m_param-rc.rateControlMode ==
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
@@ -960,10 +961,22 @@
 copyRceData(rce, m_rce2Pass[rce-poc]);
 }
 rce-isActive = true;
-if (m_sliceType == B_SLICE)
-rce-bframes = m_leadingBframes;
-else
-m_leadingBframes = curFrame-m_lowres.leadingBframes;
+bool isframeAfterKeyframe = m_sliceType != I_SLICE 
m_curSlice-m_refFrameList[0][0]-m_encData-m_slice-m_sliceType ==
I_SLICE;
+if (curFrame-m_lowres.bScenecut)
+{
+m_isSceneTransition = true;
+/* Frame Predictors and Row predictors used in vbv */
+for (int i = 0; i  4; i++)
+{
+m_pred[i].coeff = 1.0;
+m_pred[i].count = 1.0;
+m_pred[i].decay = 0.5;
+m_pred[i].offset = 0.0;
+}
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+}
+else if (m_sliceType != B_SLICE  !isframeAfterKeyframe)
+m_isSceneTransition = false;

 rce-bLastMiniGopBFrame = curFrame-m_lowres.bLastMiniGopBFrame;
 rce-bufferRate = m_bufferRate;
@@ -1040,6 +1053,10 @@
 }
 }
 }
+/* For a scenecut that occurs within the mini-gop, enable scene
transition
+ * switch until the next mini-gop to ensure a min qp for all the
frames within
+ * the scene-transition mini-gop */
+
 double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
 q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
 m_qp = int(q + 0.5);
@@ -1382,6 +1399,13 @@
 else
 q += m_pbOffset;

+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+q = X265_MAX(ABR_SCENECUT_INIT_QP_MIN, q);
+double minScenecutQscale
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN);
+m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale,
m_lastQScaleFor[P_SLICE]);
+}
 double qScale = x265_qp2qScale(q);
 rce-qpNoVbv = q;
 double lmin = 0, lmax = 0;
@@ -1544,6 +1568,13 @@
 q = X265_MIN(lqmax, q);
 }
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+   double minScenecutQscale
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN);
+   q = X265_MAX(minScenecutQscale, q);
+   m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale,
m_lastQScaleFor[P_SLICE]);
+}
 rce-qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead
estimation to avoid possible
@@ -1750,7 +1781,7 @@
 }
 /* Try to get the buffer not more than 80% filled, but
don't set an impossible goal. */
 targetFill = x265_clip3(m_bufferSize * (1 - 0.2 *
finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
-if (m_isCbr  bufferFillCur  targetFill)
+if (m_isCbr  bufferFillCur  targetFill 
!m_isSceneTransition)
 {
 q /= 1.01;
 loopTerminate |= 2;
diff -r cea0ce5bf57d -r 4f5109967676 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Wed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.h Tue Aug 11 15:27:34 2015 +0530
@@ -147,7 +147,6 @@
 double  m_pbOffset;
 int64_t m_bframeBits;
 int64_t m_currentSatd;
-int m_leadingBframes;
 int

[x265] [PATCH] rc: fix corrupted stat file issue in multipass encodes (ref #147)

2015-08-17 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1439801027 -19800
#  Mon Aug 17 14:13:47 2015 +0530
# Node ID 42ae42318a18111e2c76d1882ceb432731f6df7b
# Parent  996ebce8c874fc511d495cee227d24413e99d0c1
rc: fix corrupted stat file issue in multipass encodes (ref #147)

diff -r 996ebce8c874 -r 42ae42318a18 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Aug 17 10:52:15 2015 +0530
+++ b/source/encoder/encoder.cppMon Aug 17 14:13:47 2015 +0530
@@ -682,9 +682,13 @@
 /* Allow FrameEncoder::compressFrame() to start in the frame 
encoder thread */
 if (!curEncoder-startCompressFrame(frameEnc))
 m_aborted = true;
+/* Write RateControl Frame level stats in multipass encodes */
+if (m_param-rc.bStatWrite)
+if (m_rateControl-writeRateControlFrameStats(frameEnc, 
curEncoder-m_rce))
+m_aborted = true;
 }
 else if (m_encodedFrameNum)
-m_rateControl-setFinalFrameCount(m_encodedFrameNum);
+m_rateControl-setFinalFrameCount(m_encodedFrameNum); 
 }
 while (m_bZeroLatency  ++pass  2);
 
diff -r 996ebce8c874 -r 42ae42318a18 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Aug 17 10:52:15 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Aug 17 14:13:47 2015 +0530
@@ -2196,35 +2196,6 @@
 }
 }
 
-// Write frame stats into the stats file if 2 pass is enabled.
-if (m_param-rc.bStatWrite)
-{
-char cType = rce-sliceType == I_SLICE ? (rce-poc  0  
m_param-bOpenGOP ? 'i' : 'I')
-: rce-sliceType == P_SLICE ? 'P'
-: IS_REFERENCED(curFrame) ? 'B' : 'b';
-if (fprintf(m_statFileOut,
-in:%d out:%d type:%c q:%.2f q-aq:%.2f tex:%d mv:%d 
misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n,
-rce-poc, rce-encodeOrder,
-cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
-curFrame-m_encData-m_frameStats.coeffBits,
-curFrame-m_encData-m_frameStats.mvBits,
-curFrame-m_encData-m_frameStats.miscBits,
-curFrame-m_encData-m_frameStats.percent8x8Intra * m_ncu,
-curFrame-m_encData-m_frameStats.percent8x8Inter * m_ncu,
-curFrame-m_encData-m_frameStats.percent8x8Skip  * m_ncu) 
 0)
-goto writeFailure;
-/* Don't re-write the data in multi-pass mode. */
-if (m_param-rc.cuTree  IS_REFERENCED(curFrame)  
!m_param-rc.bStatRead)
-{
-uint8_t sliceType = (uint8_t)rce-sliceType;
-for (int i = 0; i  m_ncu; i++)
-m_cuTreeStats.qpBuffer[0][i] = 
(uint16_t)(curFrame-m_lowres.qpCuTreeOffset[i] * 256.0);
-if (fwrite(sliceType, 1, 1, m_cutreeStatFileOut)  1)
-goto writeFailure;
-if (fwrite(m_cuTreeStats.qpBuffer[0], sizeof(uint16_t), m_ncu, 
m_cutreeStatFileOut)  (size_t)m_ncu)
-goto writeFailure;
-}
-}
 if (m_isAbr  !m_isAbrReset)
 {
 /* amortize part of each I slice over the next several frames, up to
@@ -2306,12 +2277,43 @@
 // Allow rateControlStart of next frame only when rateControlEnd of 
previous frame is over
 m_startEndOrder.incr();
 return 0;
+}
 
-writeFailure:
+/* called to write out the rate control frame stats info in multipass encodes 
*/
+int RateControl::writeRateControlFrameStats(Frame* curFrame, RateControlEntry* 
rce)
+{
+FrameData curEncData = *curFrame-m_encData;
+char cType = rce-sliceType == I_SLICE ? (rce-poc  0  
m_param-bOpenGOP ? 'i' : 'I')
+: rce-sliceType == P_SLICE ? 'P'
+: IS_REFERENCED(curFrame) ? 'B' : 'b';
+if (fprintf(m_statFileOut,
+in:%d out:%d type:%c q:%.2f q-aq:%.2f tex:%d mv:%d misc:%d 
icu:%.2f pcu:%.2f scu:%.2f ;\n,
+rce-poc, rce-encodeOrder,
+cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
+curFrame-m_encData-m_frameStats.coeffBits,
+curFrame-m_encData-m_frameStats.mvBits,
+curFrame-m_encData-m_frameStats.miscBits,
+curFrame-m_encData-m_frameStats.percent8x8Intra * m_ncu,
+curFrame-m_encData-m_frameStats.percent8x8Inter * m_ncu,
+curFrame-m_encData-m_frameStats.percent8x8Skip  * m_ncu)  0)
+goto writeFailure;
+/* Don't re-write the data in multi-pass mode. */
+if (m_param-rc.cuTree  IS_REFERENCED(curFrame)  
!m_param-rc.bStatRead)
+{
+uint8_t sliceType = (uint8_t)rce-sliceType;
+for (int i = 0; i  m_ncu; i++)
+m_cuTreeStats.qpBuffer[0][i] = 
(uint16_t)(curFrame-m_lowres.qpCuTreeOffset[i] * 256.0);
+if (fwrite(sliceType, 1, 1, m_cutreeStatFileOut)  1)
+goto writeFailure;
+if (fwrite(m_cuTreeStats.qpBuffer[0], sizeof(uint16_t), m_ncu, 
m_cutreeStatFileOut)  (size_t

[x265] [PATCH 1 of 2] slicetype: Modify Scenecut algorithm to detect scene transition points

2015-08-16 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1437505166 -19800
#  Wed Jul 22 00:29:26 2015 +0530
# Node ID 51320561d41f32faa75dd3d04d88ea68500ce995
# Parent  d56b2466c04459205287e1581d8a36eebf372ba6
slicetype: Modify Scenecut algorithm to detect scene transition points
to improve Rate Control (refs #160).

identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the flag 
bSceneCut
in Lowres structure. This flag will be used by RateControl to adjust the wps 
during scene cuts.

diff -r d56b2466c044 -r 51320561d41f source/common/lowres.cpp
--- a/source/common/lowres.cpp  Wed Aug 12 18:12:20 2015 +0530
+++ b/source/common/lowres.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -126,7 +126,7 @@
 void Lowres::init(PicYuv *origPic, int poc)
 {
 bLastMiniGopBFrame = false;
-bScenecut = true;  // could be a scene-cut, until ruled out by flash 
detection
+bScenecut = false;  // could be a scene-cut, until ruled out by flash 
detection
 bKeyframe = false; // Not a keyframe unless identified by lookahead
 frameNum = poc;
 leadingBframes = 0;
diff -r d56b2466c044 -r 51320561d41f source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Wed Aug 12 18:12:20 2015 +0530
+++ b/source/encoder/slicetype.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -483,6 +483,7 @@
 m_pool  = pool;
 
 m_lastNonB = NULL;
+m_isSceneTransition = false;
 m_scratch  = NULL;
 m_tld  = NULL;
 m_filled   = false;
@@ -1267,10 +1268,16 @@
 
 int numBFrames = 0;
 int numAnalyzed = numFrames;
-if (m_param-scenecutThreshold  scenecut(frames, 0, 1, true, 
origNumFrames, maxSearch))
+
+if (m_param-bFrameAdaptive)
 {
-frames[1]-sliceType = X265_TYPE_I;
-return;
+bool isScenecut = scenecut(frames, 0, 1, true, origNumFrames);
+/* When scenecut threshold is set, use scenecut detection for I frame 
placements */
+if (!m_param-scenecutThreshold  isScenecut)
+{
+frames[1]-sliceType = X265_TYPE_I;
+return;
+}
 }
 
 if (m_param-bframes)
@@ -1357,14 +1364,13 @@
 /* Check scenecut on the first minigop. */
 for (int j = 1; j  numBFrames + 1; j++)
 {
-if (m_param-scenecutThreshold  scenecut(frames, j, j + 1, 
false, origNumFrames, maxSearch))
+if (m_param-scenecutThreshold  scenecut(frames, j, j + 1, 
false, origNumFrames))
 {
 frames[j]-sliceType = X265_TYPE_P;
 numAnalyzed = j;
 break;
 }
 }
-
 resetStart = bKeyframe ? 1 : X265_MIN(numBFrames + 2, numAnalyzed + 1);
 }
 else
@@ -1388,46 +1394,97 @@
 if (bIsVbvLookahead)
 vbvLookahead(frames, numFrames, bKeyframe);
 
+ int maxp1 = X265_MIN(m_param-bframes + 1, origNumFrames);
 /* Restore frame types for all frames that haven't actually been decided 
yet. */
 for (int j = resetStart; j = numFrames; j++)
+{
 frames[j]-sliceType = X265_TYPE_AUTO;
+/* If any frame marked as scenecut is being restarted for 
sliceDecision, 
+ * undo scene Transition flag */
+if (j = maxp1  frames[j]-bScenecut  m_isSceneTransition)
+m_isSceneTransition = false;
+}
 }
 
-bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, 
int numFrames, int maxSearch)
+bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, 
int numFrames)
 {
 /* Only do analysis during a normal scenecut check. */
 if (bRealScenecut  m_param-bframes)
 {
 int origmaxp1 = p0 + 1;
 /* Look ahead to avoid coding short flashes as scenecuts. */
-if (m_param-bFrameAdaptive == X265_B_ADAPT_TRELLIS)
-/* Don't analyse any more frames than the trellis would have 
covered. */
-origmaxp1 += m_param-bframes;
-else
-origmaxp1++;
+origmaxp1 += m_param-bframes;
 int maxp1 = X265_MIN(origmaxp1, numFrames);
-
+bool fluctuate = false;
+bool noScenecuts = false;
+int64_t avgSatdCost = 0;
+if (frames[0]-costEst[1][0]  -1)
+avgSatdCost = frames[0]-costEst[1][0];
+int cnt = 1;
 /* Where A and B are scenes: AABBBAA
  * If BBB is shorter than (maxp1-p0), it is detected as a flash
  * and not considered a scenecut. */
 for (int cp1 = p1; cp1 = maxp1; cp1++)
 {
 if (!scenecutInternal(frames, p0, cp1, false))
+{
 /* Any frame in between p0 and cur_p1 cannot be a real 
scenecut. */
 for (int i = cp1; i  p0; i--)
+{
 frames[i]-bScenecut = false;
+noScenecuts = false;
+}
+}
+else if (scenecutInternal(frames, cp1 - 1, cp1, false))
+{
+/* If current frame is a Scenecut from p0 frame as well

[x265] [PATCH 2 of 2] rc: adjust qp for scene transitions and fade ins to avoid quality loss with vbv

2015-08-16 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1439287054 -19800
#  Tue Aug 11 15:27:34 2015 +0530
# Node ID 201a9d44179524d7ef498c9fe0e69ccb83f68bc7
# Parent  51320561d41f32faa75dd3d04d88ea68500ce995
rc: adjust qp for scene transitions and fade ins to avoid quality loss with vbv

diff -r 51320561d41f -r 201a9d441795 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Aug 11 15:27:34 2015 +0530
@@ -181,6 +181,7 @@
 m_bTerminated = false;
 m_finalFrameCount = 0;
 m_numEntries = 0;
+m_isSceneTransition = false;
 if (m_param-rc.rateControlMode == X265_RC_CRF)
 {
 m_param-rc.qp = (int)m_param-rc.rfConstant;
@@ -273,7 +274,6 @@
 if(m_param-rc.bStrictCbr)
 m_rateTolerance = 0.7;
 
-m_leadingBframes = m_param-bframes;
 m_bframeBits = 0;
 m_leadingNoBSatd = 0;
 m_ipOffset = 6.0 * X265_LOG2(m_param-rc.ipFactor);
@@ -282,6 +282,7 @@
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param-rc.rfConstant
 for (int i = 0; i  3; i++)
 m_lastQScaleFor[i] = x265_qp2qScale(m_param-rc.rateControlMode == 
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
@@ -960,10 +961,22 @@
 copyRceData(rce, m_rce2Pass[rce-poc]);
 }
 rce-isActive = true;
-if (m_sliceType == B_SLICE)
-rce-bframes = m_leadingBframes;
-else
-m_leadingBframes = curFrame-m_lowres.leadingBframes;
+bool isframeAfterKeyframe = m_sliceType != I_SLICE  
m_curSlice-m_refPicList[0][0]-m_encData-m_slice-m_sliceType == I_SLICE;
+if (curFrame-m_lowres.bScenecut)
+{
+m_isSceneTransition = true;
+/* Frame Predictors and Row predictors used in vbv */
+for (int i = 0; i  4; i++)
+{
+m_pred[i].coeff = 1.0;
+m_pred[i].count = 1.0;
+m_pred[i].decay = 0.5;
+m_pred[i].offset = 0.0;
+}
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+}
+else if (m_sliceType != B_SLICE  !isframeAfterKeyframe)
+m_isSceneTransition = false;
 
 rce-bLastMiniGopBFrame = curFrame-m_lowres.bLastMiniGopBFrame;
 rce-bufferRate = m_bufferRate;
@@ -1040,6 +1053,10 @@
 }
 }
 }
+/* For a scenecut that occurs within the mini-gop, enable scene 
transition
+ * switch until the next mini-gop to ensure a min qp for all the 
frames within 
+ * the scene-transition mini-gop */
+
 double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
 q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
 m_qp = int(q + 0.5);
@@ -1382,6 +1399,13 @@
 else
 q += m_pbOffset;
 
+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+q = X265_MAX(ABR_SCENECUT_INIT_QP_MIN, q);
+double minScenecutQscale 
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN); 
+m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale, 
m_lastQScaleFor[P_SLICE]);
+}
 double qScale = x265_qp2qScale(q);
 rce-qpNoVbv = q;
 double lmin = 0, lmax = 0;
@@ -1544,6 +1568,13 @@
 q = X265_MIN(lqmax, q);
 }
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+   double minScenecutQscale 
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN); 
+   q = X265_MAX(minScenecutQscale, q);
+   m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale, 
m_lastQScaleFor[P_SLICE]);
+}
 rce-qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
@@ -1750,7 +1781,7 @@
 }
 /* Try to get the buffer not more than 80% filled, but don't 
set an impossible goal. */
 targetFill = x265_clip3(m_bufferSize * (1 - 0.2 * finalDur), 
m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
-if (m_isCbr  bufferFillCur  targetFill)
+if (m_isCbr  bufferFillCur  targetFill  
!m_isSceneTransition)
 {
 q /= 1.01;
 loopTerminate |= 2;
diff -r 51320561d41f -r 201a9d441795 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Wed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Aug 11 15:27:34 2015 +0530
@@ -147,7 +147,6 @@
 double  m_pbOffset;
 int64_t m_bframeBits;
 int64_t m_currentSatd;
-int m_leadingBframes;
 int m_qpConstant[3];
 int m_lastNonBPictType;
 int

[x265] [PATCH 1 of 2] slicetype: Modify Scenecut algorithm to detect scene transition points

2015-08-11 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1437505166 -19800
#  Wed Jul 22 00:29:26 2015 +0530
# Node ID be31c36c1f50cc46f47ebfc4b3929dee9079c9d8
# Parent  cbdefdfca87723342d21d90c41a93254553ed3d1
slicetype: Modify Scenecut algorithm to detect scene transition points
to improve Rate Control.

identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the flag 
bSceneCut
in Lowres structure. This flag will be used by RateControl to adjust the wps 
during scene cuts.

diff -r cbdefdfca877 -r be31c36c1f50 source/common/lowres.cpp
--- a/source/common/lowres.cpp  Thu Aug 06 14:23:43 2015 +0530
+++ b/source/common/lowres.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -126,7 +126,7 @@
 void Lowres::init(PicYuv *origPic, int poc)
 {
 bLastMiniGopBFrame = false;
-bScenecut = true;  // could be a scene-cut, until ruled out by flash 
detection
+bScenecut = false;  // could be a scene-cut, until ruled out by flash 
detection
 bKeyframe = false; // Not a keyframe unless identified by lookahead
 frameNum = poc;
 leadingBframes = 0;
diff -r cbdefdfca877 -r be31c36c1f50 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Thu Aug 06 14:23:43 2015 +0530
+++ b/source/encoder/slicetype.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -469,6 +469,7 @@
 m_pool  = pool;
 
 m_lastNonB = NULL;
+m_isSceneTransition = false;
 m_scratch  = NULL;
 m_tld  = NULL;
 m_filled   = false;
@@ -1253,7 +1254,7 @@
 
 int numBFrames = 0;
 int numAnalyzed = numFrames;
-if (m_param-scenecutThreshold  scenecut(frames, 0, 1, true, 
origNumFrames, maxSearch))
+if (m_param-scenecutThreshold  scenecut(frames, 0, 1, true, 
origNumFrames))
 {
 frames[1]-sliceType = X265_TYPE_I;
 return;
@@ -1343,14 +1344,13 @@
 /* Check scenecut on the first minigop. */
 for (int j = 1; j  numBFrames + 1; j++)
 {
-if (m_param-scenecutThreshold  scenecut(frames, j, j + 1, 
false, origNumFrames, maxSearch))
+if (m_param-scenecutThreshold  scenecut(frames, j, j + 1, 
false, origNumFrames))
 {
 frames[j]-sliceType = X265_TYPE_P;
 numAnalyzed = j;
 break;
 }
 }
-
 resetStart = bKeyframe ? 1 : X265_MIN(numBFrames + 2, numAnalyzed + 1);
 }
 else
@@ -1374,46 +1374,90 @@
 if (bIsVbvLookahead)
 vbvLookahead(frames, numFrames, bKeyframe);
 
+ int maxp1 = X265_MIN(m_param-bframes + 1, origNumFrames);
 /* Restore frame types for all frames that haven't actually been decided 
yet. */
 for (int j = resetStart; j = numFrames; j++)
+{
 frames[j]-sliceType = X265_TYPE_AUTO;
+/* If any frame marked as scenecut is being restarted for 
sliceDecision, 
+ * undo scene Transition flag */
+if (j = maxp1  frames[j]-bScenecut  m_isSceneTransition)
+m_isSceneTransition = false;
+}
 }
 
-bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, 
int numFrames, int maxSearch)
+bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, 
int numFrames)
 {
 /* Only do analysis during a normal scenecut check. */
 if (bRealScenecut  m_param-bframes)
 {
 int origmaxp1 = p0 + 1;
 /* Look ahead to avoid coding short flashes as scenecuts. */
-if (m_param-bFrameAdaptive == X265_B_ADAPT_TRELLIS)
-/* Don't analyse any more frames than the trellis would have 
covered. */
-origmaxp1 += m_param-bframes;
-else
-origmaxp1++;
+origmaxp1 += m_param-bframes;
 int maxp1 = X265_MIN(origmaxp1, numFrames);
-
+bool fluctuate = false;
+int64_t avgSatdCost = frames[0]-costEst[1][0];
+int cnt = 1;
 /* Where A and B are scenes: AABBBAA
  * If BBB is shorter than (maxp1-p0), it is detected as a flash
  * and not considered a scenecut. */
 for (int cp1 = p1; cp1 = maxp1; cp1++)
 {
+/* compute average satdcost of all the frames in the mini-gop to 
confirm 
+ * whether there is any great fluctuation among them to rule out 
false positives */
+avgSatdCost += frames[cp1]-costEst[cp1 - p0][0];
+cnt++;
 if (!scenecutInternal(frames, p0, cp1, false))
+{
 /* Any frame in between p0 and cur_p1 cannot be a real 
scenecut. */
 for (int i = cp1; i  p0; i--)
+{
 frames[i]-bScenecut = false;
+fluctuate = false;
+}
+}
+else
+{
+frames[cp1]-bScenecut = true;
+fluctuate = true;
+}
 }
+/* Identify possible scene fluctuations by comparing the satd cost of 
the frames.
+ * This could denote the beginning or ending of scene transitions

[x265] [PATCH 2 of 2] rc: adjust qp for scene transitions and fade ins to avoid quality loss with vbv

2015-07-28 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1438068899 -19800
#  Tue Jul 28 13:04:59 2015 +0530
# Node ID 26435f1f57e81f68a3eea244c10b06ede3570a18
# Parent  2a901547b3b8ebed95a4580ff4bcbc2582e55437
rc: adjust qp for scene transitions and fade ins to avoid quality loss with vbv

diff -r 2a901547b3b8 -r 26435f1f57e8 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Jul 28 13:04:59 2015 +0530
@@ -181,6 +181,7 @@
 m_bTerminated = false;
 m_finalFrameCount = 0;
 m_numEntries = 0;
+m_isSceneTransition = false;
 if (m_param-rc.rateControlMode == X265_RC_CRF)
 {
 m_param-rc.qp = (int)m_param-rc.rfConstant;
@@ -273,7 +274,7 @@
 if(m_param-rc.bStrictCbr)
 m_rateTolerance = 0.7;
 
-m_leadingBframes = m_param-bframes;
+m_numFramesInMiniGop = 0;
 m_bframeBits = 0;
 m_leadingNoBSatd = 0;
 m_ipOffset = 6.0 * X265_LOG2(m_param-rc.ipFactor);
@@ -282,6 +283,7 @@
 /* Adjust the first frame in order to stabilize the quality level compared 
to the rest */
 #define ABR_INIT_QP_MIN (24)
 #define ABR_INIT_QP_MAX (40)
+#define ABR_SCENECUT_INIT_QP_MIN (12)
 #define CRF_INIT_QP (int)m_param-rc.rfConstant
 for (int i = 0; i  3; i++)
 m_lastQScaleFor[i] = x265_qp2qScale(m_param-rc.rateControlMode == 
X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);
@@ -960,10 +962,11 @@
 copyRceData(rce, m_rce2Pass[rce-poc]);
 }
 rce-isActive = true;
-if (m_sliceType == B_SLICE)
-rce-bframes = m_leadingBframes;
-else
-m_leadingBframes = curFrame-m_lowres.leadingBframes;
+bool isframeAfterKeyframe = m_sliceType != I_SLICE  
m_curSlice-m_refPicList[0][0]-m_encData-m_slice-m_sliceType == I_SLICE;
+if (curFrame-m_lowres.bSceneChange  m_param-scenecutThreshold)
+m_isSceneTransition = true;
+else if (m_sliceType != B_SLICE  !isframeAfterKeyframe)
+m_isSceneTransition = false;
 
 rce-bLastMiniGopBFrame = curFrame-m_lowres.bLastMiniGopBFrame;
 rce-bufferRate = m_bufferRate;
@@ -1040,6 +1043,10 @@
 }
 }
 }
+/* For a scenecut that occurs within the mini-gop, enable scene 
transition
+ * switch until the next mini-gop to ensure a min qp for all the 
frames within 
+ * the scene-transition mini-gop */
+
 double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
 q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
 m_qp = int(q + 0.5);
@@ -1382,6 +1389,13 @@
 else
 q += m_pbOffset;
 
+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+q = X265_MAX(ABR_SCENECUT_INIT_QP_MIN, q);
+double minScenecutQscale 
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN); 
+m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale, 
m_lastQScaleFor[P_SLICE]);
+}
 double qScale = x265_qp2qScale(q);
 rce-qpNoVbv = q;
 double lmin = 0, lmax = 0;
@@ -1544,6 +1558,13 @@
 q = X265_MIN(lqmax, q);
 }
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+/* Set a min qp at scenechanges and transitions */
+if (m_isSceneTransition)
+{
+   double minScenecutQscale 
=x265_qp2qScale(ABR_SCENECUT_INIT_QP_MIN); 
+   q = X265_MAX(minScenecutQscale, q);
+   m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale, 
m_lastQScaleFor[P_SLICE]);
+}
 rce-qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
@@ -1750,7 +1771,7 @@
 }
 /* Try to get the buffer not more than 80% filled, but don't 
set an impossible goal. */
 targetFill = x265_clip3(m_bufferSize * (1 - 0.2 * finalDur), 
m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
-if (m_isCbr  bufferFillCur  targetFill)
+if (m_isCbr  bufferFillCur  targetFill  
!m_isSceneTransition)
 {
 q /= 1.01;
 loopTerminate |= 2;
diff -r 2a901547b3b8 -r 26435f1f57e8 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Wed Jul 22 00:29:26 2015 +0530
+++ b/source/encoder/ratecontrol.h  Tue Jul 28 13:04:59 2015 +0530
@@ -147,7 +147,7 @@
 double  m_pbOffset;
 int64_t m_bframeBits;
 int64_t m_currentSatd;
-int m_leadingBframes;
+int m_numFramesInMiniGop;
 int m_qpConstant[3];
 int m_lastNonBPictType;
 int m_framesDone;/* # of frames passed through RateCotrol 
already */
@@ -173,6 +173,7 @@
 int64_t m_lastBsliceSatdCost;
 int m_numBframesInPattern;
 boolm_isPatternPresent;
+boolm_isSceneTransition

[x265] [PATCH 1 of 2] slicetype: Modify Scenecut algorithm to detect scene transition points

2015-07-28 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1437505166 -19800
#  Wed Jul 22 00:29:26 2015 +0530
# Node ID 2a901547b3b8ebed95a4580ff4bcbc2582e55437
# Parent  46152345eb6ff261fd90272f7a0712300d6324c0
slicetype: Modify Scenecut algorithm to detect scene transition points
to improve Rate Control.

identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the flag 
bSceneChange
in Lowres structure. This flag will be used by RateControl to adjust the wps 
during scene cuts.
No changes in sliceType decisions or I frame placement.

diff -r 46152345eb6f -r 2a901547b3b8 source/common/lowres.cpp
--- a/source/common/lowres.cpp  Mon Jul 20 17:18:54 2015 -0700
+++ b/source/common/lowres.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -127,6 +127,7 @@
 {
 bLastMiniGopBFrame = false;
 bScenecut = true;  // could be a scene-cut, until ruled out by flash 
detection
+bSceneChange = true;
 bKeyframe = false; // Not a keyframe unless identified by lookahead
 frameNum = poc;
 leadingBframes = 0;
diff -r 46152345eb6f -r 2a901547b3b8 source/common/lowres.h
--- a/source/common/lowres.hMon Jul 20 17:18:54 2015 -0700
+++ b/source/common/lowres.hWed Jul 22 00:29:26 2015 +0530
@@ -115,6 +115,7 @@
 intleadingBframes;   // number of leading B frames for P or I
 
 bool   bScenecut;// Set to false if the frame cannot possibly be 
part of a real scenecut.
+bool   bSceneChange;
 bool   bKeyframe;
 bool   bLastMiniGopBFrame;
 
diff -r 46152345eb6f -r 2a901547b3b8 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Mon Jul 20 17:18:54 2015 -0700
+++ b/source/encoder/slicetype.cpp  Wed Jul 22 00:29:26 2015 +0530
@@ -462,6 +462,7 @@
 m_pool  = pool;
 
 m_lastNonB = NULL;
+m_isSceneTransition = false;
 m_scratch  = NULL;
 m_tld  = NULL;
 m_filled   = false;
@@ -881,6 +882,8 @@
 
 if (/* (!param-intraRefresh || frm.frameNum == 0)  */ frm.frameNum 
- m_lastKeyframe = m_param-keyframeMax)
 {
+if (frm.sliceType != X265_TYPE_I)
+frm.bSceneChange = false; 
 if (frm.sliceType == X265_TYPE_AUTO || frm.sliceType == 
X265_TYPE_I)
 frm.sliceType = m_param-bOpenGOP  m_lastKeyframe = 0 ? 
X265_TYPE_I : X265_TYPE_IDR;
 bool warn = frm.sliceType != X265_TYPE_IDR;
@@ -1375,6 +1378,9 @@
 bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, 
int numFrames, int maxSearch)
 {
 /* Only do analysis during a normal scenecut check. */
+int64_t avgSatdCost = 0;
+int cnt = 0;
+
 if (bRealScenecut  m_param-bframes)
 {
 int origmaxp1 = p0 + 1;
@@ -1392,11 +1398,45 @@
 for (int cp1 = p1; cp1 = maxp1; cp1++)
 {
 if (!scenecutInternal(frames, p0, cp1, false))
+{
 /* Any frame in between p0 and cur_p1 cannot be a real 
scenecut. */
 for (int i = cp1; i  p0; i--)
+{
 frames[i]-bScenecut = false;
+frames[i]-bSceneChange = false;
+}
+}
+else if (!scenecutInternal(frames,cp1 - 1, cp1, false))
+{
+/* Prevent false flashes. */
+frames[cp1]-bSceneChange = false;
+}
+else
+{
+/* compute average satdcost of flashes of scenecuts to confirm 
+ * bwhether a scene transition is possible within the segment. 
*/
+avgSatdCost += frames[cp1]-costEst[1][0];
+cnt++;
+}
 }
-
+/* Identify possible scene fluctuations by comparing the satd cost of 
the flashes.
+ * This could denote the beginning or ending of scene transitions.
+ * During a scene transition(fade in/fade outs), if fluctuate remains 
false,
+ * then the scene had completed its transition or stabilized. 
+ */
+bool fluctuate = false;
+if (avgSatdCost  0)
+{
+avgSatdCost /= cnt;
+for (int i= p1 ; i = maxp1; i++)
+{
+if (abs(frames[i]-costEst[1][0] - avgSatdCost)   0.1 * 
avgSatdCost)
+{
+fluctuate = true;
+break;
+}
+}
+}
 /* Where A-F are scenes: ABBCCDDEEFF
  * If each of BB ... EE are shorter than (maxp1-p0), they are
  * detected as flashes and not considered scenecuts.
@@ -1405,8 +1445,25 @@
 for (int cp0 = p0; cp0 = maxp1; cp0++)
 {
 if (origmaxp1  maxSearch || (cp0  maxp1  
scenecutInternal(frames, cp0, maxp1, false)))
+{
 /* If cur_p0 is the p0 of a scenecut, it cannot be the p1 of a 
scenecut. */
 frames[cp0]-bScenecut = false;
+/* Check for start of flash sequence for a new scene 
transition segment

Re: [x265] [PATCH] slicetype: Modify Scenecut algorithm to detect scene transition points

2015-07-22 Thread Aarthi Priya Thirumalai
Currently during scene change transitions, esp slow gradual
fadeins/fadeouts every frame changes vastly in luma intensity and hence
passes as a scenecut but these are  treated
as a series of flashes in scenecut() . So, none of the frames gets marked
as scencut during such transitions.
It would be better if we can signal the first frame of such transition
flashes as sceneChange for RateControl. so that the rate control can set a
minimum qp for such frames.
This would help the bitrate spikes at fade ins where the qp can be really
low.

The patch mainly fixes the place in scenecut() where the flash detection
happens and the first frame in a series of flash is signaled as
sceneChange.
Changing bias or modifying scenecutInterval doesn't help here as those
frames are already ,marked as scenecuts from those function.
Only scencut() flash detection part reverts the flashes as non-scenecuts
which we are changing.

the slicetype decision is not changed as I am signalling these scene
changes with a different flag that Ratecontrol would be using.


On Wed, Jul 22, 2015 at 10:10 PM, Deepthi Nandakumar 
deep...@multicorewareinc.com wrote:

 The intention was to separate slicetype decision from scene change
 detection, where scene change detection would also account for transitions
 (like fade-ins, fade-outs etc), in addition to the abrupt scene change.

 It is not clear to me how this is being done without modifying
 scenecutInternal.

 On Wed, Jul 22, 2015 at 9:59 PM, Steve Borho st...@borho.org wrote:

 On 07/22, aar...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Aarthi Thirumalai
  # Date 1437505166 -19800
  #  Wed Jul 22 00:29:26 2015 +0530
  # Node ID f134920ac855af45f052ccd6d3c239d39940a100
  # Parent  46152345eb6ff261fd90272f7a0712300d6324c0
  slicetype: Modify Scenecut algorithm to detect scene transition points
  to improve Rate Control.
 
  identify scene trasitions, fade-ins, fadeouts, sceneCuts and signal the
 flag bSceneChange
  in Lowres structure. This flag will be used by RateControl to adjust
 the wps during scene cuts.
  No changes in sliceType decisions or I frame placement.

 I could nitpick a few coding style issues, but my main question is
 whether you tried disabling the keyframe distance bias during flash
 detection and arrived at this approach, or whether this is an orthogonal
 change?

  diff -r 46152345eb6f -r f134920ac855 source/common/lowres.cpp
  --- a/source/common/lowres.cppMon Jul 20 17:18:54 2015 -0700
  +++ b/source/common/lowres.cppWed Jul 22 00:29:26 2015 +0530
  @@ -127,6 +127,7 @@
   {
   bLastMiniGopBFrame = false;
   bScenecut = true;  // could be a scene-cut, until ruled out by
 flash detection
  +bSceneChange = true;
   bKeyframe = false; // Not a keyframe unless identified by lookahead
   frameNum = poc;
   leadingBframes = 0;
  diff -r 46152345eb6f -r f134920ac855 source/common/lowres.h
  --- a/source/common/lowres.h  Mon Jul 20 17:18:54 2015 -0700
  +++ b/source/common/lowres.h  Wed Jul 22 00:29:26 2015 +0530
  @@ -115,6 +115,7 @@
   intleadingBframes;   // number of leading B frames for P or I
 
   bool   bScenecut;// Set to false if the frame cannot
 possibly be part of a real scenecut.
  +bool   bSceneChange;
   bool   bKeyframe;
   bool   bLastMiniGopBFrame;
 
  diff -r 46152345eb6f -r f134920ac855 source/encoder/slicetype.cpp
  --- a/source/encoder/slicetype.cppMon Jul 20 17:18:54 2015 -0700
  +++ b/source/encoder/slicetype.cppWed Jul 22 00:29:26 2015 +0530
  @@ -462,6 +462,7 @@
   m_pool  = pool;
 
   m_lastNonB = NULL;
  +m_isSceneTransition = false;
   m_scratch  = NULL;
   m_tld  = NULL;
   m_filled   = false;
  @@ -1375,6 +1376,8 @@
   bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool
 bRealScenecut, int numFrames, int maxSearch)
   {
   /* Only do analysis during a normal scenecut check. */
  +int64_t avgSatdCost = 0;
  +int cnt = 0;
   if (bRealScenecut  m_param-bframes)
   {
   int origmaxp1 = p0 + 1;
  @@ -1392,11 +1395,45 @@
   for (int cp1 = p1; cp1 = maxp1; cp1++)
   {
   if (!scenecutInternal(frames, p0, cp1, false))
  +{
   /* Any frame in between p0 and cur_p1 cannot be a real
 scenecut. */
   for (int i = cp1; i  p0; i--)
  +{
   frames[i]-bScenecut = false;
  +frames[i]-bSceneChange = false;
  +}
  +}
  +else if (!scenecutInternal(frames,cp1 - 1, cp1, false))
  +{
  +/* Prevent false flashes. */
  +frames[cp1]-bSceneChange = false;
  +}
  +else
  +{
  +/* compute average satdcost of flashes of scenecuts to
 confirm
  + * bwhether a scene transition is possible within the
 segment

[x265] [PATCH] rc: fixes inconsistent output in linux because of RC Lock in CQP/CRF

2015-06-29 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1435312791 -19800
#  Fri Jun 26 15:29:51 2015 +0530
# Node ID 2dac97717742d6187df7798bdfbd8a9f04e6f446
# Parent  f7bbb04e1992a238aee739a0e21777932c1dfa57
rc: fixes inconsistent output in linux because of RC Lock in CQP/CRF

the inconsistency is due to a race hazrd in slice context initializations when 
2 Frame Encoders complete
RateControlStart in correct order but slice context initializations in the 
wrong order in CRF/CQP.

diff -r f7bbb04e1992 -r 2dac97717742 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Fri Jun 26 10:16:29 2015 +0530
+++ b/source/encoder/frameencoder.cpp   Fri Jun 26 15:29:51 2015 +0530
@@ -474,6 +474,19 @@
 m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs);
 }
 
+/* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to 
+ * tune RateControl parameters for other frames.
+ * Hence, for these modes, update m_startEndOrder and unlock RC for 
previous threads waiting in
+ * RateControlEnd here, after the slicecontexts are initialized. For the 
rest - ABR
+ * and VBV, unlock only after rateControlUpdateStats of this frame is 
called */
+if (m_param-rc.rateControlMode != X265_RC_ABR  
!m_top-m_rateControl-m_isVbv)
+{
+m_top-m_rateControl-m_startEndOrder.incr();
+
+if (m_rce.encodeOrder  m_param-frameNumThreads - 1)
+m_top-m_rateControl-m_startEndOrder.incr(); // faked 
rateControlEnd calls for negative frames
+}
+
 /* Analyze CTU rows, most of the hard work is done here.  Frame is
  * compressed in a wave-front pattern if WPP is enabled. Row based loop
  * filters runs behind the CTU compression and reconstruction */
diff -r f7bbb04e1992 -r 2dac97717742 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Jun 26 10:16:29 2015 +0530
+++ b/source/encoder/ratecontrol.cppFri Jun 26 15:29:51 2015 +0530
@@ -1087,18 +1087,6 @@
 }
 m_framesDone++;
 
-/* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to 
- * tune RateControl parameters for other frames.
- * Hence, for these modes, update m_startEndOrder and unlock RC for 
previous threads waiting in
- * RateControlEnd here.those modes here. For the rest - ABR
- * and VBV, unlock only after rateControlUpdateStats of this frame is 
called */
-if (m_param-rc.rateControlMode != X265_RC_ABR  !m_isVbv)
-{
-m_startEndOrder.incr();
-
-if (rce-encodeOrder  m_param-frameNumThreads - 1)
-m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
-}
 return m_qp;
 }
 
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: fixes inconsistent output in linux because of RC Lock issue in CQP/CRF

2015-06-26 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1434973816 -19800
#  Mon Jun 22 17:20:16 2015 +0530
# Node ID 1c6744174bfcfc031492c041243e1d9a9c02a5cd
# Parent  1e5c4d155ab85e8e8dd199bb3515801766ea9e88
rc: fixes inconsistent output in linux because of RC Lock issue in CQP/CRF

diff -r 1e5c4d155ab8 -r 1c6744174bfc source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Thu Jun 25 13:42:29 2015 +0530
+++ b/source/encoder/frameencoder.cpp   Mon Jun 22 17:20:16 2015 +0530
@@ -1056,18 +1056,26 @@
 rowCount = X265_MIN((m_numRows + 1) / 2, m_numRows - 1);
 else
 rowCount = X265_MIN(m_refLagRows, m_numRows - 1);
-if (row == rowCount)
+}
+if (row == rowCount)
+{
+m_rce.rowTotalBits = 0;
+if (m_param-rc.rateControlMode == X265_RC_ABR || bIsVbv)
 {
-m_rce.rowTotalBits = 0;
 if (bIsVbv)
 for (uint32_t i = 0; i  rowCount; i++)
 m_rce.rowTotalBits += curEncData.m_rowStat[i].encodedBits;
 else
 for (uint32_t cuAddr = 0; cuAddr  rowCount * numCols; 
cuAddr++)
 m_rce.rowTotalBits += 
curEncData.m_cuStat[cuAddr].totalBits;
-
 m_top-m_rateControl-rateControlUpdateStats(m_rce);
 }
+/* do not allow the next frame to enter rateControlStart() until this
+ * frame has updated its mid-frame statistics */
+m_top-m_rateControl-m_startEndOrder.incr();
+
+if (m_rce.encodeOrder  m_param-frameNumThreads - 1)
+m_top-m_rateControl-m_startEndOrder.incr(); // faked 
rateControlEnd calls for negative frames
 }
 
 /* flush row bitstream (if WPP and no SAO) or flush frame if no WPP and no 
SAO */
diff -r 1e5c4d155ab8 -r 1c6744174bfc source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppThu Jun 25 13:42:29 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Jun 22 17:20:16 2015 +0530
@@ -1086,19 +1086,6 @@
 }
 }
 m_framesDone++;
-
-/* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to 
- * tune RateControl parameters for other frames.
- * Hence, for these modes, update m_startEndOrder and unlock RC for 
previous threads waiting in
- * RateControlEnd here.those modes here. For the rest - ABR
- * and VBV, unlock only after rateControlUpdateStats of this frame is 
called */
-if (m_param-rc.rateControlMode != X265_RC_ABR  !m_isVbv)
-{
-m_startEndOrder.incr();
-
-if (rce-encodeOrder  m_param-frameNumThreads - 1)
-m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
-}
 return m_qp;
 }
 
@@ -1625,16 +1612,6 @@
 
 m_cplxrSum += rce-rowCplxrSum;
 m_totalBits += rce-rowTotalBits;
-
-/* do not allow the next frame to enter rateControlStart() until this
- * frame has updated its mid-frame statistics */
-if (m_param-rc.rateControlMode == X265_RC_ABR || m_isVbv)
-{
-m_startEndOrder.incr();
-
-if (rce-encodeOrder  m_param-frameNumThreads - 1)
-m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
-}
 }
 
 void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 6 of 7] reconfig: add more params

2015-05-05 Thread aarthi
# HG changeset patch
# User Deepthi Nandakumar deep...@multicorewareinc.com
# Date 1427589981 -19800
#  Sun Mar 29 06:16:21 2015 +0530
# Node ID 89b32a040dda4cf836d9921a3d529b847f2791ab
# Parent  8c77520681ab0bc1124b79e18299d3cbc12616a1
reconfig: add more params

diff -r 8c77520681ab -r 89b32a040dda source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppThu Mar 26 15:15:22 2015 +0530
+++ b/source/encoder/encoder.cppSun Mar 29 06:16:21 2015 +0530
@@ -757,6 +757,9 @@
 encParam-bEnableTSkipFast = param-bEnableTSkipFast;
 encParam-psyRd = param-psyRd;
 encParam-psyRdoq = param-psyRdoq;
+encParam-bEnableSignHiding = param-bEnableSignHiding;
+encParam-bEnableFastIntra = param-bEnableFastIntra;
+encParam-maxTUSize = param-maxTUSize;
 return x265_check_params(encParam);
 }
 
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 4 of 7] api: introduce api to reconfigure encoder param

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427257989 -19800
#  Wed Mar 25 10:03:09 2015 +0530
# Node ID 0c09d2320a9283c1a940043132415d82d4976f3f
# Parent  303a09b9cb9419564804c3b79bca3caa61e07e82
api: introduce api to reconfigure encoder param

diff -r 303a09b9cb94 -r 0c09d2320a92 doc/reST/api.rst
--- a/doc/reST/api.rst  Wed Mar 25 11:53:44 2015 +0530
+++ b/doc/reST/api.rst  Wed Mar 25 10:03:09 2015 +0530
@@ -173,6 +173,21 @@
 *  (e.g. filenames) should not be modified by the calling 
application. */
void x265_encoder_parameters(x265_encoder *, x265_param *); 
 
 
+**x265_encoder_reconfig()** may be used to reconfigure encoder parameters::
+
+   /* x265_encoder_reconfig:
+   *   used to modify encoder parameters.
+*  various parameters from x265_param are copied.
+*  this takes effect immediately, on whichever frame is encoded 
next;
+*  returns 0 on success, negative on parameter validation error.
+*  not all parameters can be changed; see the actual function for 
a detailed breakdown.
+*  since not all parameters can be changed, moving from preset to 
preset may not always
+*  fully copy all relevant parameters, but should still work 
usably in practice. however,
+*  more so than for other presets, many of the speed shortcuts 
used in ultrafast cannot be
+*  switched out of; using reconfig to switch between ultrafast and 
other presets is not
+*  recommended without a more fine-grained breakdown of parameters 
to take this into account. */
+   int x265_encoder_reconfig(x265_encoder *, x265_param *);
+   
 Pictures
 
 
diff -r 303a09b9cb94 -r 0c09d2320a92 source/CMakeLists.txt
--- a/source/CMakeLists.txt Wed Mar 25 11:53:44 2015 +0530
+++ b/source/CMakeLists.txt Wed Mar 25 10:03:09 2015 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 57)
+set(X265_BUILD 58)
 configure_file(${PROJECT_SOURCE_DIR}/x265.def.in
${PROJECT_BINARY_DIR}/x265.def)
 configure_file(${PROJECT_SOURCE_DIR}/x265_config.h.in
diff -r 303a09b9cb94 -r 0c09d2320a92 source/encoder/api.cpp
--- a/source/encoder/api.cppWed Mar 25 11:53:44 2015 +0530
+++ b/source/encoder/api.cppWed Mar 25 10:03:09 2015 +0530
@@ -123,6 +123,24 @@
 }
 
 extern C
+int x265_encoder_reconfig(x265_encoder *enc, x265_param *param_in)
+{
+if (!enc || !param_in)
+return -1;
+
+Encoder *encoder = static_castEncoder*(enc);
+x265_param* safe = X265_MALLOC(x265_param, 1);
+memcpy(safe, encoder-m_latestParam, sizeof(x265_param));
+int ret = encoder-reconfigureParam(encoder-m_latestParam, param_in);
+if (!ret)
+encoder-m_reconfigured = true;
+else
+memcpy(encoder-m_latestParam, safe, sizeof(x265_param));
+X265_FREE(safe);
+return ret;
+}
+
+extern C
 int x265_encoder_encode(x265_encoder *enc, x265_nal **pp_nal, uint32_t 
*pi_nal, x265_picture *pic_in, x265_picture *pic_out)
 {
 if (!enc)
diff -r 303a09b9cb94 -r 0c09d2320a92 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppWed Mar 25 11:53:44 2015 +0530
+++ b/source/encoder/encoder.cppWed Mar 25 10:03:09 2015 +0530
@@ -58,6 +58,7 @@
 Encoder::Encoder()
 {
 m_aborted = false;
+m_reconfigured = false;
 m_encodedFrameNum = 0;
 m_pocLast = -1;
 m_curEncoder = 0;
@@ -448,7 +449,8 @@
 if (m_dpb-m_freeList.empty())
 {
 inFrame = new Frame;
-if (inFrame-create(m_param))
+x265_param* p = m_reconfigured? m_latestParam : m_param;
+if (inFrame-create(p))
 {
 /* the first PicYuv created is asked to generate the CU and 
block unit offset
  * arrays which are then shared with all subsequent PicYuv 
(orig and recon) 
@@ -501,6 +503,7 @@
 inFrame-m_userData  = pic_in-userData;
 inFrame-m_pts   = pic_in-pts;
 inFrame-m_forceqp   = pic_in-forceqp;
+inFrame-m_param = m_reconfigured ? m_latestParam : m_param;
 
 if (m_pocLast == 0)
 m_firstPts = inFrame-m_pts;
@@ -732,6 +735,32 @@
 return ret;
 }
 
+int Encoder::reconfigureParam(x265_param* encParam, x265_param* param)
+{
+int width = 0, height = 0;
+encParam-maxNumReferences = param-maxNumReferences; // but never uses 
more refs than initially specified
+encParam-bEnableLoopFilter = param-bEnableLoopFilter;
+encParam-deblockingFilterTCOffset = param-deblockingFilterTCOffset;
+encParam-deblockingFilterBetaOffset = param-deblockingFilterBetaOffset; 
+encParam-bEnableFastIntra = param-bEnableFastIntra;
+encParam-bEnableEarlySkip = param-bEnableEarlySkip;
+encParam-bEnableTemporalMvp = param

[x265] [PATCH 7 of 7] param: add function to print reconfigured param options

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427796515 -19800
#  Tue Mar 31 15:38:35 2015 +0530
# Node ID 3285714d7c3bee8e5a843894a2b7daa0d6b7718b
# Parent  89b32a040dda4cf836d9921a3d529b847f2791ab
param: add function to print reconfigured param options

diff -r 89b32a040dda -r 3285714d7c3b source/common/param.cpp
--- a/source/common/param.cpp   Sun Mar 29 06:16:21 2015 +0530
+++ b/source/common/param.cpp   Tue Mar 31 15:38:35 2015 +0530
@@ -1335,6 +1335,42 @@
 fflush(stderr);
 }
 
+void x265_print_reconfigured_params(x265_param* param, x265_param* 
reconfiguredParam)
+{
+if (param  reconfiguredParam)
+{
+x265_log(param,X265_LOG_INFO, Reconfigured param options :\n);
+char buf[80] = { 0 };
+char tmp[40];
+#define TOOLCMP(COND1, COND2, STR, VAL)  if (COND1 != COND2) { sprintf(tmp, 
STR, VAL); appendtool(param, buf, sizeof(buf), tmp); }
+TOOLCMP(param-maxNumReferences, reconfiguredParam-maxNumReferences, 
ref=%d, reconfiguredParam-maxNumReferences);
+TOOLCMP(param-maxTUSize, reconfiguredParam-maxTUSize, 
max-tu-size=%d, reconfiguredParam-maxTUSize);
+TOOLCMP(param-searchRange, reconfiguredParam-searchRange, 
merange=%d, reconfiguredParam-searchRange);
+TOOLCMP(param-subpelRefine, reconfiguredParam-subpelRefine, subme= 
%d, reconfiguredParam-subpelRefine);
+TOOLCMP(param-rdLevel, reconfiguredParam-rdLevel, rd=%d, 
reconfiguredParam-rdLevel);
+TOOLCMP(param-psyRd, reconfiguredParam-psyRd, psy-rd=%.2lf, 
reconfiguredParam-psyRd);
+TOOLCMP(param-rdoqLevel, reconfiguredParam-rdoqLevel, rdoq=%d, 
reconfiguredParam-rdoqLevel);
+TOOLCMP(param-psyRdoq, reconfiguredParam-psyRdoq, psy-rdoq=%.2lf, 
reconfiguredParam-psyRdoq);
+TOOLCMP(param-noiseReductionIntra, 
reconfiguredParam-noiseReductionIntra, nr-intra=%d, 
reconfiguredParam-noiseReductionIntra);
+TOOLCMP(param-noiseReductionInter, 
reconfiguredParam-noiseReductionInter, nr-inter=%d, 
reconfiguredParam-noiseReductionInter);
+TOOLCMP(param-bEnableTSkipFast, reconfiguredParam-bEnableTSkipFast, 
tskip-fast=%d, reconfiguredParam-bEnableTSkipFast);
+TOOLCMP(param-bEnableSignHiding, 
reconfiguredParam-bEnableSignHiding, signhide=%d, 
reconfiguredParam-bEnableSignHiding);
+TOOLCMP(param-bEnableFastIntra, reconfiguredParam-bEnableFastIntra, 
fast-intra=%d, reconfiguredParam-bEnableFastIntra);
+if (param-bEnableLoopFilter  (param-deblockingFilterBetaOffset != 
reconfiguredParam-deblockingFilterBetaOffset 
+|| param-deblockingFilterTCOffset != 
reconfiguredParam-deblockingFilterTCOffset))
+{
+sprintf(tmp, deblock(tC=%d:B=%d), 
param-deblockingFilterTCOffset, param-deblockingFilterBetaOffset);
+appendtool(param, buf, sizeof(buf), tmp);
+}
+else
+TOOLCMP(param-bEnableLoopFilter,  
reconfiguredParam-bEnableLoopFilter, deblock=%d, 
reconfiguredParam-bEnableLoopFilter);
+
+TOOLCMP(param-bEnableTemporalMvp, 
reconfiguredParam-bEnableTemporalMvp, tmvp=%d, 
reconfiguredParam-bEnableTemporalMvp);
+TOOLCMP(param-bEnableEarlySkip, reconfiguredParam-bEnableEarlySkip, 
early-skip=%d, reconfiguredParam-bEnableEarlySkip);
+x265_log(param, X265_LOG_INFO, tools:%s\n, buf);
+}
+}
+
 char *x265_param2string(x265_param* p)
 {
 char *buf, *s;
diff -r 89b32a040dda -r 3285714d7c3b source/common/param.h
--- a/source/common/param.h Sun Mar 29 06:16:21 2015 +0530
+++ b/source/common/param.h Tue Mar 31 15:38:35 2015 +0530
@@ -28,6 +28,7 @@
 int   x265_check_params(x265_param *param);
 int   x265_set_globals(x265_param *param);
 void  x265_print_params(x265_param *param);
+void  x265_print_reconfigured_params(x265_param* param, x265_param* 
reconfiguredParam);
 void  x265_param_apply_fastfirstpass(x265_param *p);
 char* x265_param2string(x265_param *param);
 int   x265_atoi(const char *str, bool bError);
diff -r 89b32a040dda -r 3285714d7c3b source/encoder/api.cpp
--- a/source/encoder/api.cppSun Mar 29 06:16:21 2015 +0530
+++ b/source/encoder/api.cppTue Mar 31 15:38:35 2015 +0530
@@ -133,7 +133,10 @@
 memcpy(safe, encoder-m_latestParam, sizeof(x265_param));
 int ret = encoder-reconfigureParam(encoder-m_latestParam, param_in);
 if (!ret)
+{
 encoder-m_reconfigured = true;
+x265_print_reconfigured_params(safe, encoder-m_latestParam);
+}
 else
 memcpy(encoder-m_latestParam, safe, sizeof(x265_param));
 X265_FREE(safe);
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 5 of 7] encoder: clean up

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427363122 -19800
#  Thu Mar 26 15:15:22 2015 +0530
# Node ID 8c77520681ab0bc1124b79e18299d3cbc12616a1
# Parent  0c09d2320a9283c1a940043132415d82d4976f3f
encoder: clean up

diff -r 0c09d2320a92 -r 8c77520681ab source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppWed Mar 25 10:03:09 2015 +0530
+++ b/source/encoder/encoder.cppThu Mar 26 15:15:22 2015 +0530
@@ -737,7 +737,6 @@
 
 int Encoder::reconfigureParam(x265_param* encParam, x265_param* param)
 {
-int width = 0, height = 0;
 encParam-maxNumReferences = param-maxNumReferences; // but never uses 
more refs than initially specified
 encParam-bEnableLoopFilter = param-bEnableLoopFilter;
 encParam-deblockingFilterTCOffset = param-deblockingFilterTCOffset;
@@ -753,7 +752,7 @@
 /* We can't switch out of subme=0 during encoding. */
 if (encParam-subpelRefine)
 encParam-subpelRefine = param-subpelRefine;
-encParam-rdoqLevel = param-psyRdoq;
+encParam-rdoqLevel = param-rdoqLevel;
 encParam-rdLevel = param-rdLevel;
 encParam-bEnableTSkipFast = param-bEnableTSkipFast;
 encParam-psyRd = param-psyRd;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 1 of 7] frame: add x265_param* to each frame

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427281133 -19800
#  Wed Mar 25 16:28:53 2015 +0530
# Node ID fc12a89d17cbf231f63e7eeba4a9112d1cf0fe17
# Parent  f32e6464225afa02983af1b1905f50cdccae5244
frame: add x265_param* to each frame

The x265_param* points to encoder's param settings by default.
This design will be useful to specify parameters for each input picture 
separately.

diff -r f32e6464225a -r fc12a89d17cb source/common/frame.cpp
--- a/source/common/frame.cpp   Mon May 04 15:15:42 2015 -0500
+++ b/source/common/frame.cpp   Wed Mar 25 16:28:53 2015 +0530
@@ -38,12 +38,14 @@
 m_reconPic = NULL;
 m_next = NULL;
 m_prev = NULL;
+m_param = NULL;
 memset(m_lowres, 0, sizeof(m_lowres));
 }
 
 bool Frame::create(x265_param *param)
 {
 m_fencPic = new PicYuv;
+m_param = param;
 
 return m_fencPic-create(param-sourceWidth, param-sourceHeight, 
param-internalCsp) 
m_lowres.create(m_fencPic, param-bframes, !!param-rc.aqMode);
diff -r f32e6464225a -r fc12a89d17cb source/common/frame.h
--- a/source/common/frame.h Mon May 04 15:15:42 2015 -0500
+++ b/source/common/frame.h Wed Mar 25 16:28:53 2015 +0530
@@ -65,7 +65,7 @@
 
 Frame* m_next;   // PicList doubly linked list 
pointers
 Frame* m_prev;
-
+x265_param*m_param; // Points to the latest Param 
set for the frame.
 x265_analysis_data m_analysisData;
 Frame();
 
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 7] frameEncoder: copy param state for each FE and worker thread from input frame

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427281243 -19800
#  Wed Mar 25 16:30:43 2015 +0530
# Node ID 084e7ed97059873201ccb4762eeb9d3a55dd3238
# Parent  fc12a89d17cbf231f63e7eeba4a9112d1cf0fe17
frameEncoder: copy param state for each FE and worker thread from input frame

Each FrameEncoder gets the param from the current frame it is processing and 
all the worker threads
/bondedgrp worker threads sets the param to it's parent FrameEncoder instance.

diff -r fc12a89d17cb -r 084e7ed97059 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp   Wed Mar 25 16:28:53 2015 +0530
+++ b/source/encoder/analysis.cpp   Wed Mar 25 16:30:43 2015 +0530
@@ -348,6 +348,7 @@
 ScopedElapsedTime pmodeTime(master.m_stats[fe].pmodeTime);
 #endif
 ProfileScopeEvent(pmode);
+master.m_tld[workerThreadId].analysis.m_param = master.m_param;
 master.processPmode(*this, master.m_tld[workerThreadId].analysis);
 }
 
diff -r fc12a89d17cb -r 084e7ed97059 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Wed Mar 25 16:28:53 2015 +0530
+++ b/source/encoder/frameencoder.cpp   Wed Mar 25 16:30:43 2015 +0530
@@ -217,6 +217,7 @@
 curFrame-m_encData-m_frameEncoderID = m_jpId;
 curFrame-m_encData-m_jobProvider = this;
 curFrame-m_encData-m_slice-m_mref = m_mref;
+this-m_param = curFrame-m_param;
 
 if (!m_cuGeoms)
 {
@@ -793,7 +794,7 @@
 {
 uint32_t row = (uint32_t)intRow;
 CTURow curRow = m_rows[row];
-
+tld.analysis.m_param = m_param;
 if (m_param-bEnableWavefront)
 {
 ScopedLock self(curRow.lock);
@@ -1092,7 +1093,7 @@
 tryWakeOne();
 }
 }
-
+tld.analysis.m_param = NULL;
 curRow.busy = false;
 
 if (ATOMIC_INC(m_completionCount) == 2 * (int)m_numRows)
diff -r fc12a89d17cb -r 084e7ed97059 source/encoder/search.cpp
--- a/source/encoder/search.cpp Wed Mar 25 16:28:53 2015 +0530
+++ b/source/encoder/search.cpp Wed Mar 25 16:30:43 2015 +0530
@@ -1897,6 +1897,7 @@
 ScopedElapsedTime pmeTime(master.m_stats[fe].pmeTime);
 #endif
 ProfileScopeEvent(pme);
+master.m_tld[workerThreadId].analysis.m_param = master.m_param;
 master.processPME(*this, master.m_tld[workerThreadId].analysis);
 }
 
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 3 of 7] encoder: introduce an instance to hold the latest param setting in the encoder

2015-05-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427264624 -19800
#  Wed Mar 25 11:53:44 2015 +0530
# Node ID 303a09b9cb9419564804c3b79bca3caa61e07e82
# Parent  084e7ed97059873201ccb4762eeb9d3a55dd3238
encoder: introduce an instance to hold the latest param setting in the encoder

this will be used to hold the latest param options when dynamically 
reconfiguring the encoder parameters

diff -r 084e7ed97059 -r 303a09b9cb94 source/encoder/api.cpp
--- a/source/encoder/api.cppWed Mar 25 16:30:43 2015 +0530
+++ b/source/encoder/api.cppWed Mar 25 11:53:44 2015 +0530
@@ -40,7 +40,8 @@
 return NULL;
 
 x265_param *param = X265_MALLOC(x265_param, 1);
-if (!param)
+x265_param *latestParam = X265_MALLOC(x265_param, 1);
+if (!param || !latestParam)
 return NULL;
 
 memcpy(param, p, sizeof(x265_param));
@@ -61,11 +62,11 @@
 
 // may change params for auto-detect, etc
 encoder-configure(param);
-
 // may change rate control and CPB params
 if (!enforceLevel(*param, encoder-m_vps))
 {
 delete encoder;
+x265_param_free(latestParam);
 return NULL;
 }
 
@@ -80,9 +81,12 @@
 }
 
 encoder-create();
+encoder-m_latestParam = latestParam;
+memcpy(latestParam, param, sizeof(x265_param));
 if (encoder-m_aborted)
 {
 delete encoder;
+x265_param_free(latestParam);
 return NULL;
 }
 
diff -r 084e7ed97059 -r 303a09b9cb94 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppWed Mar 25 16:30:43 2015 +0530
+++ b/source/encoder/encoder.cppWed Mar 25 11:53:44 2015 +0530
@@ -73,6 +73,7 @@
 m_outputCount = 0;
 m_csvfpt = NULL;
 m_param = NULL;
+m_latestParam = NULL;
 m_cuOffsetY = NULL;
 m_cuOffsetC = NULL;
 m_buOffsetY = NULL;
@@ -376,6 +377,8 @@
 
 X265_FREE(m_param);
 }
+if (m_latestParam)
+X265_FREE(m_latestParam);
 }
 
 void Encoder::updateVbvPlan(RateControl* rc)
diff -r 084e7ed97059 -r 303a09b9cb94 source/encoder/encoder.h
--- a/source/encoder/encoder.h  Wed Mar 25 16:30:43 2015 +0530
+++ b/source/encoder/encoder.h  Wed Mar 25 11:53:44 2015 +0530
@@ -125,6 +125,7 @@
 uint32_t   m_numDelayedPic;
 
 x265_param*m_param;
+x265_param*m_latestParam;
 RateControl*   m_rateControl;
 Lookahead* m_lookahead;
 Window m_conformanceWindow;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 0 of 7 ] api to reconfigure encoder parameters

2015-05-05 Thread aarthi

___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] log: make qTreeCnt as stack arrays to avoid non determinism in 2 pass

2015-04-28 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1430225684 -19800
#  Tue Apr 28 18:24:44 2015 +0530
# Node ID 9a66b31df0d07a7146694763de119cb2e0ca2cfa
# Parent  13290abce29209be5206cce66e436c8ff3682540
log: make qTreeCnt as stack arrays to avoid non determinism in 2 pass

currently,qTreeCount arrays collected in log stats for each sliceType is not 
protected and may cause
inconsistency in 2 pass encodes when multiple rows finish simultaneously.

diff -r 13290abce292 -r 9a66b31df0d0 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Mon Apr 27 14:15:28 2015 -0500
+++ b/source/encoder/frameencoder.cpp   Tue Apr 28 18:24:44 2015 +0530
@@ -823,7 +823,12 @@
 const uint32_t numCols = m_numCols;
 const uint32_t lineStartCUAddr = row * numCols;
 bool bIsVbv = m_param-rc.vbvBufferSize  0  m_param-rc.vbvMaxBitrate  
0;
-
+/* These states store the count of inter,intra and skip ctus within quad 
tree structure of each CU */
+uint32_t qTreeInterCnt[4];
+uint32_t qTreeIntraCnt[4];
+uint32_t qTreeSkipCnt[4];
+for (uint32_t depth = 0; depth = g_maxCUDepth; depth++)
+qTreeIntraCnt[depth] = qTreeInterCnt[depth] = qTreeSkipCnt[depth] = 0;
 while (curRow.completed  numCols)
 {
 ProfileScopeEvent(encodeCTU);
@@ -896,7 +901,7 @@
 curRow.completed++;
 
 if (m_param-bLogCuStats || m_param-rc.bStatWrite)
-curEncData.m_rowStat[row].sumQpAq += collectCTUStatistics(*ctu);
+curEncData.m_rowStat[row].sumQpAq += collectCTUStatistics(*ctu, 
qTreeInterCnt, qTreeIntraCnt, qTreeSkipCnt);
 else if (m_param-rc.aqMode)
 curEncData.m_rowStat[row].sumQpAq += calcCTUQP(*ctu);
 
@@ -906,18 +911,17 @@
 curRow.rowStats.mvBits += best.mvBits;
 curRow.rowStats.coeffBits += best.coeffBits;
 curRow.rowStats.miscBits += best.totalBits - (best.mvBits + 
best.coeffBits);
-StatisticLog* log = m_sliceTypeLog[slice-m_sliceType];
 
 for (uint32_t depth = 0; depth = g_maxCUDepth; depth++)
 {
 /* 1  shift == number of 8x8 blocks at current depth */
 int shift = 2 * (g_maxCUDepth - depth);
-curRow.rowStats.iCuCnt += log-qTreeIntraCnt[depth]  shift;
-curRow.rowStats.pCuCnt += log-qTreeInterCnt[depth]  shift;
-curRow.rowStats.skipCuCnt += log-qTreeSkipCnt[depth]  shift;
+curRow.rowStats.iCuCnt += qTreeIntraCnt[depth]  shift;
+curRow.rowStats.pCuCnt += qTreeInterCnt[depth]  shift;
+curRow.rowStats.skipCuCnt += qTreeSkipCnt[depth]  shift;
 
 // clear the row cu data from thread local object
-log-qTreeIntraCnt[depth] = log-qTreeInterCnt[depth] = 
log-qTreeSkipCnt[depth] = 0;
+qTreeIntraCnt[depth] = qTreeInterCnt[depth] = 
qTreeSkipCnt[depth] = 0;
 }
 }
 
@@ -1094,7 +1098,7 @@
 }
 
 /* collect statistics about CU coding decisions, return total QP */
-int FrameEncoder::collectCTUStatistics(const CUData ctu)
+int FrameEncoder::collectCTUStatistics(const CUData ctu, uint32_t* 
qtreeInterCnt, uint32_t* qtreeIntraCnt, uint32_t* qtreeSkipCnt)
 {
 StatisticLog* log = m_sliceTypeLog[ctu.m_slice-m_sliceType];
 int totQP = 0;
@@ -1108,14 +1112,14 @@
 
 log-totalCu++;
 log-cntIntra[depth]++;
-log-qTreeIntraCnt[depth]++;
+qtreeIntraCnt[depth]++;
 totQP += ctu.m_qp[absPartIdx] * (ctu.m_numPartitions  (depth * 
2));
 
 if (ctu.m_predMode[absPartIdx] == MODE_NONE)
 {
 log-totalCu--;
 log-cntIntra[depth]--;
-log-qTreeIntraCnt[depth]--;
+qtreeIntraCnt[depth]--;
 }
 else if (ctu.m_partSize[absPartIdx] != SIZE_2Nx2N)
 {
@@ -1150,12 +1154,12 @@
 {
 log-totalCu--;
 log-cntSkipCu[depth]++;
-log-qTreeSkipCnt[depth]++;
+qtreeSkipCnt[depth]++;
 }
 else if (ctu.isInter(absPartIdx))
 {
 log-cntInter[depth]++;
-log-qTreeInterCnt[depth]++;
+qtreeInterCnt[depth]++;
 
 if (ctu.m_partSize[absPartIdx]  AMP_ID)
 
log-cuInterDistribution[depth][ctu.m_partSize[absPartIdx]]++;
@@ -1165,7 +1169,7 @@
 else if (ctu.isIntra(absPartIdx))
 {
 log-cntIntra[depth]++;
-log-qTreeIntraCnt[depth]++;
+qtreeIntraCnt[depth]++;
 
 if (ctu.m_partSize[absPartIdx] != SIZE_2Nx2N)
 {
diff -r 13290abce292 -r 9a66b31df0d0 source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h Mon Apr 27 14:15:28 2015 -0500
+++ b/source/encoder/frameencoder.h Tue Apr 28 18:24:44 2015 +0530
@@ -63,11 +63,6 @@
 uint64_t cntTotalCu[4

Re: [x265] [PATCH 6 of 6 REV2] analysis: always configure quant QP directly after setting RD lambda

2015-04-27 Thread Aarthi Priya Thirumalai
We may remove the qp offset calculations from there but may need to use it
for collecting cu level intra and inter satdcosts
from lowres data for row vbv encodes.

On Sun, Apr 26, 2015 at 11:17 PM, Steve Borho st...@borho.org wrote:

 On Sun, Apr 26, 2015 at 12:21 PM, Steve Borho st...@borho.org wrote:
  # HG changeset patch
  # User Steve Borho st...@borho.org
  # Date 1429943995 18000
  #  Sat Apr 25 01:39:55 2015 -0500
  # Node ID 68a13226d586b335c02cade9311e093f0149c42a
  # Parent  6a0a37c01cff03cadd44691a0fe447d17ec0b14f
  analysis: always configure quant QP directly after setting RD lambda
 
  Basically, everywhere we adjust or assign QP we set quant QP
 immediately. This
  removes a great many ad-hoc calls to setQPforQuant() and hopefully makes
 it
  impossible to miss quant being configured properly.
 
  This patch fixes a layering violation where the frame encoder was
 setting the
  RDO lambdas directly, but only when delta-QP was not enabled.
 
  diff -r 6a0a37c01cff -r 68a13226d586 source/common/quant.cpp
  --- a/source/common/quant.cpp   Sat Apr 25 00:39:48 2015 -0500
  +++ b/source/common/quant.cpp   Sat Apr 25 01:39:55 2015 -0500
  @@ -225,16 +225,15 @@
   X265_FREE(m_fencShortBuf);
   }
 
  -void Quant::setQPforQuant(const CUData cu)
  +void Quant::setQPforQuant(const CUData ctu, int qp)
   {
  -m_tqBypass = !!cu.m_tqBypass[0];
  +m_tqBypass = !!ctu.m_tqBypass[0];
   if (m_tqBypass)
   return;
  -m_nr = m_frameNr ? m_frameNr[cu.m_encData-m_frameEncoderID] :
 NULL;
  -int qpy = cu.m_qp[0];
  -m_qpParam[TEXT_LUMA].setQpParam(qpy + QP_BD_OFFSET);
  -setChromaQP(qpy + cu.m_slice-m_pps-chromaQpOffset[0],
 TEXT_CHROMA_U, cu.m_chromaFormat);
  -setChromaQP(qpy + cu.m_slice-m_pps-chromaQpOffset[1],
 TEXT_CHROMA_V, cu.m_chromaFormat);
  +m_nr = m_frameNr ? m_frameNr[ctu.m_encData-m_frameEncoderID] :
 NULL;
  +m_qpParam[TEXT_LUMA].setQpParam(qp + QP_BD_OFFSET);
  +setChromaQP(qp + ctu.m_slice-m_pps-chromaQpOffset[0],
 TEXT_CHROMA_U, ctu.m_chromaFormat);
  +setChromaQP(qp + ctu.m_slice-m_pps-chromaQpOffset[1],
 TEXT_CHROMA_V, ctu.m_chromaFormat);
   }
 
   void Quant::setChromaQP(int qpin, TextType ttype, int chFmt)
  diff -r 6a0a37c01cff -r 68a13226d586 source/common/quant.h
  --- a/source/common/quant.h Sat Apr 25 00:39:48 2015 -0500
  +++ b/source/common/quant.h Sat Apr 25 01:39:55 2015 -0500
  @@ -103,7 +103,7 @@
   bool allocNoiseReduction(const x265_param param);
 
   /* CU setup */
  -void setQPforQuant(const CUData cu);
  +void setQPforQuant(const CUData ctu, int qp);
 
   uint32_t transformNxN(const CUData cu, const pixel* fenc, uint32_t
 fencStride, const int16_t* residual, uint32_t resiStride, coeff_t* coeff,
 uint32_t log2TrSize, TextType ttype, uint32_t
 absPartIdx, bool useTransformSkip);
  diff -r 6a0a37c01cff -r 68a13226d586 source/encoder/analysis.cpp
  --- a/source/encoder/analysis.cpp   Sat Apr 25 00:39:48 2015 -0500
  +++ b/source/encoder/analysis.cpp   Sat Apr 25 01:39:55 2015 -0500
  @@ -146,18 +146,16 @@
 
   if (m_slice-m_pps-bUseDQP)
   {
  -m_aqQP[0] = calculateQpforCuSize(ctu, cuGeom);
  -setLambdaFromQP(*m_slice, m_aqQP[0]);
  -m_aqQP[0] = x265_clip3(QP_MIN, QP_MAX_SPEC, m_aqQP[0]);
  -ctu.setQPSubParts((int8_t)m_aqQP[0], 0, 0);
  +m_aqQP[0] = setLambdaFromQP(ctu, calculateQpforCuSize(ctu,
 cuGeom));
 
   if (m_slice-m_pps-maxCuDQPDepth)
   initAqQPs(1, ctu, cuGeom + 1);
   }
   else
  -m_aqQP[0] = m_slice-m_sliceQp;
  +/* adaptive quant disabled, CTU QP is always slice QP, and
 within spec range */
  +m_aqQP[0] = setLambdaFromQP(ctu, m_slice-m_sliceQp);
 
  -m_quant.setQPforQuant(ctu);
  +ctu.setQPSubParts((int8_t)m_aqQP[0], 0, 0);
   m_rqt[0].cur.load(initialContext);
   m_modeDepth[0].fencYuv.copyFromPicYuv(*m_frame-m_fencPic,
 ctu.m_cuAddr, 0);
 
  @@ -231,20 +229,24 @@
   return;
   else if (md.bestMode-cu.isIntra(0))
   {
  +m_quant.m_tqBypass = true;
   md.pred[PRED_LOSSLESS].initCosts();
   md.pred[PRED_LOSSLESS].cu.initLosslessCU(md.bestMode-cu,
 cuGeom);
   PartSize size =
 (PartSize)md.pred[PRED_LOSSLESS].cu.m_partSize[0];
   uint8_t* modes = md.pred[PRED_LOSSLESS].cu.m_lumaIntraDir;
   checkIntra(md.pred[PRED_LOSSLESS], cuGeom, size, modes, NULL);
   checkBestMode(md.pred[PRED_LOSSLESS], cuGeom.depth);
  +m_quant.m_tqBypass = false;
   }
   else
   {
  +m_quant.m_tqBypass = true;
   md.pred[PRED_LOSSLESS].initCosts();
   md.pred[PRED_LOSSLESS].cu.initLosslessCU(md.bestMode-cu,
 cuGeom);
 
 md.pred[PRED_LOSSLESS].predYuv.copyFromYuv(md.bestMode-predYuv);
   encodeResAndCalcRdInterCU(md.pred[PRED_LOSSLESS], cuGeom);
   checkBestMode(md.pred[PRED_LOSSLESS], cuGeom.depth);
  +

[x265] [PATCH] rc: fix cost issues in predicting row size during mid frame vbv encodes

2015-04-26 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1429617548 -19800
#  Tue Apr 21 17:29:08 2015 +0530
# Node ID c68d582086a3a5c91c71c5e3ae3ffbf179a038b1
# Parent  4a7176bab7423d831675f0419b6470668bdbd919
rc: fix cost issues in predicting row size during mid frame vbv encodes.

diff -r 4a7176bab742 -r c68d582086a3 source/common/framedata.h
--- a/source/common/framedata.h Fri Apr 24 16:07:42 2015 -0500
+++ b/source/common/framedata.h Tue Apr 21 17:29:08 2015 +0530
@@ -74,6 +74,7 @@
 uint32_t numEncodedCUs; /* ctuAddr of last encoded CTU in row */
 uint32_t encodedBits;   /* sum of 'totalBits' of encoded CTUs */
 uint32_t satdForVbv;/* sum of lowres (estimated) costs for entire 
row */
+uint32_t intraSatdForVbv; /* sum of lowres (estimated) intra costs for 
entire row */
 uint32_t diagSatd;
 uint32_t diagIntraSatd;
 double   diagQp;
diff -r 4a7176bab742 -r c68d582086a3 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Apr 24 16:07:42 2015 -0500
+++ b/source/encoder/ratecontrol.cppTue Apr 21 17:29:08 2015 +0530
@@ -1395,6 +1395,7 @@
 q += m_pbOffset;
 
 double qScale = x265_qp2qScale(q);
+rce-qpNoVbv = q;
 double lmin = 0, lmax = 0;
 if (m_isVbv)
 {
@@ -1407,7 +1408,6 @@
 qScale = x265_clip3(lmin, lmax, qScale);
 q = x265_qScale2qp(qScale);
 }
-rce-qpNoVbv = q;
 if (!m_2pass)
 {
 qScale = clipQscale(curFrame, rce, qScale);
@@ -1858,18 +1858,26 @@
 if (satdCostForPendingCus   0)
 {
 double pred_s = predictSize(rce-rowPred[0], qScale, 
satdCostForPendingCus);
-uint32_t refRowSatdCost = 0, refRowBits = 0, intraCost = 0;
+uint32_t refRowSatdCost = 0, refRowBits = 0, 
intraCostForPendingCus = 0;
 double refQScale = 0;
 
 if (picType != I_SLICE)
 {
 FrameData refEncData = *refFrame-m_encData;
 uint32_t endCuAddr = maxCols * (row + 1);
-for (uint32_t cuAddr = curEncData.m_rowStat[row].numEncodedCUs 
+ 1; cuAddr  endCuAddr; cuAddr++)
+uint32_t startCuAddr = curEncData.m_rowStat[row].numEncodedCUs;
+if (startCuAddr)
 {
-refRowSatdCost += refEncData.m_cuStat[cuAddr].vbvCost;
-refRowBits += refEncData.m_cuStat[cuAddr].totalBits;
-intraCost += curEncData.m_cuStat[cuAddr].intraVbvCost;
+for (uint32_t cuAddr = startCuAddr + 1 ; cuAddr  
endCuAddr; cuAddr++)
+{
+refRowSatdCost += refEncData.m_cuStat[cuAddr].vbvCost;
+refRowBits += refEncData.m_cuStat[cuAddr].totalBits;
+}
+}
+else
+{
+refRowBits = refEncData.m_rowStat[row].encodedBits;
+refRowSatdCost = refEncData.m_rowStat[row].satdForVbv;
 }
 
 refRowSatdCost = X265_DEPTH - 8;
@@ -1879,7 +1887,7 @@
 if (picType == I_SLICE || qScale = refQScale)
 {
 if (picType == P_SLICE 
- !refFrame 
+ refFrame 
  refFrame-m_encData-m_slice-m_sliceType == picType
  refQScale  0
  refRowSatdCost  0)
@@ -1895,8 +1903,9 @@
 }
 else if (picType == P_SLICE)
 {
+intraCostForPendingCus = 
curEncData.m_rowStat[row].intraSatdForVbv - 
curEncData.m_rowStat[row].diagIntraSatd;
 /* Our QP is lower than the reference! */
-double pred_intra = predictSize(rce-rowPred[1], qScale, 
intraCost);
+double pred_intra = predictSize(rce-rowPred[1], qScale, 
intraCostForPendingCus);
 /* Sum: better to overestimate than underestimate by using 
only one of the two predictors. */
 totalSatdBits += (int32_t)(pred_intra + pred_s);
 }
diff -r 4a7176bab742 -r c68d582086a3 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Fri Apr 24 16:07:42 2015 -0500
+++ b/source/encoder/slicetype.cpp  Tue Apr 21 17:29:08 2015 +0530
@@ -739,7 +739,7 @@
 {
 /* aggregate lowres row satds to CTU resolution */
 curFrame-m_lowres.lowresCostForRc = curFrame-m_lowres.lowresCosts[b 
- p0][p1 - b];
-uint32_t lowresRow = 0, lowresCol = 0, lowresCuIdx = 0, sum = 0;
+uint32_t lowresRow = 0, lowresCol = 0, lowresCuIdx = 0, sum = 0, 
intraSum = 0;
 uint32_t scale = m_param-maxCUSize / (2 * X265_LOWRES_CU_SIZE);
 uint32_t numCuInHeight = (m_param-sourceHeight + g_maxCUSize - 1) / 
g_maxCUSize;
 uint32_t widthInLowresCu = (uint32_t)m_8x8Width, heightInLowresCu = 
(uint32_t)m_8x8Height

Re: [x265] [PATCH 2 of 2] rc: tune initial predictor values for better frame size predictions in vbv lookahead

2015-04-09 Thread Aarthi Priya Thirumalai
On Thu, Apr 9, 2015 at 12:09 AM, Steve Borho st...@borho.org wrote:

 On 04/08, aar...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Aarthi Thirumalai
  # Date 1426487738 -19800
  #  Mon Mar 16 12:05:38 2015 +0530
  # Node ID b4646bdaf2202748d3a3b159b9bc8e3cfcd272de
  # Parent  6f159ec858f4eec484d722916c41911e3e4540f9
  rc: tune initial predictor values for better frame size predictions in
 vbv lookahead
 
  an overall improvement in ssim of around .05-.1 db can be seen.
  Also, improves visual quality at the start of the encode.
 
  SteamLocomotiveTrain_2560x1600_60_10bit_crop.yuv --bitrate 9000
 --vbv-bufsize 9000 --strict-cbr
 
 Bitrate Y PSNR  U PSNR  V PSNR  Global PSNR SSIM
 SSIM (dB)
  before  9168.43 39.689  45.096 45.152   41.048 0.93176  11.66
  after   9106.16  39.864 45.16945.19941.194 0.93518
 11.883

 do these pair of commits belong on stable?

Yes, they belong on the stable


  diff -r 6f159ec858f4 -r b4646bdaf220 source/encoder/ratecontrol.cpp
  --- a/source/encoder/ratecontrol.cpp  Tue Mar 31 22:16:21 2015 +0530
  +++ b/source/encoder/ratecontrol.cpp  Mon Mar 16 12:05:38 2015 +0530
  @@ -372,12 +372,17 @@
   /* Frame Predictors and Row predictors used in vbv */
   for (int i = 0; i  4; i++)
   {
  -m_pred[i].coeff = 1.5;
  +m_pred[i].coeff = 1.0;
   m_pred[i].count = 1.0;
   m_pred[i].decay = 0.5;
   m_pred[i].offset = 0.0;
   }
  -m_pred[0].coeff = 1.0;
  +m_pred[0].coeff = m_pred[3].coeff = 0.75;
  +if (m_param-rc.qCompress = 0.8) // when tuned for grain
  +{
  +m_pred[1].coeff = 0.75;
  +m_pred[0].coeff = m_pred[3].coeff = 0.50;
  +}
   if (!m_statFileOut  (m_param-rc.bStatWrite ||
 m_param-rc.bStatRead))
   {
   /* If the user hasn't defined the stat filename, use the
 default value */
  @@ -1797,8 +1802,11 @@
   double pbits = predictSize(m_pred[m_predType], q,
 (double)m_currentSatd);
   if (pbits  rce-frameSizeMaximum)
   q *= pbits / rce-frameSizeMaximum;
  -
  -if (!m_isCbr || (m_isAbr  m_currentSatd = rce-movingAvgSum
  q = q0 / 2))
  +/* To detect frames that are more complex in SATD costs
 compared to prev window, yet
  + * lookahead vbv reduces its qscale by half its value. Be on
 safer side and avoid drastic
  + * qscale reductions for frames high in complexity */
  +bool mispredCheck = rce-movingAvgSum  m_currentSatd =
 rce-movingAvgSum  q = q0 / 2;
  +if (!m_isCbr || (m_isAbr  mispredCheck))
   q = X265_MAX(q0, q);
 
   if (m_rateFactorMaxIncrement)
  ___
  x265-devel mailing list
  x265-devel@videolan.org
  https://mailman.videolan.org/listinfo/x265-devel

 --
 Steve Borho
 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel

___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 1 of 2] rc: separate frame bits predictor objects for BRef and B frames

2015-04-09 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Thirumalai
# Date 1428573257 -19800
#  Thu Apr 09 15:24:17 2015 +0530
# Node ID c87e15a9a353bc13036bb33a4a1932ebdb7dfb1a
# Parent  4d3bfacc276362175f5f0b4a5844ec640c8871f0
rc: add helper function to decide the VBV predictor type for each frame

diff -r 4d3bfacc2763 -r c87e15a9a353 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Mar 16 12:05:38 2015 +0530
+++ b/source/encoder/ratecontrol.cpp Thu Apr 09 15:24:17 2015 +0530
@@ -952,7 +952,7 @@
 rce-sliceType = m_sliceType;
 if (!m_2pass)
 rce-keptAsRef = IS_REFERENCED(curFrame);
-m_predType = m_sliceType == B_SLICE  rce-keptAsRef ? 3 :
m_sliceType;
+m_predType = getPredictorType(curFrame-m_lowres.sliceType,
m_sliceType);
 rce-poc = m_curSlice-m_poc;
 if (m_param-rc.bStatRead)
 {
@@ -1113,6 +1113,14 @@
 m_accumPQp += m_qp;
 }

+int RateControl::getPredictorType(int lowresSliceType, int sliceType)
+{
+/* Use a different predictor for B Ref and B frames for vbv frame size
predictions */
+if (lowresSliceType == X265_TYPE_BREF)
+return 3;
+return sliceType;
+}
+
 double RateControl::getDiffLimitedQScale(RateControlEntry *rce, double q)
 {
 // force I/B quants as a function of P quants
@@ -1734,7 +1742,7 @@
 bufferFillCur += wantedFrameSize;
 int64_t satd = curFrame-m_lowres.plannedSatd[j] 
(X265_DEPTH - 8);
 type = IS_X265_TYPE_I(type) ? I_SLICE :
IS_X265_TYPE_B(type) ? B_SLICE : P_SLICE;
-int predType = curFrame-m_lowres.plannedType[j] ==
X265_TYPE_BREF ? 3 : type;
+int predType =
getPredictorType(curFrame-m_lowres.plannedType[j], type);
 curBits = predictSize(m_pred[predType], frameQ[type],
(double)satd);
 bufferFillCur -= curBits;
 }
diff -r 4d3bfacc2763 -r c87e15a9a353 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Mon Mar 16 12:05:38 2015 +0530
+++ b/source/encoder/ratecontrol.h Thu Apr 09 15:24:17 2015 +0530
@@ -264,7 +264,7 @@
 double rateEstimateQscale(Frame* pic, RateControlEntry *rce); // main
logic for calculating QP based on ABR
 double tuneAbrQScaleFromFeedback(double qScale);
 void   accumPQpUpdate();
-
+intgetPredictorType(int lowresSliceType, int sliceType);
 void   updateVbv(int64_t bits, RateControlEntry* rce);
 void   updatePredictor(Predictor *p, double q, double var, double
bits);
 double clipQscale(Frame* pic, RateControlEntry* rce, double q);


On Thu, Apr 9, 2015 at 12:08 AM, Steve Borho st...@borho.org wrote:

 On 04/08, aar...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Aarthi Thirumalai
  # Date 1427820381 -19800
  #  Tue Mar 31 22:16:21 2015 +0530
  # Node ID 6f159ec858f4eec484d722916c41911e3e4540f9
  # Parent  3e416dec8024b8339b18568cf65e48eb3448bed1
  rc: separate frame bits predictor objects for BRef and B frames
 
  improves frame size prediction for BRef frames in VBV.

 this probably deserves a follow up commit introducing an inline helper
 method that maps from Slice* to predictor type, so we can be sure the
 logic stays consistent going forward and is self-documenting

  diff -r 3e416dec8024 -r 6f159ec858f4 source/encoder/ratecontrol.cpp
  --- a/source/encoder/ratecontrol.cpp  Tue Apr 07 16:00:39 2015 -0500
  +++ b/source/encoder/ratecontrol.cpp  Tue Mar 31 22:16:21 2015 +0530
  @@ -370,7 +370,7 @@
   m_accumPQp = (m_param-rc.rateControlMode == X265_RC_CRF ?
 CRF_INIT_QP : ABR_INIT_QP_MIN) * m_accumPNorm;
 
   /* Frame Predictors and Row predictors used in vbv */
  -for (int i = 0; i  5; i++)
  +for (int i = 0; i  4; i++)
   {
   m_pred[i].coeff = 1.5;
   m_pred[i].count = 1.0;
  @@ -945,6 +945,9 @@
   m_curSlice = curEncData.m_slice;
   m_sliceType = m_curSlice-m_sliceType;
   rce-sliceType = m_sliceType;
  +if (!m_2pass)
  +rce-keptAsRef = IS_REFERENCED(curFrame);
  +m_predType = m_sliceType == B_SLICE  rce-keptAsRef ? 3 :
 m_sliceType;
   rce-poc = m_curSlice-m_poc;
   if (m_param-rc.bStatRead)
   {
  @@ -1074,7 +1077,7 @@
   m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
   if (rce-poc == 0)
m_lastQScaleFor[P_SLICE] =
 m_lastQScaleFor[m_sliceType] * fabs(m_param-rc.ipFactor);
  -rce-frameSizePlanned = predictSize(m_pred[m_sliceType],
 m_qp, (double)m_currentSatd);
  +rce-frameSizePlanned = predictSize(m_pred[m_predType],
 m_qp, (double)m_currentSatd);
   }
   }
   m_framesDone++;
  @@ -1397,10 +1400,10 @@
   qScale = clipQscale(curFrame, rce, qScale);
   /* clip qp to permissible range after vbv-lookahead
 estimation to avoid possible
* mispredictions by initial frame size predictors */
  -if (m_pred[m_sliceType].count == 1

[x265] [PATCH 2 of 2] rc: tune initial predictor values for better frame size predictions in vbv lookahead

2015-04-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426487738 -19800
#  Mon Mar 16 12:05:38 2015 +0530
# Node ID b4646bdaf2202748d3a3b159b9bc8e3cfcd272de
# Parent  6f159ec858f4eec484d722916c41911e3e4540f9
rc: tune initial predictor values for better frame size predictions in vbv 
lookahead

an overall improvement in ssim of around .05-.1 db can be seen.
Also, improves visual quality at the start of the encode.

SteamLocomotiveTrain_2560x1600_60_10bit_crop.yuv --bitrate 9000 --vbv-bufsize 
9000 --strict-cbr

   Bitrate   Y PSNR  U PSNR  V PSNR  Global PSNR SSIMSSIM (dB)
before  9168.43 39.689  45.096 45.152 41.048 0.93176  11.66
after   9106.16  39.864 45.169  45.19941.194 0.93518  11.883

diff -r 6f159ec858f4 -r b4646bdaf220 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Mar 31 22:16:21 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Mar 16 12:05:38 2015 +0530
@@ -372,12 +372,17 @@
 /* Frame Predictors and Row predictors used in vbv */
 for (int i = 0; i  4; i++)
 {
-m_pred[i].coeff = 1.5;
+m_pred[i].coeff = 1.0;
 m_pred[i].count = 1.0;
 m_pred[i].decay = 0.5;
 m_pred[i].offset = 0.0;
 }
-m_pred[0].coeff = 1.0;
+m_pred[0].coeff = m_pred[3].coeff = 0.75;
+if (m_param-rc.qCompress = 0.8) // when tuned for grain 
+{
+m_pred[1].coeff = 0.75;
+m_pred[0].coeff = m_pred[3].coeff = 0.50;
+}
 if (!m_statFileOut  (m_param-rc.bStatWrite || m_param-rc.bStatRead))
 {
 /* If the user hasn't defined the stat filename, use the default value 
*/
@@ -1797,8 +1802,11 @@
 double pbits = predictSize(m_pred[m_predType], q, 
(double)m_currentSatd);
 if (pbits  rce-frameSizeMaximum)
 q *= pbits / rce-frameSizeMaximum;
-
-if (!m_isCbr || (m_isAbr  m_currentSatd = rce-movingAvgSum  q = 
q0 / 2))
+/* To detect frames that are more complex in SATD costs compared to 
prev window, yet 
+ * lookahead vbv reduces its qscale by half its value. Be on safer 
side and avoid drastic 
+ * qscale reductions for frames high in complexity */
+bool mispredCheck = rce-movingAvgSum  m_currentSatd = 
rce-movingAvgSum  q = q0 / 2;
+if (!m_isCbr || (m_isAbr  mispredCheck))
 q = X265_MAX(q0, q);
 
 if (m_rateFactorMaxIncrement)
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 1 of 2] rc: separate frame bits predictor objects for BRef and B frames

2015-04-08 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1427820381 -19800
#  Tue Mar 31 22:16:21 2015 +0530
# Node ID 6f159ec858f4eec484d722916c41911e3e4540f9
# Parent  3e416dec8024b8339b18568cf65e48eb3448bed1
rc: separate frame bits predictor objects for BRef and B frames

improves frame size prediction for BRef frames in VBV.

diff -r 3e416dec8024 -r 6f159ec858f4 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Apr 07 16:00:39 2015 -0500
+++ b/source/encoder/ratecontrol.cppTue Mar 31 22:16:21 2015 +0530
@@ -370,7 +370,7 @@
 m_accumPQp = (m_param-rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : 
ABR_INIT_QP_MIN) * m_accumPNorm;
 
 /* Frame Predictors and Row predictors used in vbv */
-for (int i = 0; i  5; i++)
+for (int i = 0; i  4; i++)
 {
 m_pred[i].coeff = 1.5;
 m_pred[i].count = 1.0;
@@ -945,6 +945,9 @@
 m_curSlice = curEncData.m_slice;
 m_sliceType = m_curSlice-m_sliceType;
 rce-sliceType = m_sliceType;
+if (!m_2pass)
+rce-keptAsRef = IS_REFERENCED(curFrame);
+m_predType = m_sliceType == B_SLICE  rce-keptAsRef ? 3 : m_sliceType;
 rce-poc = m_curSlice-m_poc;
 if (m_param-rc.bStatRead)
 {
@@ -1074,7 +1077,7 @@
 m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
 if (rce-poc == 0)
  m_lastQScaleFor[P_SLICE] = m_lastQScaleFor[m_sliceType] * 
fabs(m_param-rc.ipFactor);
-rce-frameSizePlanned = predictSize(m_pred[m_sliceType], m_qp, 
(double)m_currentSatd);
+rce-frameSizePlanned = predictSize(m_pred[m_predType], m_qp, 
(double)m_currentSatd);
 }
 }
 m_framesDone++;
@@ -1397,10 +1400,10 @@
 qScale = clipQscale(curFrame, rce, qScale);
 /* clip qp to permissible range after vbv-lookahead estimation 
to avoid possible 
  * mispredictions by initial frame size predictors */
-if (m_pred[m_sliceType].count == 1)
+if (m_pred[m_predType].count == 1)
 qScale = x265_clip3(lmin, lmax, qScale);
 m_lastQScaleFor[m_sliceType] = qScale;
-rce-frameSizePlanned = predictSize(m_pred[m_sliceType], 
qScale, (double)m_currentSatd);
+rce-frameSizePlanned = predictSize(m_pred[m_predType], 
qScale, (double)m_currentSatd);
 }
 else
 rce-frameSizePlanned = qScale2bits(rce, qScale);
@@ -1544,7 +1547,7 @@
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
  * mispredictions by initial frame size predictors */
-if (!m_2pass  m_isVbv  m_pred[m_sliceType].count == 1)
+if (!m_2pass  m_isVbv  m_pred[m_predType].count == 1)
 q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
@@ -1554,7 +1557,7 @@
 if (m_2pass  m_isVbv)
 rce-frameSizePlanned = qScale2bits(rce, q);
 else
-rce-frameSizePlanned = predictSize(m_pred[m_sliceType], q, 
(double)m_currentSatd);
+rce-frameSizePlanned = predictSize(m_pred[m_predType], q, 
(double)m_currentSatd);
 
 /* Always use up the whole VBV in this case. */
 if (m_singleFrameVbv)
@@ -1707,7 +1710,7 @@
 {
 double frameQ[3];
 double curBits;
-curBits = predictSize(m_pred[m_sliceType], q, 
(double)m_currentSatd);
+curBits = predictSize(m_pred[m_predType], q, 
(double)m_currentSatd);
 double bufferFillCur = m_bufferFill - curBits;
 double targetFill;
 double totalDuration = m_frameDuration;
@@ -1726,7 +1729,8 @@
 bufferFillCur += wantedFrameSize;
 int64_t satd = curFrame-m_lowres.plannedSatd[j]  
(X265_DEPTH - 8);
 type = IS_X265_TYPE_I(type) ? I_SLICE : 
IS_X265_TYPE_B(type) ? B_SLICE : P_SLICE;
-curBits = predictSize(m_pred[type], frameQ[type], 
(double)satd);
+int predType = curFrame-m_lowres.plannedType[j] == 
X265_TYPE_BREF ? 3 : type;
+curBits = predictSize(m_pred[predType], frameQ[type], 
(double)satd);
 bufferFillCur -= curBits;
 }
 
@@ -1766,7 +1770,7 @@
 }
 // Now a hard threshold to make sure the frame fits in VBV.
 // This one is mostly for I-frames.
-double bits = predictSize(m_pred[m_sliceType], q, 
(double)m_currentSatd);
+double bits = predictSize(m_pred[m_predType], q, 
(double)m_currentSatd);
 
 // For small VBVs, allow the frame to use up the entire VBV.
 double maxFillFactor;
@@ -1783,14 +1787,14 @@
 bits *= qf;
 if (bits  m_bufferRate / minFillFactor)
 q *= bits

Re: [x265] [PATCH] rc: fix bug in ABR 2 pass, calculate aq-offset only for unreferenced frame in 2 pass

2015-03-30 Thread Aarthi Priya Thirumalai
For the last pass in multi pass encodes, slice types are taken from the
stats file before the frame is added into the lookahead queue. We would not
do slice type analysis here and just stick with slice types read from the
file.
So, at this point, we would already know slice types along with CUTree
offsets which we also copy  from the previous pass for all referenced
slices. Only for the unreferenced frames, we would need to recompute
aqoffsets as the data for those won't be written in the log files.

Since calcAdaptive() rewrites all the arrays - both AQCUTree offsets, we
should not do this and overwrite the values for referenced frames. This
flow was broken when the NUMA related commits were pushed in.
On Mar 30, 2015 9:14 PM, Steve Borho st...@borho.org wrote:

 On 03/30, santhosh...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Santhoshini Sekarsanthosh...@multicorewareinc.com
  # Date 1427716771 -19800
  #  Mon Mar 30 17:29:31 2015 +0530
  # Node ID 1bdeb44d775d5be7523925017a1483294da2575d
  # Parent  22a312799bb033d40a66fc83a1ac7af192ce2420
  rc: fix bug in ABR 2 pass, calculate aq-offset only for unreferenced
 frame in 2 pass
 
  diff -r 22a312799bb0 -r 1bdeb44d775d source/encoder/slicetype.cpp
  --- a/source/encoder/slicetype.cppFri Mar 27 22:59:30 2015 -0500
  +++ b/source/encoder/slicetype.cppMon Mar 30 17:29:31 2015 +0530
  @@ -699,7 +699,7 @@
   ProfileScopeEvent(prelookahead);
 
   preFrame-m_lowres.init(preFrame-m_fencPic,
 preFrame-m_poc);
  -if (m_bAdaptiveQuant)
  +if (m_bAdaptiveQuant  (!m_param-rc.bStatRead
 ||(m_param-rc.bStatRead (!m_param-rc.cuTree || !
 IS_REFERENCED(preFrame)

 1. white-space

 2. this is pre-lookahead, the slice type and reference status is not
known yet. If the AQ offsets aren't needed, you'll need to clear them
after lookahead or just ignore them. If AQ offsets shouldn't be
generated regardless of slice type, m_bAdaptiveQuant should be
set to false much earlier

 --
 Steve Borho
 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel

___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: fix buffer underflow issue in vbv

2015-03-17 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426612817 -19800
#  Tue Mar 17 22:50:17 2015 +0530
# Node ID 638a3af86fa12132aae47ed0d4b321ce6cc36ed2
# Parent  cc579ffe4b7e0cd2b554a573ba70ff8e8c726d42
rc: fix buffer underflow issue in vbv

diff -r cc579ffe4b7e -r 638a3af86fa1 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Mar 17 11:11:32 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Mar 17 22:50:17 2015 +0530
@@ -1369,36 +1369,36 @@
 
 double qScale = x265_qp2qScale(q);
 double lmin = 0, lmax = 0;
-if (m_isCbr)
+if (m_isVbv)
 {
-qScale = tuneAbrQScaleFromFeedback(qScale);
-if (!m_isAbrReset)
+lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
+lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
+if (m_isCbr)
 {
-lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
-lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
-qScale = x265_clip3(lmin, lmax, qScale);
+qScale = tuneAbrQScaleFromFeedback(qScale);
+if (!m_isAbrReset)
+qScale = x265_clip3(lmin, lmax, qScale);
+q = x265_qScale2qp(qScale);
 }
-q = x265_qScale2qp(qScale);
+rce-qpNoVbv = q;
+if (!m_2pass)
+{
+qScale = clipQscale(curFrame, rce, qScale);
+/*  clip qp to permissible range after vbv-lookahead 
estimation to avoid possible 
+ * mispredictions by initial frame size predictors */
+   // if (m_pred[m_sliceType].count == 1)
+//qScale = x265_clip3(lmin, lmax, qScale);
+m_lastQScaleFor[m_sliceType] = qScale;
+rce-frameSizePlanned = predictSize(m_pred[m_sliceType], 
qScale, (double)m_currentSatd);
+}
+else
+{
+rce-frameSizePlanned = qScale2bits(rce, qScale);
+}
+/* Limit planned size by MinCR */
+rce-frameSizePlanned = X265_MIN(rce-frameSizePlanned, 
rce-frameSizeMaximum);
+rce-frameSizeEstimated = rce-frameSizePlanned;
 }
-rce-qpNoVbv = q;
-if (!m_2pass  m_isVbv)
-{
-qScale = clipQscale(curFrame, rce, qScale);
-/*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible 
- * mispredictions by initial frame size predictors */
-if (m_pred[m_sliceType].count == 1)
-qScale = x265_clip3(lmin, lmax, qScale);
-m_lastQScaleFor[m_sliceType] = qScale;
-rce-frameSizePlanned = predictSize(m_pred[m_sliceType], qScale, 
(double)m_currentSatd);
-}
-else if (m_2pass  m_isVbv)
-{
-rce-frameSizePlanned = qScale2bits(rce, qScale);
-}
-/* Limit planned size by MinCR */
-if (m_isVbv)
-rce-frameSizePlanned = X265_MIN(rce-frameSizePlanned, 
rce-frameSizeMaximum);
-rce-frameSizeEstimated = rce-frameSizePlanned;
 rce-newQScale = qScale;
 return qScale;
 }
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] revert unintended comments in 638a3af86fa1

2015-03-17 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426646352 -19800
#  Wed Mar 18 08:09:12 2015 +0530
# Node ID c92fd0798e71e72c18deef967fb7a95960d9bc27
# Parent  a593af2995788a3c6762f51d56c5f7d32e3ebce9
revert unintended comments in 638a3af86fa1

diff -r a593af299578 -r c92fd0798e71 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Mar 17 16:46:48 2015 -0500
+++ b/source/encoder/ratecontrol.cppWed Mar 18 08:09:12 2015 +0530
@@ -1386,6 +1386,8 @@
 qScale = clipQscale(curFrame, rce, qScale);
 /* clip qp to permissible range after vbv-lookahead estimation 
to avoid possible 
  * mispredictions by initial frame size predictors */
+if (m_pred[m_sliceType].count == 1)
+qScale = x265_clip3(lmin, lmax, qScale);
 m_lastQScaleFor[m_sliceType] = qScale;
 rce-frameSizePlanned = predictSize(m_pred[m_sliceType], 
qScale, (double)m_currentSatd);
 }
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: release RC lock after RateControlStart for CQP and CRF(without VBV)

2015-03-17 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426573364 -19800
#  Tue Mar 17 11:52:44 2015 +0530
# Node ID 447345368ddf982deb3cda4fdff36860e1364189
# Parent  b9948752d5516a72eeaf824e3ee6f0feb097381c
rc: release RC lock after RateControlStart for CQP and CRF(without VBV)

RateControlUpdateStats is not needed for CQP and CRF - without vbv,
prevent floating point divide by zero issue in CQP

diff -r b9948752d551 -r 447345368ddf source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp   Mon Mar 16 20:40:12 2015 -0500
+++ b/source/encoder/frameencoder.cpp   Tue Mar 17 11:52:44 2015 +0530
@@ -1042,24 +1042,24 @@
  * after refLagRows (the number of rows reference frames must have 
completed
  * before referencees may begin encoding) */
 uint32_t rowCount = 0;
-if (m_param-rc.rateControlMode == X265_RC_ABR)
+if (m_param-rc.rateControlMode == X265_RC_ABR || bIsVbv)
 {
 if ((uint32_t)m_rce.encodeOrder = 2 * (m_param-fpsNum / 
m_param-fpsDenom))
 rowCount = X265_MIN((m_numRows + 1) / 2, m_numRows - 1);
 else
 rowCount = X265_MIN(m_refLagRows, m_numRows - 1);
-}
-if (row == rowCount)
-{
-m_rce.rowTotalBits = 0;
-if (bIsVbv)
-for (uint32_t i = 0; i  rowCount; i++)
-m_rce.rowTotalBits += curEncData.m_rowStat[i].encodedBits;
-else
-for (uint32_t cuAddr = 0; cuAddr  rowCount * numCols; cuAddr++)
-m_rce.rowTotalBits += curEncData.m_cuStat[cuAddr].totalBits;
+if (row == rowCount)
+{
+m_rce.rowTotalBits = 0;
+if (bIsVbv)
+for (uint32_t i = 0; i  rowCount; i++)
+m_rce.rowTotalBits += curEncData.m_rowStat[i].encodedBits;
+else
+for (uint32_t cuAddr = 0; cuAddr  rowCount * numCols; 
cuAddr++)
+m_rce.rowTotalBits += 
curEncData.m_cuStat[cuAddr].totalBits;
 
-m_top-m_rateControl-rateControlUpdateStats(m_rce);
+m_top-m_rateControl-rateControlUpdateStats(m_rce);
+}
 }
 
 /* flush row bitstream (if WPP and no SAO) or flush frame if no WPP and no 
SAO */
diff -r b9948752d551 -r 447345368ddf source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Mar 16 20:40:12 2015 -0500
+++ b/source/encoder/ratecontrol.cppTue Mar 17 11:52:44 2015 +0530
@@ -1077,9 +1077,20 @@
 rce-frameSizePlanned = predictSize(m_pred[m_sliceType], m_qp, 
(double)m_currentSatd);
 }
 }
-// Do not increment m_startEndOrder here. Make rateControlEnd of previous 
thread
-// to wait until rateControlUpdateStats of this frame is called
 m_framesDone++;
+
+/* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to 
+ * tune RateControl parameters for other frames.
+ * Hence, for these modes, update m_startEndOrder and unlock RC for 
previous threads waiting in
+ * RateControlEnd here.those modes here. For the rest - ABR
+ * and VBV, unlock only after rateControlUpdateStats of this frame is 
called */
+if (m_param-rc.rateControlMode != X265_RC_ABR  !m_isVbv)
+{
+m_startEndOrder.incr();
+
+if (rce-encodeOrder  m_param-frameNumThreads - 1)
+m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
+}
 return m_qp;
 }
 
@@ -1588,10 +1599,13 @@
 
 /* do not allow the next frame to enter rateControlStart() until this
  * frame has updated its mid-frame statistics */
-m_startEndOrder.incr();
+if (m_param-rc.rateControlMode == X265_RC_ABR || m_isVbv)
+{
+m_startEndOrder.incr();
 
-if (rce-encodeOrder  m_param-frameNumThreads - 1)
-m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
+if (rce-encodeOrder  m_param-frameNumThreads - 1)
+m_startEndOrder.incr(); // faked rateControlEnd calls for negative 
frames
+}
 }
 
 void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: bug fix for enforcing qpFile in 2 pass(fixes issue #111)

2015-03-16 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426501581 -19800
#  Mon Mar 16 15:56:21 2015 +0530
# Node ID 2cd5af5a527d595d74fbad748c769bc48dce3e08
# Parent  74496ce5d8ba9577410875703fef3f4a96362f7c
rc: bug fix for enforcing qpFile in 2 pass(fixes issue #111)

diff -r 74496ce5d8ba -r 2cd5af5a527d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Mar 16 10:47:09 2015 +0530
+++ b/source/encoder/ratecontrol.cppMon Mar 16 15:56:21 2015 +0530
@@ -1068,7 +1068,7 @@
 m_qp = (int32_t)(curFrame-m_forceqp + 0.5) - 1;
 m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);
 rce-qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
-if (m_isAbr)
+if (m_isAbr || m_2pass)
 {
 rce-qpNoVbv = rce-qpaRc;
 m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
@@ -1473,7 +1473,7 @@
  * tolerances, the bit distribution approaches that of 2pass. */
 
 double overflow = 1;
-double lqmin = 0, lqmax = 0;
+double lqmin = MIN_QPSCALE, lqmax = MAX_MAX_QPSCALE;
 m_shortTermCplxSum *= 0.5;
 m_shortTermCplxCount *= 0.5;
 m_shortTermCplxSum += m_currentSatd / 
(CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);
@@ -1534,7 +1534,7 @@
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
  * mispredictions by initial frame size predictors */
-if (m_isVbv  m_pred[m_sliceType].count == 1)
+if (!m_2pass  m_isVbv  m_pred[m_sliceType].count == 1)
 q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
diff -r 74496ce5d8ba -r 2cd5af5a527d source/x265.cpp
--- a/source/x265.cpp   Mon Mar 16 10:47:09 2015 +0530
+++ b/source/x265.cpp   Mon Mar 16 15:56:21 2015 +0530
@@ -530,7 +530,7 @@
 while (pic_in  !b_ctrl_c)
 {
 pic_orig.poc = inFrameCount;
-if (cliopt.qpfile  !param-rc.bStatRead)
+if (cliopt.qpfile)
 {
 if (!cliopt.parseQPFile(pic_orig))
 {
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: fix bug in CRF caused by e0f834c69cb2

2015-03-13 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426264076 -19800
#  Fri Mar 13 21:57:56 2015 +0530
# Node ID 7b2212877f62fc4ad1db069f8351ece5be02b674
# Parent  c1a8eef8be143a40981ae6909c6c8c3a6b85901c
rc: fix bug in CRF caused by e0f834c69cb2

diff -r c1a8eef8be14 -r 7b2212877f62 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppFri Mar 13 16:40:06 2015 +0530
+++ b/source/encoder/ratecontrol.cppFri Mar 13 21:57:56 2015 +0530
@@ -1526,7 +1526,7 @@
 else if (m_framesDone == 0  !m_isVbv  
m_param-rc.rateControlMode == X265_RC_ABR)
 {
 /* for ABR alone, clip the first I frame qp */
-double lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * m_lstep;
+lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * m_lstep;
 q = X265_MIN(lqmax, q);
 }
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
@@ -1534,7 +1534,7 @@
 q = clipQscale(curFrame, rce, q);
 /*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
  * mispredictions by initial frame size predictors */
-if (m_pred[m_sliceType].count == 1)
+if (m_isVbv  m_pred[m_sliceType].count == 1)
 q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 2] rc: clip qp after initial vbv-lookahead estimation

2015-03-12 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426096587 -19800
#  Wed Mar 11 23:26:27 2015 +0530
# Node ID dc325b5736f3f6ab4595132673895e00a297e57b
# Parent  29daf84c63f4d219988c81dc668706a5d7c20cde
rc: clip qp after initial vbv-lookahead estimation.

avoid drastic qp changes caused due to possible mispredictions from initial vbv 
predictors.

diff -r 29daf84c63f4 -r dc325b5736f3 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Mar 11 23:05:55 2015 +0530
+++ b/source/encoder/ratecontrol.cppWed Mar 11 23:26:27 2015 +0530
@@ -1368,13 +1368,14 @@
 q += m_pbOffset;
 
 double qScale = x265_qp2qScale(q);
+double lmin = 0, lmax = 0;
 if (m_isCbr)
 {
 qScale = tuneAbrQScaleFromFeedback(qScale);
 if (!m_isAbrReset)
 {
-double lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
-double lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
+lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
+lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
 qScale = x265_clip3(lmin, lmax, qScale);
 }
 q = x265_qScale2qp(qScale);
@@ -1383,6 +1384,10 @@
 if (!m_2pass  m_isVbv)
 {
 qScale = clipQscale(curFrame, rce, qScale);
+/*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible 
+ * mispredictions by initial frame size predictors */
+if (m_pred[m_sliceType].count == 1)
+qScale = x265_clip3(lmin, lmax, qScale);
 m_lastQScaleFor[m_sliceType] = qScale;
 rce-frameSizePlanned = predictSize(m_pred[m_sliceType], qScale, 
(double)m_currentSatd);
 }
@@ -1468,7 +1473,7 @@
  * tolerances, the bit distribution approaches that of 2pass. */
 
 double overflow = 1;
-
+double lqmin = 0, lqmax = 0;
 m_shortTermCplxSum *= 0.5;
 m_shortTermCplxCount *= 0.5;
 m_shortTermCplxSum += m_currentSatd / 
(CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);
@@ -1502,7 +1507,6 @@
 {
 if (m_param-rc.rateControlMode != X265_RC_CRF)
 {
-double lqmin = 0, lqmax = 0;
 lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
 lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
 if (!m_partialResidualFrames)
@@ -1528,6 +1532,10 @@
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
 rce-qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
+/*  clip qp to permissible range after vbv-lookahead estimation to 
avoid possible
+ * mispredictions by initial frame size predictors */
+if (m_pred[m_sliceType].count == 1)
+q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
 if ((m_curSlice-m_poc == 0 || m_lastQScaleFor[P_SLICE]  q)  
!(m_2pass  !m_isVbv))
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 1 of 2] rc: recompute planned frame size when using vbv with --qpfile

2015-03-12 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1426095355 -19800
#  Wed Mar 11 23:05:55 2015 +0530
# Node ID 29daf84c63f4d219988c81dc668706a5d7c20cde
# Parent  3187844f4a7f86b1751eaddbb0f0ed926f767eeb
rc: recompute planned frame size when using vbv with --qpfile

diff -r 3187844f4a7f -r 29daf84c63f4 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Mar 09 14:35:20 2015 +0530
+++ b/source/encoder/ratecontrol.cppWed Mar 11 23:05:55 2015 +0530
@@ -1068,6 +1068,14 @@
 m_qp = (int32_t)(curFrame-m_forceqp + 0.5) - 1;
 m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);
 rce-qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
+if (m_isAbr)
+{
+rce-qpNoVbv = rce-qpaRc;
+m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
+if (rce-poc == 0)
+ m_lastQScaleFor[P_SLICE] = m_lastQScaleFor[m_sliceType] * 
fabs(m_param-rc.ipFactor);
+rce-frameSizePlanned = predictSize(m_pred[m_sliceType], m_qp, 
(double)m_currentSatd);
+}
 }
 // Do not increment m_startEndOrder here. Make rateControlEnd of previous 
thread
 // to wait until rateControlUpdateStats of this frame is called
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: recompute planned frame size when using vbv with --qpfile

2015-03-11 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1425994215 -19800
#  Tue Mar 10 19:00:15 2015 +0530
# Node ID 9b7b93384e39e90cf2d4c0c0a53213abff362f70
# Parent  8f148ac8dbe4b68e88ceff84f40e33b29e888dc9
rc: recompute planned frame size when using vbv with --qpfile

diff -r 8f148ac8dbe4 -r 9b7b93384e39 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppTue Mar 10 15:46:36 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Mar 10 19:00:15 2015 +0530
@@ -1067,7 +1067,15 @@
 {
 m_qp = (int32_t)(curFrame-m_forceqp + 0.5) - 1;
 m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);
-rce-qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
+rce-qpaRc =curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
+if (m_isAbr)
+{
+rce-qpNoVbv = rce-qpaRc;
+m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
+if (rce-poc == 0)
+ m_lastQScaleFor[P_SLICE] = m_lastQScaleFor[m_sliceType] * 
fabs(m_param-rc.ipFactor);
+rce-frameSizePlanned = predictSize(m_pred[m_sliceType], 
rce-qpaRc, (double)m_currentSatd);
+}
 }
 // Do not increment m_startEndOrder here. Make rateControlEnd of previous 
thread
 // to wait until rateControlUpdateStats of this frame is called
@@ -1360,13 +1368,14 @@
 q += m_pbOffset;
 
 double qScale = x265_qp2qScale(q);
+double lmin = 0, lmax = 0;
 if (m_isCbr)
 {
 qScale = tuneAbrQScaleFromFeedback(qScale);
 if (!m_isAbrReset)
 {
-double lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
-double lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
+ lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
+ lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
 qScale = x265_clip3(lmin, lmax, qScale);
 }
 q = x265_qScale2qp(qScale);
@@ -1375,6 +1384,8 @@
 if (!m_2pass  m_isVbv)
 {
 qScale = clipQscale(curFrame, rce, qScale);
+if (m_pred[m_sliceType].count == 1)
+qScale = x265_clip3(lmin, lmax, qScale);
 m_lastQScaleFor[m_sliceType] = qScale;
 rce-frameSizePlanned = predictSize(m_pred[m_sliceType], qScale, 
(double)m_currentSatd);
 }
@@ -1460,7 +1471,7 @@
  * tolerances, the bit distribution approaches that of 2pass. */
 
 double overflow = 1;
-
+double lqmin = 0, lqmax = 0;
 m_shortTermCplxSum *= 0.5;
 m_shortTermCplxCount *= 0.5;
 m_shortTermCplxSum += m_currentSatd / 
(CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);
@@ -1494,7 +1505,6 @@
 {
 if (m_param-rc.rateControlMode != X265_RC_CRF)
 {
-double lqmin = 0, lqmax = 0;
 lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
 lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
 if (!m_partialResidualFrames)
@@ -1520,6 +1530,8 @@
 q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
 rce-qpNoVbv = x265_qScale2qp(q);
 q = clipQscale(curFrame, rce, q);
+if (m_pred[m_sliceType].count == 1  m_framesDone  0)
+q = x265_clip3(lqmin, lqmax, q);
 }
 m_lastQScaleFor[m_sliceType] = q;
 if ((m_curSlice-m_poc == 0 || m_lastQScaleFor[P_SLICE]  q)  
!(m_2pass  !m_isVbv))
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] analysis:add logic for calculate qp for a given cu size

2015-03-11 Thread Aarthi Priya Thirumalai
Also, since vbv may be changing the qp for each row, you need to pick up
the base qp from
curEncData.m_cuStat[cuAddr].baseQp instead of m_frame-m_encData-m_avgQpRc;

On Thu, Mar 12, 2015 at 10:25 AM, Sreelakshmy Govindan 
sreelaks...@multicorewareinc.com wrote:

 Thanks Steve. I will make the changes and resend the patch.


 Regards,
 Sreelakshmy

 On Thu, Mar 12, 2015 at 9:32 AM, Steve Borho st...@borho.org wrote:

 On Wed, Mar 11, 2015 at 10:36 PM,  sreelaks...@multicorewareinc.com
 wrote:
  # HG changeset patch
  # User Sreelakshmy V G sreelaks...@multicorewareinc.com
  # Date 1426131126 -19800
  #  Thu Mar 12 09:02:06 2015 +0530
  # Node ID c7182de7496906e81b57cb94278d60cbcc446648
  # Parent  b931c50d55011a1ddc08f0a230b9632fcb4674d7
  analysis:add logic for calculate qp for a given cu size

 the commit message should mention that the commit is adding the
 function but that it is not yet used, for the convenience of reviewers

  diff -r b931c50d5501 -r c7182de74969 source/encoder/analysis.cpp
  --- a/source/encoder/analysis.cpp   Wed Mar 11 21:58:02 2015 -0500
  +++ b/source/encoder/analysis.cpp   Thu Mar 12 09:02:06 2015 +0530
  @@ -1895,3 +1895,41 @@
 
   return false;
   }
  +
  +int Analysis::calculateQpforCuSize(CUData ctu, const CUGeom cuGeom)
  +{
  +x265_emms();

 it doesn't appear that this function needs to use floats, so EMMS
 should eventually be unnecessary

  +int depth = cuGeom.depth;
  +uint32_t ctuAddr;
  +ctuAddr = ctu.m_cuAddr;
  +double qp = m_frame-m_encData-m_avgQpRc;
  +
  +uint32_t width = m_frame-m_fencPic-m_picWidth;
  +uint32_t height = m_frame-m_fencPic-m_picHeight;
  +uint32_t block_x = ctu.m_cuPelX + g_zscanToPelX[cuGeom.absPartIdx];
  +uint32_t block_y = ctu.m_cuPelY + g_zscanToPelY[cuGeom.absPartIdx];
  +uint32_t maxCols = (m_frame-m_fencPic-m_picWidth + (16 - 1)) /
 16;
  +uint32_t blockSize = g_maxCUSize / (uint32_t)pow(2, depth);

 g_maxCUSize  cuGeom.depth

  +double qp_offset = 0;
  +uint32_t cnt = 0;
  +uint32_t idx;
  +
  +/* Use cuTree offsets if cuTree enabled and frame is referenced,
 else use AQ offsets */
  +bool isReferenced = IS_REFERENCED(m_frame);
  +double *qpoffs = (isReferenced  m_param-rc.cuTree) ?
 m_frame-m_lowres.qpCuTreeOffset : m_frame-m_lowres.qpAqOffset;

 the lookahead is generating FIX8 versions of these values, so integer
 math can be used in later parts of the encoder.

  +for (uint32_t block_yy = block_y; block_yy  block_y + blockSize
  block_yy  height; block_yy += 16)
  +{
  +for (uint32_t block_xx = block_x; block_xx  block_x +
 blockSize  block_xx  width; block_xx += 16)
  +{
  +idx = ((block_yy / 16) * (maxCols)) + (block_xx / 16);
  +qp_offset += qpoffs[idx];
  +cnt++;
  +}
  +}
  +
  +qp_offset /= cnt;
  +qp += qp_offset;
  +return x265_clip3(QP_MIN, QP_MAX_MAX, (int)(qp + 0.5));
  +}
  +
  diff -r b931c50d5501 -r c7182de74969 source/encoder/analysis.h
  --- a/source/encoder/analysis.h Wed Mar 11 21:58:02 2015 -0500
  +++ b/source/encoder/analysis.h Thu Mar 12 09:02:06 2015 +0530
  @@ -139,6 +139,8 @@
   /* generate residual and recon pixels for an entire CTU
 recursively (RD0) */
   void encodeResidue(const CUData parentCTU, const CUGeom cuGeom);
 
  +int calculateQpforCuSize(CUData ctu, const CUGeom cuGeom);
  +
   /* check whether current mode is the new best */
   inline void checkBestMode(Mode mode, uint32_t depth)
   {
  ___
  x265-devel mailing list
  x265-devel@videolan.org
  https://mailman.videolan.org/listinfo/x265-devel



 --
 Steve Borho
 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel



 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel


___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] rc: recompute planned frame size when using vbv with --qpfile

2015-03-11 Thread Aarthi Priya Thirumalai
I will send the other part as a different patch. It is to prevent drastic
qp changes from  vbv lookahead estimations due to possible mispredictions
by the default vbv frame size predictors.
On Mar 12, 2015 6:23 AM, Deepthi Nandakumar deep...@multicorewareinc.com
wrote:

 No, this is not. This is for a customer who wanted to be able to use
 qpfile with VBV. The first half is - I'm not sure about the second half of
 the patch.

 On Thu, Mar 12, 2015 at 1:44 AM, Steve Borho st...@borho.org wrote:

 On 03/11, aar...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Aarthi Thirumalai
  # Date 1425994215 -19800
  #  Tue Mar 10 19:00:15 2015 +0530
  # Node ID 9b7b93384e39e90cf2d4c0c0a53213abff362f70
  # Parent  8f148ac8dbe4b68e88ceff84f40e33b29e888dc9
  rc: recompute planned frame size when using vbv with --qpfile

 is this at all related to issue 111?

  diff -r 8f148ac8dbe4 -r 9b7b93384e39 source/encoder/ratecontrol.cpp
  --- a/source/encoder/ratecontrol.cpp  Tue Mar 10 15:46:36 2015 +0530
  +++ b/source/encoder/ratecontrol.cpp  Tue Mar 10 19:00:15 2015 +0530
  @@ -1067,7 +1067,15 @@
   {
   m_qp = (int32_t)(curFrame-m_forceqp + 0.5) - 1;
   m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);
  -rce-qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq =
 m_qp;
  +rce-qpaRc =curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
  +if (m_isAbr)
  +{
  +rce-qpNoVbv = rce-qpaRc;
  +m_lastQScaleFor[m_sliceType] = x265_qp2qScale(rce-qpaRc);
  +if (rce-poc == 0)
  + m_lastQScaleFor[P_SLICE] =
 m_lastQScaleFor[m_sliceType] * fabs(m_param-rc.ipFactor);
  +rce-frameSizePlanned = predictSize(m_pred[m_sliceType],
 rce-qpaRc, (double)m_currentSatd);
  +}
   }
   // Do not increment m_startEndOrder here. Make rateControlEnd of
 previous thread
   // to wait until rateControlUpdateStats of this frame is called
  @@ -1360,13 +1368,14 @@
   q += m_pbOffset;
 
   double qScale = x265_qp2qScale(q);
  +double lmin = 0, lmax = 0;
   if (m_isCbr)
   {
   qScale = tuneAbrQScaleFromFeedback(qScale);
   if (!m_isAbrReset)
   {
  -double lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
  -double lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
  + lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
  + lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
   qScale = x265_clip3(lmin, lmax, qScale);
   }
   q = x265_qScale2qp(qScale);
  @@ -1375,6 +1384,8 @@
   if (!m_2pass  m_isVbv)
   {
   qScale = clipQscale(curFrame, rce, qScale);
  +if (m_pred[m_sliceType].count == 1)
  +qScale = x265_clip3(lmin, lmax, qScale);
   m_lastQScaleFor[m_sliceType] = qScale;
   rce-frameSizePlanned = predictSize(m_pred[m_sliceType],
 qScale, (double)m_currentSatd);
   }
  @@ -1460,7 +1471,7 @@
* tolerances, the bit distribution approaches that of
 2pass. */
 
   double overflow = 1;
  -
  +double lqmin = 0, lqmax = 0;
   m_shortTermCplxSum *= 0.5;
   m_shortTermCplxCount *= 0.5;
   m_shortTermCplxSum += m_currentSatd /
 (CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);
  @@ -1494,7 +1505,6 @@
   {
   if (m_param-rc.rateControlMode != X265_RC_CRF)
   {
  -double lqmin = 0, lqmax = 0;
   lqmin = m_lastQScaleFor[m_sliceType] / m_lstep;
   lqmax = m_lastQScaleFor[m_sliceType] * m_lstep;
   if (!m_partialResidualFrames)
  @@ -1520,6 +1530,8 @@
   q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
   rce-qpNoVbv = x265_qScale2qp(q);
   q = clipQscale(curFrame, rce, q);
  +if (m_pred[m_sliceType].count == 1  m_framesDone  0)
  +q = x265_clip3(lqmin, lqmax, q);
   }
   m_lastQScaleFor[m_sliceType] = q;
   if ((m_curSlice-m_poc == 0 || m_lastQScaleFor[P_SLICE]  q)
  !(m_2pass  !m_isVbv))
  ___
  x265-devel mailing list
  x265-devel@videolan.org
  https://mailman.videolan.org/listinfo/x265-devel

 --
 Steve Borho
 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel



 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel


___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH] slicetype: fix crash when rc-lookahead = bframes

2015-03-09 Thread Aarthi Priya Thirumalai
crash occurs when lookaheadDepth equals bframes.
need to modify it CHECK(param-bframes *=* param-lookaheadDepth

On Mon, Mar 9, 2015 at 9:18 PM, Steve Borho st...@borho.org wrote:

 On 03/09, Deepthi Nandakumar wrote:
  slicetypeAnalyse::maxSearch also needs to be changed, or you could
 trigger
  another crash using --b-adapt 1.
 
  It seems to me, under the hood we're just incrementing lookaheadDepth.
 That
  may be the right thing to do here, or do a CHECK for lookaheadDepth =
  bframes?

 We have:

 CHECK(param-bframes  param-lookaheadDepth  !param-rc.bStatRead,
   Lookahead depth must be greater than the max consecutive bframe
 count);

 is this not sufficient?

 --
 Steve Borho
 ___
 x265-devel mailing list
 x265-devel@videolan.org
 https://mailman.videolan.org/listinfo/x265-devel

___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] slicetype: fix crash when rc-lookahead = bframes

2015-03-09 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1425883938 -19800
#  Mon Mar 09 12:22:18 2015 +0530
# Node ID 520ab30492f631b5502b309183f47efc0b8a9768
# Parent  043c2418864b0a3ada6f597e6def6ead73d90b5f
slicetype: fix crash when rc-lookahead = bframes.

diff -r 043c2418864b -r 520ab30492f6 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Fri Mar 06 13:15:55 2015 -0600
+++ b/source/encoder/slicetype.cpp  Mon Mar 09 12:22:18 2015 +0530
@@ -484,7 +484,7 @@
 memset(m_preframes, 0, sizeof(m_preframes));
 m_preTotal = m_preAcquired = m_preCompleted = 0;
 m_sliceTypeBusy = false;
-m_fullQueueSize = m_param-lookaheadDepth;
+m_fullQueueSize = X265_MAX(m_param-lookaheadDepth, m_param-bframes + 1);
 m_bAdaptiveQuant = m_param-rc.aqMode || m_param-bEnableWeightedPred || 
m_param-bEnableWeightedBiPred;
 
 /* If we have a thread pool and are using --b-adapt 2, it is generally
@@ -835,7 +835,7 @@
 {
 Lowres *frames[X265_LOOKAHEAD_MAX];
 Frame *list[X265_LOOKAHEAD_MAX];
-int maxSearch = X265_MIN(m_param-lookaheadDepth, X265_LOOKAHEAD_MAX);
+int maxSearch = X265_MIN(X265_MAX(m_param-lookaheadDepth, 
m_param-bframes + 1), X265_LOOKAHEAD_MAX);
 
 memset(frames, 0, sizeof(frames));
 memset(list, 0, sizeof(list));
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: fix crash in strict cbr when totalFrames = 0

2015-03-05 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1425624228 -19800
#  Fri Mar 06 12:13:48 2015 +0530
# Node ID fa0034f0e38d127fbf8343b63a54798b8350083e
# Parent  45deb0125890ab0211d0e256c74d91ede78d12d3
rc: fix crash in strict cbr when totalFrames = 0

diff -r 45deb0125890 -r fa0034f0e38d source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppThu Mar 05 20:39:08 2015 -0600
+++ b/source/encoder/encoder.cppFri Mar 06 12:13:48 2015 +0530
@@ -1667,7 +1667,7 @@
 if (p-rc.aqMode == X265_AQ_NONE  p-rc.cuTree == 0)
 p-rc.aqStrength = 0;
 
-if (p-totalFrames = 2 * ((float)p-fpsNum) / p-fpsDenom  
p-rc.bStrictCbr)
+if (p-totalFrames  p-totalFrames = 2 * ((float)p-fpsNum) / 
p-fpsDenom  p-rc.bStrictCbr)
 p-lookaheadDepth = p-totalFrames;
 
 if (p-scalingLists  p-internalCsp == X265_CSP_I444)
diff -r 45deb0125890 -r fa0034f0e38d source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppThu Mar 05 20:39:08 2015 -0600
+++ b/source/encoder/ratecontrol.cppFri Mar 06 12:13:48 2015 +0530
@@ -272,7 +272,7 @@
 x265_log(m_param, X265_LOG_WARNING, strict CBR set without CBR mode, 
ignored\n);
 m_param-rc.bStrictCbr = 0;
 }
-if (m_param-totalFrames = 2 * m_fps  m_param-rc.bStrictCbr) /* Strict 
CBR segment encode */
+if (m_param-totalFrames  m_param-totalFrames = 2 * m_fps  
m_param-rc.bStrictCbr) /* Strict CBR segment encode */
 {
 m_amortizeFraction = 0.85;
 m_amortizeFrames = m_param-totalFrames / 2;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] rc: fix to avoid false abr restarts

2015-02-26 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1423638042 -19800
#  Wed Feb 11 12:30:42 2015 +0530
# Node ID bd5a4f539fbc82298877b0ec3cc3bcf2794fbcd3
# Parent  0e89af0781ee95453846340cdbc61d2b21672798
rc: fix to avoid false abr restarts

diff -r 0e89af0781ee -r bd5a4f539fbc source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppWed Feb 25 18:32:04 2015 -0800
+++ b/source/encoder/ratecontrol.cppWed Feb 11 12:30:42 2015 +0530
@@ -219,6 +219,7 @@
 m_statFileOut = NULL;
 m_cutreeStatFileOut = m_cutreeStatFileIn = NULL;
 m_rce2Pass = NULL;
+m_lastBsliceSatdCost = 0;
 
 // vbv initialization
 m_param-rc.vbvBufferSize = x265_clip3(0, 200, 
m_param-rc.vbvBufferSize);
@@ -357,6 +358,8 @@
 m_encodedBitsWindow[i] = 0;
 }
 m_sliderPos = 0;
+m_isPatternPresent = false;
+m_numBframesInPattern = 0;
 
 /* 720p videos seem to be a good cutoff for cplxrSum */
 double tuneCplxFactor = (m_param-rc.cuTree  m_ncu  3600) ? 2.5 : 1;
@@ -1009,6 +1012,26 @@
 /* Update rce for use in rate control VBV later */
 rce-lastSatd = m_currentSatd;
 X265_CHECK(rce-lastSatd, satdcost cannot be zero\n);
+/* Detect a pattern for B frames with same SATDcost to identify a 
series of static frames
+ * and the P frame at the end of the series marks a possible case 
for ABR reset logic */
+if (m_param-bframes)
+{
+if (m_sliceType != B_SLICE  m_numBframesInPattern  
m_param-bframes)
+{
+m_isPatternPresent = true;
+}
+else if (m_sliceType == B_SLICE  !IS_REFERENCED(curFrame))
+{
+if (m_currentSatd != m_lastBsliceSatdCost  
!rce-bLastMiniGopBFrame)
+{
+m_isPatternPresent = false;
+m_lastBsliceSatdCost = m_currentSatd;
+m_numBframesInPattern = 0;
+}
+else if (m_currentSatd == m_lastBsliceSatdCost)
+m_numBframesInPattern++;
+}
+}
 }
 double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
 q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
@@ -1288,7 +1311,7 @@
 slidingWindowCplxSum *= 0.5;
 if (!m_satdCostWindow[pos])
 break;
-slidingWindowCplxSum += m_satdCostWindow[pos] / 
(CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);
+slidingWindowCplxSum += m_satdCostWindow[pos];
 }
 rce-movingAvgSum = slidingWindowCplxSum;
 m_satdCostWindow[m_sliderPos % s_slidingWindowFrames] = 
rce-lastSatd;
@@ -1563,9 +1586,11 @@
 // Check if current Slice is a scene cut that follows low detailed/blank 
frames
 if (rce-lastSatd  4 * rce-movingAvgSum)
 {
-if (!m_isAbrReset  rce-movingAvgSum  0)
+if (!m_isAbrReset  rce-movingAvgSum  0
+ (m_isPatternPresent || !m_param-bframes))
 {
-int64_t shrtTermWantedBits = (int64_t) (X265_MIN(m_sliderPos, 
s_slidingWindowFrames) * m_bitrate * m_frameDuration);
+int pos = X265_MAX(m_sliderPos - m_param-frameNumThreads, 0);
+int64_t shrtTermWantedBits = (int64_t) (X265_MIN(pos, 
s_slidingWindowFrames) * m_bitrate * m_frameDuration);
 int64_t shrtTermTotalBitsSum = 0;
 // Reset ABR if prev frames are blank to prevent further sudden 
overflows/ high bit rate spikes.
 for (int i = 0; i  s_slidingWindowFrames ; i++)
@@ -1581,7 +1606,7 @@
 m_lastAbrResetPoc = rce-poc;
 }
 }
-else
+else if (m_isAbrReset  isFrameDone)
 {
 // Clear flag to reset ABR and continue as usual.
 m_isAbrReset = false;
diff -r 0e89af0781ee -r bd5a4f539fbc source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h  Wed Feb 25 18:32:04 2015 -0800
+++ b/source/encoder/ratecontrol.h  Wed Feb 11 12:30:42 2015 +0530
@@ -181,6 +181,11 @@
 int64_t  m_satdCostWindow[50];
 int  m_sliderPos;
 int64_t  m_encodedBitsWindow[50];
+/* To detect a pattern of low detailed static frames in single pass ABR 
using satdcosts */
+bool m_isPatternPresent;
+int64_t m_lastBsliceSatdCost;
+int m_numBframesInPattern;
+
 /* a common variable on which rateControlStart, rateControlEnd and 
rateControUpdateStats waits to
  * sync the calls to these functions. For example
  * -F2:
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] slicetype: fix the BRef cost estimates in vbv lookahead

2015-02-15 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1424063038 -19800
#  Mon Feb 16 10:33:58 2015 +0530
# Node ID b14b95a4565986c9678442dbc510fed974bb413c
# Parent  164bd8337e72624a7605424cc3bdc67042dd5294
slicetype: fix the BRef cost estimates in vbv lookahead.

diff -r 164bd8337e72 -r b14b95a45659 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Sun Feb 15 20:13:22 2015 -0600
+++ b/source/encoder/slicetype.cpp  Mon Feb 16 10:33:58 2015 +0530
@@ -580,7 +580,9 @@
 curNonB++;
 int nextNonB = keyframe ? prevNonB : curNonB;
 int nextB = prevNonB + 1;
-int nextBRef = 0;
+int nextBRef = 0, curBRef = 0;
+if (m_param-bBPyramid  curNonB - prevNonB  1)
+curBRef = (prevNonB + curNonB + 1) / 2;
 int miniGopEnd = keyframe ? prevNonB : curNonB;
 while (curNonB  numFrames + !keyframe)
 {
@@ -597,7 +599,6 @@
 {
 frames[j]-plannedSatd[frames[j]-indB] = 
frames[nextNonB]-plannedSatd[idx];
 frames[j]-plannedType[frames[j]-indB++] = 
frames[nextNonB]-plannedType[idx];
-
 }
 }
 idx++;
@@ -629,12 +630,12 @@
 
 for (int j = nextB; j  miniGopEnd; j++)
 {
-if (nextBRef  i == nextBRef)
+if (curBRef  curBRef == i)
 break;
 if (j = i  j !=nextBRef)
 continue;
 frames[j]-plannedSatd[frames[j]-indB] = satdCost;
-frames[j]-plannedType[frames[j]-indB++] = X265_TYPE_B;
+frames[j]-plannedType[frames[j]-indB++] = type;
 }
 }
 prevNonB = curNonB;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] slicetype: fix the BRef cost estimates in vbv lookahead

2015-02-15 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1424063038 -19800
#  Mon Feb 16 10:33:58 2015 +0530
# Node ID 540697e77bbce88e1065035d41b5222da45318cb
# Parent  164bd8337e72624a7605424cc3bdc67042dd5294
slicetype: fix the BRef cost estimates in vbv lookahead.

diff -r 164bd8337e72 -r 540697e77bbc source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp  Sun Feb 15 20:13:22 2015 -0600
+++ b/source/encoder/slicetype.cpp  Mon Feb 16 10:33:58 2015 +0530
@@ -580,7 +580,9 @@
 curNonB++;
 int nextNonB = keyframe ? prevNonB : curNonB;
 int nextB = prevNonB + 1;
-int nextBRef = 0;
+int nextBRef = 0, curBRef = 0;
+if (m_param-bBPyramid  curNonB - prevNonB  1)
+curBRef = (prevNonB + curNonB + 1) / 2;
 int miniGopEnd = keyframe ? prevNonB : curNonB;
 while (curNonB  numFrames + !keyframe)
 {
@@ -597,7 +599,6 @@
 {
 frames[j]-plannedSatd[frames[j]-indB] = 
frames[nextNonB]-plannedSatd[idx];
 frames[j]-plannedType[frames[j]-indB++] = 
frames[nextNonB]-plannedType[idx];
-
 }
 }
 idx++;
@@ -622,19 +623,19 @@
 satdCost = vbvFrameCost(frames, nextBRef, curNonB, i);
 }
 else
-satdCost = vbvFrameCost(frames, prevNonB, nextNonB, i);
+satdCost = vbvFrameCost(frames, prevNonB, curNonB, i);
 frames[nextNonB]-plannedSatd[idx] = satdCost;
 frames[nextNonB]-plannedType[idx] = type;
 /* Save the nextB Cost in each B frame of the current miniGop */
 
 for (int j = nextB; j  miniGopEnd; j++)
 {
-if (nextBRef  i == nextBRef)
+if (curBRef  curBRef == i)
 break;
 if (j = i  j !=nextBRef)
 continue;
 frames[j]-plannedSatd[frames[j]-indB] = satdCost;
-frames[j]-plannedType[frames[j]-indB++] = X265_TYPE_B;
+frames[j]-plannedType[frames[j]-indB++] = type;
 }
 }
 prevNonB = curNonB;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH] entropy: fix bug in coding HRD parameters based on the temporal layers

2015-02-10 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1423556473 -19800
#  Tue Feb 10 13:51:13 2015 +0530
# Node ID 494200c9cbf5cc597b37688e254a8f93db475963
# Parent  da3302cc67fb06c62726d175593fdfda0db2fd54
entropy: fix bug in coding HRD parameters based on the temporal layers.

diff -r da3302cc67fb -r 494200c9cbf5 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cppMon Feb 09 16:45:31 2015 -0600
+++ b/source/encoder/entropy.cppTue Feb 10 13:51:13 2015 +0530
@@ -136,7 +136,7 @@
 WRITE_FLAG(sps.bUseStrongIntraSmoothing, 
sps_strong_intra_smoothing_enable_flag);
 
 WRITE_FLAG(1, vui_parameters_present_flag);
-codeVUI(sps.vuiParameters);
+codeVUI(sps.vuiParameters, sps.maxTempSubLayers - 1);
 
 WRITE_FLAG(0, sps_extension_flag);
 }
@@ -239,7 +239,7 @@
 }
 }
 
-void Entropy::codeVUI(const VUI vui)
+void Entropy::codeVUI(const VUI vui, int maxSubTLayersMinusOne)
 {
 WRITE_FLAG(vui.aspectRatioInfoPresentFlag,  
aspect_ratio_info_present_flag);
 if (vui.aspectRatioInfoPresentFlag)
@@ -297,7 +297,7 @@
 
 WRITE_FLAG(vui.hrdParametersPresentFlag,  
vui_hrd_parameters_present_flag);
 if (vui.hrdParametersPresentFlag)
-codeHrdParameters(vui.hrdParameters);
+codeHrdParameters(vui.hrdParameters, maxSubTLayersMinusOne);
 
 WRITE_FLAG(0, bitstream_restriction_flag);
 }
@@ -344,10 +344,8 @@
 }
 }
 
-void Entropy::codeHrdParameters(const HRDInfo hrd)
+void Entropy::codeHrdParameters(const HRDInfo hrd, int maxSubTLayersMinusOne)
 {
-for (int i = 0; i = 1; i++)
-{
 WRITE_FLAG(1, nal_hrd_parameters_present_flag);
 WRITE_FLAG(0, vcl_hrd_parameters_present_flag);
 WRITE_FLAG(0, sub_pic_hrd_params_present_flag);
@@ -358,15 +356,16 @@
 WRITE_CODE(hrd.initialCpbRemovalDelayLength - 1, 5, 
initial_cpb_removal_delay_length_minus1);
 WRITE_CODE(hrd.cpbRemovalDelayLength - 1,5, 
au_cpb_removal_delay_length_minus1);
 WRITE_CODE(hrd.dpbOutputDelayLength - 1, 5, 
dpb_output_delay_length_minus1);
+for (int i = 0; i = maxSubTLayersMinusOne; i++)
+{
+WRITE_FLAG(1, fixed_pic_rate_general_flag);
+WRITE_UVLC(0, elemental_duration_in_tc_minus1);
+WRITE_UVLC(0, cpb_cnt_minus1);
 
-WRITE_FLAG(1, fixed_pic_rate_general_flag);
-WRITE_UVLC(0, elemental_duration_in_tc_minus1);
-WRITE_UVLC(0, cpb_cnt_minus1);
-
-WRITE_UVLC(hrd.bitRateValue - 1, bit_rate_value_minus1);
-WRITE_UVLC(hrd.cpbSizeValue - 1, cpb_size_value_minus1);
-WRITE_FLAG(hrd.cbrFlag, cbr_flag);
-}
+WRITE_UVLC(hrd.bitRateValue - 1, bit_rate_value_minus1);
+WRITE_UVLC(hrd.cpbSizeValue - 1, cpb_size_value_minus1);
+WRITE_FLAG(hrd.cbrFlag, cbr_flag);
+}
 }
 
 void Entropy::codeAUD(const Slice slice)
diff -r da3302cc67fb -r 494200c9cbf5 source/encoder/entropy.h
--- a/source/encoder/entropy.h  Mon Feb 09 16:45:31 2015 -0600
+++ b/source/encoder/entropy.h  Tue Feb 10 13:51:13 2015 +0530
@@ -142,9 +142,9 @@
 void codeVPS(const VPS vps);
 void codeSPS(const SPS sps, const ScalingList scalingList, const 
ProfileTierLevel ptl);
 void codePPS(const PPS pps);
-void codeVUI(const VUI vui);
+void codeVUI(const VUI vui, int maxSubTLayersMinusOne);
 void codeAUD(const Slice slice);
-void codeHrdParameters(const HRDInfo hrd);
+void codeHrdParameters(const HRDInfo hrd, int maxSubTLayersMinusOne);
 
 void codeSliceHeader(const Slice slice, FrameData encData);
 void codeSliceHeaderWPPEntryPoints(const Slice slice, const uint32_t 
*substreamSizes, uint32_t maxOffset);
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 2 of 2] cli: add cli option --temporal-layers/--no-temporal-layers to enable/disable temporal layering

2015-02-03 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1422960762 -19800
#  Tue Feb 03 16:22:42 2015 +0530
# Node ID 3646ebea807a9e58d1b352627d09b0607abfab5d
# Parent  830d29c97117c609585b7c18cc75f120a89ce79e
cli: add cli option --temporal-layers/--no-temporal-layers to enable/disable 
temporal layering.

by default, it is turned off.

diff -r 830d29c97117 -r 3646ebea807a doc/reST/cli.rst
--- a/doc/reST/cli.rst  Tue Feb 03 16:21:21 2015 +0530
+++ b/doc/reST/cli.rst  Tue Feb 03 16:22:42 2015 +0530
@@ -171,8 +171,6 @@
Over-allocation of frame threads will not improve performance, it
will generally just increase memory use.
 
-   **Values:** any value between 8 and 16. Default is 0, auto-detect
-
 .. option:: --threads integer
 
Number of threads to allocate for the worker thread pool  This pool
@@ -1376,6 +1374,12 @@
1. MD5
2. CRC
3. Checksum
+   
+.. option:: --temporal-layers,--no-temporal-layers
+
+   Enable Temporal Sub Layers in the bitstream and signal the temporal 
layer ids
+   in the VPS, SPS and coded slice NAL unit headers. As of now, 
+   maxTemporalSubLayers that can be enabled = 2 when this option is turned 
on. 
 
 Debugging options
 =
diff -r 830d29c97117 -r 3646ebea807a source/CMakeLists.txt
--- a/source/CMakeLists.txt Tue Feb 03 16:21:21 2015 +0530
+++ b/source/CMakeLists.txt Tue Feb 03 16:22:42 2015 +0530
@@ -21,7 +21,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 43)
+set(X265_BUILD 44)
 configure_file(${PROJECT_SOURCE_DIR}/x265.def.in
${PROJECT_BINARY_DIR}/x265.def)
 configure_file(${PROJECT_SOURCE_DIR}/x265_config.h.in
@@ -240,11 +240,6 @@
 add_subdirectory(profile/vtune)
 endif(ENABLE_VTUNE)
 
-option(DETAILED_CU_STATS Enable internal profiling of encoder work OFF)
-if(DETAILED_CU_STATS)
-add_definitions(-DDETAILED_CU_STATS)
-endif(DETAILED_CU_STATS)
-
 add_subdirectory(encoder)
 add_subdirectory(common)
 
diff -r 830d29c97117 -r 3646ebea807a source/common/param.cpp
--- a/source/common/param.cpp   Tue Feb 03 16:21:21 2015 +0530
+++ b/source/common/param.cpp   Tue Feb 03 16:22:42 2015 +0530
@@ -606,6 +606,7 @@
 p-scenecutThreshold = atoi(value);
 }
 }
+OPT(temporal-layers) p-bEnableTemporalSubLayers = atobool(value);
 OPT(keyint) p-keyframeMax = atoi(value);
 OPT(min-keyint) p-keyframeMin = atoi(value);
 OPT(rc-lookahead) p-lookaheadDepth = atoi(value);
diff -r 830d29c97117 -r 3646ebea807a source/x265cli.h
--- a/source/x265cli.h  Tue Feb 03 16:21:21 2015 +0530
+++ b/source/x265cli.h  Tue Feb 03 16:22:42 2015 +0530
@@ -193,6 +193,8 @@
 { analysis-mode,  required_argument, NULL, 0 },
 { analysis-file,  required_argument, NULL, 0 },
 { strict-cbr,   no_argument, NULL, 0 },
+{ temporal-layers,  no_argument, NULL, 0 },
+{ no-temporal-layers,   no_argument, NULL, 0 },
 { 0, 0, 0, 0 },
 { 0, 0, 0, 0 },
 { 0, 0, 0, 0 },
@@ -373,6 +375,7 @@
 H0(   --[no-]audEmit access unit delimiters at the 
start of each access unit. Default %s\n, 
OPT(param-bEnableAccessUnitDelimiters));
 H0(   --[no-]hrdEnable HRD parameters signaling. 
Default %s\n, OPT(param-bEmitHRDSEI));
 H0(   --[no-]repeat-headers Emit SPS and PPS headers at each 
keyframe. Default %s\n, OPT(param-bRepeatHeaders));
+H0(   --[no-]temporal-layersEnable temporal layer support to 
obtain bitstreams with half the frame rate. Default %s\n, 
OPT(param-bEnableTemporalSubLayers));
 H1(   --hash integer  Decoded Picture Hash SEI 0: disabled, 
1: MD5, 2: CRC, 3: Checksum. Default %d\n, param-decodedPictureHashSEI);
 H1(\nReconstructed video options (debugging):\n);
 H1(-r/--recon filenameReconstructed raw image YUV or Y4M 
output file name\n);
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


[x265] [PATCH 1 of 2] encoder: Add support for Temporal Layering of the encoded bitstream

2015-02-03 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1422960681 -19800
#  Tue Feb 03 16:21:21 2015 +0530
# Node ID 830d29c97117c609585b7c18cc75f120a89ce79e
# Parent  4583eda4cf55e9a7f5c11d1ea660367f3822af53
encoder: Add support for Temporal Layering of the encoded bitstream.

Implements Temporal Sub Layers while encoding, signals NAL units of coded slices
with their temporalId. Output bitstreams can be extracted either at the base 
temporal layer
(layer 0) with roughly half the frame rate or at a higher temporal layer (layer 
1)
that decodes all the frames in the sequence.

diff -r 4583eda4cf55 -r 830d29c97117 source/common/param.cpp
--- a/source/common/param.cpp   Mon Feb 02 17:03:40 2015 +0530
+++ b/source/common/param.cpp   Tue Feb 03 16:21:21 2015 +0530
@@ -181,6 +181,7 @@
 param-bIntraInBFrames = 0;
 param-bLossless = 0;
 param-bCULossless = 0;
+param-bEnableTemporalSubLayers = 0;
 
 /* Rate control options */
 param-rc.vbvMaxBitrate = 0;
diff -r 4583eda4cf55 -r 830d29c97117 source/common/slice.h
--- a/source/common/slice.h Mon Feb 02 17:03:40 2015 +0530
+++ b/source/common/slice.h Tue Feb 03 16:21:21 2015 +0530
@@ -149,6 +149,7 @@
 
 struct VPS
 {
+uint32_t maxTempSubLayers;
 uint32_t numReorderPics;
 uint32_t maxDecPicBuffering;
 HRDInfo  hrdParameters;
@@ -228,6 +229,7 @@
 bool bUseAMP; // use param
 uint32_t maxAMPDepth;
 
+uint32_t maxTempSubLayers; // max number of Temporal Sub layers
 uint32_t maxDecPicBuffering; // these are dups of VPS values
 int  numReorderPics;
 int  maxLatencyIncrease;
diff -r 4583eda4cf55 -r 830d29c97117 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Feb 02 17:03:40 2015 +0530
+++ b/source/encoder/encoder.cppTue Feb 03 16:21:21 2015 +0530
@@ -669,6 +669,14 @@
 /* determine references, setup RPS, etc */
 m_dpb-prepareEncode(frameEnc);
 
+/* If temporal Layers are enabled, set tempLayer and NAL Unit Type.
+ * For now, there are a max of 2 layers, with the non Referenced B 
frames
+ * forming the temporal sublayer and other referenced frames are 
on the base layer */
+if (!frameEnc-m_encData-m_bHasReferences  
m_param-bEnableTemporalSubLayers)
+{
+frameEnc-m_encData-m_slice-m_nalUnitType = 
NAL_UNIT_CODED_SLICE_TSA_N;
+}
+
 if (m_param-rc.rateControlMode != X265_RC_CQP)
 m_lookahead-getEstimatedPictureCost(frameEnc);
 
@@ -1413,6 +1421,7 @@
 sps-bUseAMP = m_param-bEnableAMP;
 sps-maxAMPDepth = m_param-bEnableAMP ? g_maxCUDepth : 0;
 
+sps-maxTempSubLayers = m_param-bEnableTemporalSubLayers ? 2 : 1;
 sps-maxDecPicBuffering = m_vps.maxDecPicBuffering;
 sps-numReorderPics = m_vps.numReorderPics;
 sps-maxLatencyIncrease = m_param-bframes;
@@ -1622,6 +1631,19 @@
 p-bDistributeMotionEstimation = p-bDistributeModeAnalysis = 0;
 }
 
+if (p-bEnableTemporalSubLayers)
+{
+if (p-bFrameAdaptive)
+x265_log(p, X265_LOG_WARNING, Scalable Video Coding needs fixed 
GOP structure, requires --b-adapt 0\n);
+p-bFrameAdaptive = 0;
+if (p-scenecutThreshold)
+x265_log(p, X265_LOG_WARNING, Scalable Video Coding needs fixed 
GOP structure, requires --no -scenecut\n);
+p-scenecutThreshold = 0;
+if (p-bframes != 3)
+x265_log(p, X265_LOG_WARNING, Ideally 3 bframes are needed to 
generate a base temporal layer bitstream with half the fps, requires --bframes 
3\n);
+p-bframes = 3;
+}
+
 m_bframeDelay = p-bframes ? (p-bBPyramid ? 2 : 1) : 0;
 
 p-bFrameBias = X265_MIN(X265_MAX(-90, p-bFrameBias), 100);
diff -r 4583eda4cf55 -r 830d29c97117 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cppMon Feb 02 17:03:40 2015 +0530
+++ b/source/encoder/entropy.cppTue Feb 03 16:21:21 2015 +0530
@@ -51,17 +51,22 @@
 WRITE_CODE(0,   4, vps_video_parameter_set_id);
 WRITE_CODE(3,   2, vps_reserved_three_2bits);
 WRITE_CODE(0,   6, vps_reserved_zero_6bits);
-WRITE_CODE(0,   3, vps_max_sub_layers_minus1);
-WRITE_FLAG(1,  vps_temporal_id_nesting_flag);
+WRITE_CODE(vps.maxTempSubLayers - 1,   3, vps_max_sub_layers_minus1);
+// Temporal Id Nesting is disabled only when maxTemporalLayers  1
+WRITE_FLAG(!(vps.maxTempSubLayers - 1),   
vps_temporal_id_nesting_flag);
 WRITE_CODE(0x, 16, vps_reserved__16bits);
 
-codeProfileTier(vps.ptl);
+codeProfileTier(vps.ptl ,vps.maxTempSubLayers - 1);
 
 WRITE_FLAG(true, vps_sub_layer_ordering_info_present_flag);
-WRITE_UVLC(vps.maxDecPicBuffering - 1, 
vps_max_dec_pic_buffering_minus1[i]);
-WRITE_UVLC(vps.numReorderPics, vps_num_reorder_pics[i]);
 
-WRITE_UVLC(0,vps_max_latency_increase_plus1[i]);
+for (uint32_t i = 0; i

[x265] [PATCH] encoder: Add support for Temporal Layering of the encoded bitstream

2015-02-02 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1422885719 -19800
#  Mon Feb 02 19:31:59 2015 +0530
# Node ID e241b255b992fdf5c83c1744240ff5a6beaa188b
# Parent  1760823cdd46572b5db364cb93495bbff6908e17
encoder: Add support for Temporal Layering of the encoded bitstream.

use --temporal-layers to enable Temporal Sub Layers while encoding, signals NAL 
units of coded slices
with their temporalId. Output bitstreams can be extracted either at the base 
temporal layer
(layer 0) with roughly half the frame rate or at a higher temporal layer (layer 
1)
that decodes all the frames in the sequence.

diff -r 1760823cdd46 -r e241b255b992 doc/reST/cli.rst
--- a/doc/reST/cli.rst  Mon Feb 02 16:27:07 2015 +0530
+++ b/doc/reST/cli.rst  Mon Feb 02 19:31:59 2015 +0530
@@ -1048,15 +1048,6 @@
target bitrate in CBR mode. Bitrate adherence is prioritised
over quality. Rate tolerance is reduced to 50%. Default disabled.

-   This option is for use-cases which require the final average bitrate 
-   to be within very strict limits of the target - preventing overshoots 
-   completely, and achieve bitrates within 5% of target bitrate, 
-   especially in short segment encodes. Typically, the encoder stays 
-   conservative, waiting until there is enough feedback in terms of 
-   encoded frames to control QP. strict-cbr allows the encoder to be 
-   more aggressive in hitting the target bitrate even for short segment 
-   videos. Experimental.
-   
 .. option:: --cbqpoffs integer
 
Offset of Cb chroma QP from the luma QP selected by rate control.
@@ -1097,6 +1088,12 @@
The maximum single adjustment in QP allowed to rate control. Default
4
 
+.. option:: --ratetol float
+
+   The degree of rate fluctuation that x265 tolerates. Rate tolerance
+   is used along with overflow (difference between actual and target
+   bitrate), to adjust qp. Default is 1.0
+
 .. option:: --qblur float
 
Temporally blur quants. Default 0.5
@@ -1374,6 +1371,12 @@
1. MD5
2. CRC
3. Checksum
+   
+.. option:: --temporal-layers,--no-temporal-layers
+
+   Enable Temporal Sub Layers in the bitstream and signal the temporal 
layer ids
+   in the VPS, SPS and coded slice NAL unit headers. As of now, 
+   maxTemporalSubLayers that can be enabled = 2 when this option is turned 
on. 
 
 Debugging options
 =
diff -r 1760823cdd46 -r e241b255b992 source/common/param.cpp
--- a/source/common/param.cpp   Mon Feb 02 16:27:07 2015 +0530
+++ b/source/common/param.cpp   Mon Feb 02 19:31:59 2015 +0530
@@ -181,6 +181,7 @@
 param-bIntraInBFrames = 0;
 param-bLossless = 0;
 param-bCULossless = 0;
+param-bEnableTemporalSubLayers = 1;
 
 /* Rate control options */
 param-rc.vbvMaxBitrate = 0;
@@ -806,6 +807,10 @@
 OPT(scaling-list) p-scalingLists = strdup(value);
 OPT(lambda-file) p-rc.lambdaFileName = strdup(value);
 OPT(analysis-file) p-analysisFileName = strdup(value);
+OPT(temporal-layers)
+{
+p-bEnableTemporalSubLayers = atobool(value);
+}
 else
 return X265_PARAM_BAD_NAME;
 #undef OPT
diff -r 1760823cdd46 -r e241b255b992 source/common/slice.h
--- a/source/common/slice.h Mon Feb 02 16:27:07 2015 +0530
+++ b/source/common/slice.h Mon Feb 02 19:31:59 2015 +0530
@@ -149,6 +149,7 @@
 
 struct VPS
 {
+uint32_t maxTempSubLayers;
 uint32_t numReorderPics;
 uint32_t maxDecPicBuffering;
 HRDInfo  hrdParameters;
@@ -228,6 +229,7 @@
 bool bUseAMP; // use param
 uint32_t maxAMPDepth;
 
+uint32_t maxTempSubLayers; // max number of Temporal Sub layers
 uint32_t maxDecPicBuffering; // these are dups of VPS values
 int  numReorderPics;
 int  maxLatencyIncrease;
diff -r 1760823cdd46 -r e241b255b992 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cppMon Feb 02 16:27:07 2015 +0530
+++ b/source/encoder/encoder.cppMon Feb 02 19:31:59 2015 +0530
@@ -1331,6 +1331,7 @@
 sps-bUseAMP = m_param-bEnableAMP;
 sps-maxAMPDepth = m_param-bEnableAMP ? g_maxCUDepth : 0;
 
+sps-maxTempSubLayers = m_param-bEnableTemporalSubLayers ? 2 : 1;
 sps-maxDecPicBuffering = m_vps.maxDecPicBuffering;
 sps-numReorderPics = m_vps.numReorderPics;
 sps-maxLatencyIncrease = m_param-bframes;
@@ -1540,6 +1541,16 @@
 p-bDistributeMotionEstimation = p-bDistributeModeAnalysis = 0;
 }
 
+if (p-bEnableTemporalSubLayers)
+{
+if (p-bFrameAdaptive)
+x265_log(p, X265_LOG_WARNING, Scalable Video Coding needs fixed 
GOP structure, requires --b-adapt 0\n);
+p-bFrameAdaptive = 0;
+if (p-scenecutThreshold)
+x265_log(p, X265_LOG_WARNING, Scalable Video Coding needs fixed 
GOP structure, requires --scenecut 0\n);
+p-scenecutThreshold = 0;
+}
+
 m_bframeDelay = p-bframes ? (p-bBPyramid ? 2 : 1

[x265] [PATCH] rc: fix bug in using strict-cbr option

2015-01-13 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1421151120 -19800
#  Tue Jan 13 17:42:00 2015 +0530
# Node ID 23dc2db8baad588c0c1e10aac4e90fc5d5008f9d
# Parent  50a2071500dc4b813edb357c298867931bbf42a1
rc: fix bug in using strict-cbr option

diff -r 50a2071500dc -r 23dc2db8baad source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppMon Jan 12 20:01:58 2015 +0530
+++ b/source/encoder/ratecontrol.cppTue Jan 13 17:42:00 2015 +0530
@@ -407,7 +407,7 @@
 m_param-bEmitHRDSEI = 0;
 }
 m_isCbr = m_param-rc.rateControlMode == X265_RC_ABR  m_isVbv  
!m_2pass  m_param-rc.vbvMaxBitrate = m_param-rc.bitrate;
-if (m_param-rc.bStrictCbr  m_isCbr)
+if (m_param-rc.bStrictCbr  !m_isCbr)
 {
 x265_log(m_param, X265_LOG_WARNING, strict CBR set without CBR mode, 
ignored\n);
 m_param-rc.bStrictCbr = 0;
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel


Re: [x265] [PATCH 2 of 2] rc: restrict low tolerance for bitrate fluctuations to strict-cbr option

2015-01-11 Thread Aarthi Priya Thirumalai
# HG changeset patch
# User Aarthi Thirumalai
# Date 1419064540 -19800
#  Sat Dec 20 14:05:40 2014 +0530
# Node ID 1e7de45ddd54a1af7feab49d807c3fde7d34e1f8
# Parent  d55fed4ebcd22823f8ffb878fa898b5d288cbb6a
rc: restrict low tolerance for bitrate fluctuations to strict-cbr option

diff -r d55fed4ebcd2 -r 1e7de45ddd54 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Tue Dec 23 16:32:30 2014 +0530
+++ b/source/encoder/ratecontrol.cpp Sat Dec 20 14:05:40 2014 +0530
@@ -1759,7 +1759,7 @@
 for (int j = 0; bufferFillCur = 0; j++)
 {
 int type = curFrame-m_lowres.plannedType[j];
-if (type == X265_TYPE_AUTO)
+if (type == X265_TYPE_AUTO || totalDuration = 1.0)
 break;
 totalDuration += m_frameDuration;
 double wantedFrameSize = m_vbvMaxRate *
m_frameDuration;
@@ -1773,17 +1773,21 @@
 bufferFillCur -= curBits;
 }

-/* Try to get the buffer no more than 80% filled, but
don't set an impossible goal. */
-double tol = isIFramePresent ? 1 / totalDuration :
totalDuration  0.5 ? 2 : 1;
-targetFill = X265_MIN(m_bufferFill + totalDuration *
m_vbvMaxRate * 0.5 , m_bufferSize * (1 - 0.8 * totalDuration * tol));
+/* Try to get the buffer at least 50% filled, but don't
set an impossible goal. */
+double finalDur = 1;
+if (m_param-rc.bStrictCbr)
+{
+finalDur = x265_clip3(0.4, 1.0, totalDuration);
+}
+targetFill = X265_MIN(m_bufferFill + totalDuration *
m_vbvMaxRate * 0.5 , m_bufferSize * (1 - 0.5 * finalDur));
 if (bufferFillCur  targetFill)
 {
 q *= 1.01;
 loopTerminate |= 1;
 continue;
 }
-/* Try to get the buffer atleast 50% filled, but don't set
an impossible goal. */
-targetFill = x265_clip3(m_bufferSize - (m_bufferSize *
totalDuration * 0.5), m_bufferSize, m_bufferFill - totalDuration *
m_vbvMaxRate * 0.5);
+/* Try to get the buffer not more than 80% filled, but
don't set an impossible goal. */
+targetFill = x265_clip3(m_bufferSize * (1 - 0.2 *
finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
 if (m_isCbr  bufferFillCur  targetFill)
 {
 q /= 1.01;
@@ -1976,7 +1980,7 @@
 if (row  sps.numCuInHeight - 1)
 {
 /* More threads means we have to be more cautious in letting
ratecontrol use up extra bits. */
-double rcTol = (bufferLeftPlanned * 0.2) /
m_param-frameNumThreads * m_param-rc.rateTolerance;
+double rcTol = bufferLeftPlanned / m_param-frameNumThreads *
m_param-rc.rateTolerance;
 int32_t encodedBitsSoFar = 0;
 double accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv,
encodedBitsSoFar);

@@ -1994,7 +1998,7 @@

 while (qpVbv  qpMax
 ((accFrameBits  rce-frameSizePlanned + rcTol) ||
-   (rce-bufferFill - accFrameBits  bufferLeftPlanned *
0.2) ||
+   (rce-bufferFill - accFrameBits  bufferLeftPlanned *
0.5) ||
(accFrameBits  rce-frameSizePlanned  qpVbv 
rce-qpNoVbv)))
 {
 qpVbv += stepSize;


On Sun, Jan 11, 2015 at 3:57 PM, Aarthi Priya Thirumalai 
aar...@multicorewareinc.com wrote:

 no, there were a few conflicts because my local tip wasn't updated.
 Sending again..

 On Thu, Jan 8, 2015 at 8:02 PM, Steve Borho st...@borho.org wrote:

 On 01/07, aar...@multicorewareinc.com wrote:
  # HG changeset patch
  # User Aarthi Thirumalai
  # Date 1419064540 -19800
  #  Sat Dec 20 14:05:40 2014 +0530
  # Node ID 5d658640bcf115f2add4da1619eeaec50177973f
  # Parent  9b30c4b16dfc4c673b57ee4c567fa8956a41e2fc
  rc: restrict low tolerance for bitrate fluctuations to strict-cbr option

 this patch isn't applying; perhaps it depends on the RCstart/stop patch

  diff -r 9b30c4b16dfc -r 5d658640bcf1 source/encoder/ratecontrol.cpp
  --- a/source/encoder/ratecontrol.cpp  Tue Dec 23 16:32:30 2014 +0530
  +++ b/source/encoder/ratecontrol.cpp  Sat Dec 20 14:05:40 2014 +0530
  @@ -1759,7 +1759,7 @@
   for (int j = 0; bufferFillCur = 0; j++)
   {
   int type = curFrame-m_lowres.plannedType[j];
  -if (type == X265_TYPE_AUTO)
  +if (type == X265_TYPE_AUTO || totalDuration = 1.0)
   break;
   totalDuration += m_frameDuration;
   double wantedFrameSize = m_vbvMaxRate *
 m_frameDuration;
  @@ -1773,17 +1773,21 @@
   bufferFillCur -= curBits;
   }
 
  -/* Try to get the buffer no more

[x265] [PATCH] rc: control bitrate overshoots during midframe encodes in strict-cbr

2015-01-11 Thread aarthi
# HG changeset patch
# User Aarthi Thirumalai
# Date 1420638035 -19800
#  Wed Jan 07 19:10:35 2015 +0530
# Node ID 9639a785d4380d08f19c069e24b0960a41bb2e77
# Parent  1e7de45ddd54a1af7feab49d807c3fde7d34e1f8
rc: control bitrate overshoots during midframe encodes in strict-cbr

diff -r 1e7de45ddd54 -r 9639a785d438 source/common/param.cpp
--- a/source/common/param.cpp   Sat Dec 20 14:05:40 2014 +0530
+++ b/source/common/param.cpp   Wed Jan 07 19:10:35 2015 +0530
@@ -699,7 +699,7 @@
 {
 p-rc.bStrictCbr = atobool(value);
 p-rc.pbFactor = 1.0;
-p-rc.rateTolerance = 0.5;
+p-rc.rateTolerance = 0.7;
 }
 OPT(analysis-mode) p-analysisMode = parseName(value, 
x265_analysis_names, bError);
 OPT(sar)
diff -r 1e7de45ddd54 -r 9639a785d438 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cppSat Dec 20 14:05:40 2014 +0530
+++ b/source/encoder/ratecontrol.cppWed Jan 07 19:10:35 2015 +0530
@@ -411,8 +411,8 @@
 }
 if (m_param-totalFrames = 2 * m_fps  m_param-rc.bStrictCbr)
 {
-m_amortizeFraction = 0;
-m_amortizeFrames = 0;
+m_amortizeFraction = 0.85;
+m_amortizeFrames = m_param-totalFrames / 2;
 }
 m_isCbr = m_param-rc.rateControlMode == X265_RC_ABR  m_isVbv  
!m_2pass  m_param-rc.vbvMaxBitrate = m_param-rc.bitrate;
 m_leadingBframes = m_param-bframes;
@@ -482,6 +482,7 @@
 }
 
 m_totalBits = 0;
+m_encodedBits = 0;
 m_framesDone = 0;
 m_residualCost = 0;
 m_partialResidualCost = 0;
@@ -1362,10 +1363,18 @@
 double overflow = 1.0;
 double timeDone = (double)(m_framesDone - m_param-frameNumThreads + 
1) * m_frameDuration;
 double wantedBits = timeDone * m_bitrate;
-if (wantedBits  0  m_totalBits  0  !m_partialResidualFrames)
+int64_t encodedBits = m_totalBits;
+if (m_param-totalFrames  m_param-totalFrames = 2 * m_fps)
+{
+abrBuffer = m_param-totalFrames * (m_bitrate / m_fps);
+encodedBits = m_encodedBits;
+}
+
+if (wantedBits  0  encodedBits  0  (!m_partialResidualFrames || 
+m_param-rc.bStrictCbr))
 {
 abrBuffer *= X265_MAX(1, sqrt(timeDone));
-overflow = x265_clip3(.5, 2.0, 1.0 + (m_totalBits - wantedBits) / 
abrBuffer);
+overflow = x265_clip3(.5, 2.0, 1.0 + (encodedBits - wantedBits) / 
abrBuffer);
 qScale *= overflow;
 }
 }
@@ -1572,7 +1581,8 @@
 if (m_sliceType == I_SLICE  m_param-keyframeMax  1
  m_lastNonBPictType != I_SLICE  !m_isAbrReset)
 {
-q = x265_qp2qScale(m_accumPQp / m_accumPNorm);
+if (!m_param-rc.bStrictCbr)
+q = x265_qp2qScale(m_accumPQp / m_accumPNorm);
 q /= fabs(m_param-rc.ipFactor);
 }
 else if (m_framesDone  0)
@@ -1990,28 +2000,55 @@
 if (encodedBitsSoFar  0.05f * rce-frameSizePlanned)
 qpMax = qpAbsoluteMax = prevRowQp;
 
-if (rce-sliceType != I_SLICE)
+if (rce-sliceType != I_SLICE || (m_param-rc.bStrictCbr  rce-poc  
0))
 rcTol *= 0.5;
 
 if (!m_isCbr)
 qpMin = X265_MAX(qpMin, rce-qpNoVbv);
 
+double totalBitsNeeded = m_wantedBitsWindow;
+if (m_param-totalFrames)
+totalBitsNeeded = (m_param-totalFrames * m_bitrate) / m_fps;
+double abrOvershoot = (accFrameBits + m_totalBits - 
m_wantedBitsWindow) / totalBitsNeeded;
+
 while (qpVbv  qpMax
-((accFrameBits  rce-frameSizePlanned + rcTol) ||
+(((accFrameBits  rce-frameSizePlanned + rcTol) ||
(rce-bufferFill - accFrameBits  bufferLeftPlanned * 0.5) 
||
-   (accFrameBits  rce-frameSizePlanned  qpVbv  
rce-qpNoVbv)))
+   (accFrameBits  rce-frameSizePlanned  qpVbv  
rce-qpNoVbv))
+(!m_param-rc.bStrictCbr ? 1 : abrOvershoot  0.1)))
 {
 qpVbv += stepSize;
 accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv, 
encodedBitsSoFar);
+abrOvershoot = (accFrameBits + m_totalBits - m_wantedBitsWindow) / 
totalBitsNeeded;
 }
 
 while (qpVbv  qpMin
 (qpVbv  curEncData.m_rowStat[0].diagQp || m_singleFrameVbv)
-((accFrameBits  rce-frameSizePlanned * 0.8f  qpVbv = 
prevRowQp)
-   || accFrameBits  (rce-bufferFill - m_bufferSize + 
m_bufferRate) * 1.1))
+(((accFrameBits  rce-frameSizePlanned * 0.8f  qpVbv = 
prevRowQp)
+   || accFrameBits  (rce-bufferFill - m_bufferSize + 
m_bufferRate) * 1.1)
+(!m_param-rc.bStrictCbr ? 1 : abrOvershoot  0)))
 {
 qpVbv -= stepSize;
 accFrameBits = predictRowsSizeSum(curFrame, rce, qpVbv, 
encodedBitsSoFar);
+abrOvershoot = (accFrameBits + m_totalBits - m_wantedBitsWindow

  1   2   3   4   >