<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 8, 2018 at 2:53 PM, <span dir="ltr"><<a href="mailto:aruna@multicorewareinc.com" target="_blank">aruna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Aruna Matheswaran <<a href="mailto:aruna@multicorewareinc.com">aruna@multicorewareinc.com</a>><br>
# Date 1521010828 -19800<br>
# Wed Mar 14 12:30:28 2018 +0530<br>
# Node ID 182914e1d201395d152e310db7f5cf<wbr>29ab3c787e<br>
# Parent 03dcb3457b7eafc6a13fd317286d70<wbr>921a5b7dfe<br>
Add support for chunked encoding<br>
<br>
diff -r 03dcb3457b7e -r 182914e1d201 doc/reST/cli.rst<br>
--- a/doc/reST/cli.rst Mon May 28 14:05:25 2018 +0530<br>
+++ b/doc/reST/cli.rst Wed Mar 14 12:30:28 2018 +0530<br>
@@ -535,6 +535,20 @@<br>
<br>
**CLI ONLY**<br>
<br>
+.. option:: --chunk-start <integer><br>
+<br>
+ First frame of the chunk. Frames preceeding this in display order will<br>
+ be encoded, however, they will be discarded in the bitstream. This<br>
+ feature can be enabled only in closed GOP structures.<br>
+ Default 0 (disabled).<br>
+ <br>
+.. option:: --chunk-end <integer><br>
+<br>
+ Last frame of the chunk. Frames following this in display order will be<br>
+ used in taking lookahead decisions, but, they will not be encoded.<br>
+ This feature can be enabled only in closed GOP structures.<br>
+ Default 0 (disabled).<br>
+<br>
Profile, Level, Tier<br>
====================<br>
<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/CMakeLists.txt<br>
--- a/source/CMakeLists.txt Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/CMakeLists.txt Wed Mar 14 12:30:28 2018 +0530<br>
@@ -29,7 +29,7 @@<br>
option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br>
mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
# X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 160)<br>
+set(X265_BUILD 161)<br>
configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
"${PROJECT_BINARY_DIR}/x265.<wbr>def")<br>
configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/common/param.cpp<br>
--- a/source/common/param.cpp Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/common/param.cpp Wed Mar 14 12:30:28 2018 +0530<br>
@@ -156,6 +156,9 @@<br>
param->lookaheadThreads = 0;<br>
param->scenecutBias = 5.0;<br>
param->radl = 0;<br>
+ param->chunkStart = 0;<br>
+ param->chunkEnd = 0;<br>
+<br>
/* Intra Coding Tools */<br>
param->bEnableConstrainedIntra = 0;<br>
param-><wbr>bEnableStrongIntraSmoothing = 1;<br>
@@ -1043,6 +1046,8 @@<br>
OPT("single-sei") p->bSingleSeiNal = atobool(value);<br>
OPT("atc-sei") p-><wbr>preferredTransferCharacteristi<wbr>cs = atoi(value);<br>
OPT("pic-struct") p->pictureStructure = atoi(value);<br>
+ OPT("chunk-start") p->chunkStart = atoi(value);<br>
+ OPT("chunk-end") p->chunkEnd = atoi(value);<br>
else<br>
return X265_PARAM_BAD_NAME;<br>
}<br>
@@ -1603,6 +1608,10 @@<br>
s += sprintf(s, " input-res=%dx%d", p->sourceWidth - padx, p->sourceHeight - pady);<br>
s += sprintf(s, " interlace=%d", p->interlaceMode);<br>
s += sprintf(s, " total-frames=%d", p->totalFrames);<br>
+ if (p->chunkStart)<br>
+ s += sprintf(s, " chunk-start=%d", p->chunkStart);<br>
+ if (p->chunkEnd)<br>
+ s += sprintf(s, " chunk-end=%d", p->chunkEnd);<br>
s += sprintf(s, " level-idc=%d", p->levelIdc);<br>
s += sprintf(s, " high-tier=%d", p->bHighTier);<br>
s += sprintf(s, " uhd-bd=%d", p->uhdBluray);<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/encoder/api.cpp<br>
--- a/source/encoder/api.cpp Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/encoder/api.cpp Wed Mar 14 12:30:28 2018 +0530<br>
@@ -281,7 +281,7 @@<br>
pic_in->analysis2Pass.<wbr>analysisFramedata = NULL;<br>
}<br>
<br>
- if (pp_nal && numEncoded > 0)<br>
+ if (pp_nal && numEncoded > 0 && encoder->m_outputCount >= encoder->m_latestParam-><wbr>chunkStart)<br>
{<br>
*pp_nal = &encoder->m_nalList.m_nal[0];<br>
if (pi_nal) *pi_nal = encoder->m_nalList.m_numNal;<br>
@@ -289,7 +289,7 @@<br>
else if (pi_nal)<br>
*pi_nal = 0;<br>
<br>
- if (numEncoded && encoder->m_param->csvLogLevel)<br>
+ if (numEncoded && encoder->m_param->csvLogLevel && encoder->m_outputCount >= encoder->m_latestParam-><wbr>chunkStart)<br>
x265_csvlog_frame(encoder->m_<wbr>param, pic_out);<br>
<br>
if (numEncoded < 0)<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/encoder/encoder.cpp Wed Mar 14 12:30:28 2018 +0530<br>
@@ -889,7 +889,7 @@<br>
m_exportedPic = NULL;<br>
m_dpb->recycleUnreferenced();<br>
}<br>
- if (pic_in)<br>
+ if (pic_in && (!m_param->chunkEnd || (m_encodedFrameNum < m_param->chunkEnd)))<br>
{<br>
if (m_latestParam->forceFlush == 1)<br>
{<br>
@@ -1319,7 +1319,8 @@<br>
if (m_aborted)<br>
return -1;<br>
<br>
- finishFrameStats(outFrame, curEncoder, frameData, m_pocLast);<br>
+ if ((m_outputCount + 1) >= m_param->chunkStart)<br>
+ finishFrameStats(outFrame, curEncoder, frameData, m_pocLast);<br>
<br>
/* Write RateControl Frame level stats in multipass encodes */<br>
if (m_param->rc.bStatWrite)<br>
@@ -1354,8 +1355,12 @@<br>
}<br>
else<br>
m_exportedPic = outFrame;<br>
-<br>
- m_numDelayedPic--;<br>
+ <br>
+ m_outputCount++;<br>
+ if (m_param->chunkEnd == m_outputCount)<br>
+ m_numDelayedPic = 0;<br>
+ else <br>
+ m_numDelayedPic--;<br>
<br>
ret = 1;<br>
}<br>
@@ -1364,7 +1369,7 @@<br>
* curEncoder is guaranteed to be idle at this point */<br>
if (!pass)<br>
frameEnc = m_lookahead-><wbr>getDecidedPicture();<br>
- if (frameEnc && !pass)<br>
+ if (frameEnc && !pass && (!m_param->chunkEnd || (m_encodedFrameNum < m_param->chunkEnd)))<br>
{<br>
if (m_param-><wbr>analysisMultiPassRefine || m_param-><wbr>analysisMultiPassDistortion)<br>
{<br>
@@ -1485,6 +1490,7 @@<br>
frameEnc->m_encData->m_slice-><wbr>m_iNumRPSInSPS = m_sps.spsrpsNum;<br>
<br>
curEncoder->m_rce.encodeOrder = frameEnc->m_encodeOrder = m_encodedFrameNum++;<br>
+<br>
if (!m_param->analysisLoad || !m_param->bDisableLookahead)<br>
{<br>
if (m_bframeDelay)<br>
@@ -2123,7 +2129,7 @@<br>
{<br>
const int picOrderCntLSB = slice->m_poc - slice->m_lastIDR;<br>
<br>
- frameStats->encoderOrder = m_outputCount++;<br>
+ frameStats->encoderOrder = m_outputCount;<br>
frameStats->sliceType = c;<br>
frameStats->poc = picOrderCntLSB;<br>
frameStats->qp = curEncData.m_avgQpAq;<br>
@@ -3124,6 +3130,19 @@<br>
p->radl = 0;<br>
x265_log(p, X265_LOG_WARNING, "Radl requires fixed gop-length (keyint == min-keyint). Disabling radl.\n");<br>
}<br>
+<br>
+ if ((p->chunkStart || p->chunkEnd) && p->bOpenGOP)<br>
+ {<br>
+ p->chunkStart = p->chunkEnd = 0;<br>
+ x265_log(p, X265_LOG_WARNING, "Chunking requires closed gop structure. Disabling chunking.\n");<br>
+ }<br>
+<br>
+ if (p->chunkEnd < p->chunkStart)<br>
+ {<br>
+ p->chunkStart = p->chunkEnd = 0;<br>
+ x265_log(p, X265_LOG_WARNING, "chunk-end cannot be less than chunk-start. Disabling chunking.\n");<br>
+ }<br>
+<br>
}<br>
<br>
void Encoder::allocAnalysis(x265_<wbr>analysis_data* analysis)<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/encoder/slicetype.cpp<br>
--- a/source/encoder/slicetype.cpp Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/encoder/slicetype.cpp Wed Mar 14 12:30:28 2018 +0530<br>
@@ -1108,8 +1108,9 @@<br>
x265_log(m_param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid and %d reference frames\n",<br>
frm.sliceType, m_param->maxNumReferences);<br>
}<br>
- if ((!m_param->bIntraRefresh || frm.frameNum == 0) && frm.frameNum - m_lastKeyframe >= m_param->keyframeMax &&<br>
- (!m_extendGopBoundary || frm.frameNum - m_lastKeyframe >= m_param->keyframeMax + m_param->gopLookahead))<br>
+ if (((!m_param->bIntraRefresh || frm.frameNum == 0) && frm.frameNum - m_lastKeyframe >= m_param->keyframeMax &&<br>
+ (!m_extendGopBoundary || frm.frameNum - m_lastKeyframe >= m_param->keyframeMax + m_param->gopLookahead)) ||<br>
+ (frm.frameNum == (m_param->chunkStart - 1)) || (frm.frameNum == m_param->chunkEnd))<br>
{<br>
if (frm.sliceType == X265_TYPE_AUTO || frm.sliceType == X265_TYPE_I)<br>
frm.sliceType = m_param->bOpenGOP && m_lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;<br>
@@ -1123,7 +1124,7 @@<br>
frm.sliceType = m_param->bOpenGOP && m_lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;<br>
}<br>
}<br>
- if (frm.sliceType == X265_TYPE_I && frm.frameNum - m_lastKeyframe >= m_param->keyframeMin)<br>
+ if ((frm.sliceType == X265_TYPE_I && frm.frameNum - m_lastKeyframe >= m_param->keyframeMin) || (frm.frameNum == (m_param->chunkStart - 1)) || (frm.frameNum == m_param->chunkEnd))<br>
{<br>
if (m_param->bOpenGOP)<br>
{<br>
@@ -1416,7 +1417,19 @@<br>
return;<br>
}<br>
frames[framecnt + 1] = NULL;<br>
- int keyFrameLimit = m_param->keyframeMax + m_lastKeyframe - frames[0]->frameNum - 1;<br>
+<br>
+ int keylimit = m_param->keyframeMax;<br>
+ if (frames[0]->frameNum < m_param->chunkEnd)<br>
+ {<br>
+ int chunkStart = (m_param->chunkStart - m_lastKeyframe - 1);<br>
+ int chunkEnd = (m_param->chunkEnd - m_lastKeyframe);<br>
+ if ((chunkStart > 0) && (chunkStart < m_param->keyframeMax))<br>
+ keylimit = chunkStart;<br>
+ else if ((chunkEnd > 0) && (chunkEnd < m_param->keyframeMax))<br>
+ keylimit = chunkEnd;<br>
+ }<br>
+<br>
+ int keyFrameLimit = keylimit + m_lastKeyframe - frames[0]->frameNum - 1;<br>
if (m_param->gopLookahead && keyFrameLimit <= m_param->bframes + 1)<br>
keyintLimit = keyFrameLimit + m_param->gopLookahead;<br>
else<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/test/regression-tests.<wbr>txt<br>
--- a/source/test/regression-<wbr>tests.txt Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/test/regression-<wbr>tests.txt Wed Mar 14 12:30:28 2018 +0530<br></blockquote><div><br></div><div>Please make a separate patch for regression test next time and send.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
@@ -173,4 +173,7 @@<br>
RaceHorses_416x240_30.y4m,--<wbr>preset slow --no-cutree --ctu 16 --analysis-save x265_analysis.dat --analysis-reuse-level 10 --scale-factor 2 --crf 22 --vbv-maxrate 1000 --vbv-bufsize 1000::RaceHorses_832x480_30.<wbr>y4m, --preset slow --no-cutree --ctu 32 --analysis-load x265_analysis.dat --analysis-save x265_analysis_2.dat --analysis-reuse-level 10 --scale-factor 2 --crf 16 --vbv-maxrate 4000 --vbv-bufsize 4000 --refine-intra 0 --refine-inter 1::RaceHorses_1664x960_30.y4m,<wbr>--preset slow --no-cutree --ctu 64 --analysis-load x265_analysis_2.dat --analysis-reuse-level 10 --scale-factor 2 --crf 12 --vbv-maxrate 7000 --vbv-bufsize 7000 --refine-intra 2 --refine-inter 2<br>
ElFunete_960x540_60.yuv,--<wbr>colorprim bt709 --transfer bt709 --chromaloc 2 --aud --repeat-headers --no-opt-qp-pps --no-opt-ref-list-length-pps --wpp --no-interlace --sar 1:1 --min-keyint 60 --no-open-gop --rc-lookahead 180 --bframes 5 --b-intra --ref 4 --cbqpoffs -2 --crqpoffs -2 --lookahead-threads 0 --weightb --qg-size 8 --me star --preset veryslow --frame-threads 1 --b-adapt 2 --aq-mode 3 --rd 6 --pools 15 --colormatrix bt709 --keyint 120 --high-tier --ctu 64 --tune psnr --bitrate 10000 --vbv-bufsize 30000 --vbv-maxrate 17500 --analysis-reuse-level 10 --analysis-save elfuente_960x540.dat --scale-factor 2::ElFunete_1920x1080_60.yuv,-<wbr>-colorprim bt709 --transfer bt709 --chromaloc 2 --aud --repeat-headers --no-opt-qp-pps --no-opt-ref-list-length-pps --wpp --no-interlace --sar 1:1 --min-keyint 60 --no-open-gop --rc-lookahead 180 --bframes 5 --b-intra --ref 4 --cbqpoffs -2 --crqpoffs -2 --lookahead-threads 0 --weightb --qg-size 8 --me star --preset veryslow --frame-threads 1 --b-adapt 2 --aq-mode 3 --rd 6 --pools 15 --colormatrix bt709 --keyint 120 --high-tier --ctu 64 --tune psnr --bitrate 10000 --vbv-bufsize 30000 --vbv-maxrate 17500 --analysis-reuse-level 10 --analysis-save elfuente_1920x1080.dat --limit-tu 0 --scale-factor 2 --analysis-load elfuente_960x540.dat --refine-intra 4 --refine-inter 2::ElFuente_3840x2160_60.yuv,-<wbr>-colorprim bt709 --transfer bt709 --chromaloc 2 --aud --repeat-headers --no-opt-qp-pps --no-opt-ref-list-length-pps --wpp --no-interlace --sar 1:1 --min-keyint 60 --no-open-gop --rc-lookahead 180 --bframes 5 --b-intra --ref 4 --cbqpoffs -2 --crqpoffs -2 --lookahead-threads 0 --weightb --qg-size 8 --me star --preset veryslow --frame-threads 1 --b-adapt 2 --aq-mode 3 --rd 6 --pools 15 --colormatrix bt709 --keyint 120 --high-tier --ctu 64 --tune=psnr --bitrate 24000 --vbv-bufsize 84000 --vbv-maxrate 49000 --analysis-reuse-level 10 --limit-tu 0 --scale-factor 2 --analysis-load elfuente_1920x1080.dat --refine-intra 4 --refine-inter 2<br>
<br>
+#segment encoding<br>
+BasketballDrive_1920x1080_50.<wbr>y4m, --preset ultrafast --no-open-gop --chunk-start 100 --chunk-end 200<br>
+<br>
# vim: tw=200<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/x265.cpp<br>
--- a/source/x265.cpp Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/x265.cpp Wed Mar 14 12:30:28 2018 +0530<br>
@@ -144,7 +144,7 @@<br>
{<br>
int eta = (int)(elapsed * (framesToBeEncoded - frameNum) / ((int64_t)frameNum * 1000000));<br>
sprintf(buf, "x265 [%.1f%%] %d/%d frames, %.2f fps, %.2f kb/s, eta %d:%02d:%02d",<br>
- 100. * frameNum / framesToBeEncoded, frameNum, framesToBeEncoded, fps, bitrate,<br>
+ 100. * frameNum / (param->chunkEnd ? param->chunkEnd : param->totalFrames), frameNum, (param->chunkEnd ? param->chunkEnd : param->totalFrames), fps, bitrate,<br>
eta / 3600, (eta / 60) % 60, eta % 60);<br>
}<br>
else<br>
@@ -403,7 +403,7 @@<br>
if (this->framesToBeEncoded == 0 && info.frameCount > (int)seek)<br>
this->framesToBeEncoded = info.frameCount - seek;<br>
param->totalFrames = this->framesToBeEncoded;<br>
-<br>
+ <br>
/* Force CFR until we have support for VFR */<br>
info.timebaseNum = param->fpsDenom;<br>
info.timebaseDenom = param->fpsNum;<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/x265.h<br>
--- a/source/x265.h Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/x265.h Wed Mar 14 12:30:28 2018 +0530<br>
@@ -1638,6 +1638,18 @@<br>
<br>
/* Enable writing all SEI messgaes in one single NAL instead of mul*/<br>
int bSingleSeiNal;<br>
+<br>
+<br>
+ /* First frame of the chunk. Frames preceeding this in display order will<br>
+ * be encoded, however, they will be discarded in the bitstream.<br>
+ * Default 0 (disabled). */<br>
+ int chunkStart;<br>
+<br>
+ /* Last frame of the chunk. Frames following this in display order will be<br>
+ * used in taking lookahead decisions, but, they will not be encoded.<br>
+ * Default 0 (disabled). */<br>
+ int chunkEnd;<br>
+<br>
} x265_param;<br>
<br>
/* x265_param_alloc:<br>
diff -r 03dcb3457b7e -r 182914e1d201 source/x265cli.h<br>
--- a/source/x265cli.h Mon May 28 14:05:25 2018 +0530<br>
+++ b/source/x265cli.h Wed Mar 14 12:30:28 2018 +0530<br>
@@ -152,6 +152,8 @@<br>
{ "vbv-init", required_argument, NULL, 0 },<br>
{ "vbv-end", required_argument, NULL, 0 },<br>
{ "vbv-end-fr-adj", required_argument, NULL, 0 },<br>
+ { "chunk-start", required_argument, NULL, 0 },<br>
+ { "chunk-end", required_argument, NULL, 0 },<br>
{ "bitrate", required_argument, NULL, 0 },<br>
{ "qp", required_argument, NULL, 'q' },<br>
{ "aq-mode", required_argument, NULL, 0 },<br>
@@ -468,6 +470,8 @@<br>
H0(" --vbv-init <float> Initial VBV buffer occupancy (fraction of bufsize or in kbits). Default %.2f\n", param->rc.vbvBufferInit);<br>
H0(" --vbv-end <float> Final VBV buffer emptiness (fraction of bufsize or in kbits). Default 0 (disabled)\n");<br>
H0(" --vbv-end-fr-adj <float> Frame from which qp has to be adjusted to achieve final decode buffer emptiness. Default 0\n");<br>
+ H0(" --chunk-start <integer> First frame of the chunk. Default 0 (disabled)\n");<br>
+ H0(" --chunk-end <integer> Last frame of the chunk. Default 0 (disabled)\n");<br>
H0(" --pass Multi pass rate control.\n"<br>
" - 1 : First pass, creates stats file\n"<br>
" - 2 : Last pass, does not overwrite stats file\n"<br>
<br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div><div class="gmail_extra">Pushed.</div></div>