<div dir="ltr"><div>Hi everyone!</div><div>I'm struggling to understand one piece of code:</div><div><br></div><div><div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-coMULTI">/* This is important psy-wise: if we have a non-scenecut keyframe,</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> * there will be significant visual artifacts if the frames just before</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> * go down in quality due to being referenced less, despite it being</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> * more RD-optimal. */</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-kw1">if</span><span class="gmail-m_611049403920029085gmail-br0">(</span> <span class="gmail-m_611049403920029085gmail-br0">(</span>h<span class="gmail-m_611049403920029085gmail-sy0">-></span>param.<span class="gmail-m_611049403920029085gmail-me1">analyse</span>.<span class="gmail-m_611049403920029085gmail-me1">b_psy</span> <span class="gmail-m_611049403920029085gmail-sy0">&&</span> h<span class="gmail-m_611049403920029085gmail-sy0">-></span>param.<span class="gmail-m_611049403920029085gmail-me1">rc</span>.<span class="gmail-m_611049403920029085gmail-me1">b_mb_tree</span><span class="gmail-m_611049403920029085gmail-br0">)</span> <span class="gmail-m_611049403920029085gmail-sy0">||</span> b_vbv_lookahead <span class="gmail-m_611049403920029085gmail-br0">)</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> num_frames <span class="gmail-m_611049403920029085gmail-sy0">=</span> framecnt<span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-kw1">else</span> <span class="gmail-m_611049403920029085gmail-kw1">if</span><span class="gmail-m_611049403920029085gmail-br0">(</span> h<span class="gmail-m_611049403920029085gmail-sy0">-></span>param.<span class="gmail-m_611049403920029085gmail-me1">b_open_gop</span> <span class="gmail-m_611049403920029085gmail-sy0">&&</span> num_frames <span class="gmail-m_611049403920029085gmail-sy0"><</span> framecnt <span class="gmail-m_611049403920029085gmail-br0">)</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> num_frames<span class="gmail-m_611049403920029085gmail-sy0">++;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-kw1">else</span> <span class="gmail-m_611049403920029085gmail-kw1">if</span><span class="gmail-m_611049403920029085gmail-br0">(</span> num_frames <span class="gmail-m_611049403920029085gmail-sy0">==</span> <span class="gmail-m_611049403920029085gmail-nu0">0</span> <span class="gmail-m_611049403920029085gmail-br0">)</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-br0">{</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> frames<span class="gmail-m_611049403920029085gmail-br0">[</span><span class="gmail-m_611049403920029085gmail-nu0">1</span><span class="gmail-m_611049403920029085gmail-br0">]</span><span class="gmail-m_611049403920029085gmail-sy0">-></span>i_type <span class="gmail-m_611049403920029085gmail-sy0">=</span> X264_TYPE_I<span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-kw1">return</span><span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-br0">}</span></span></div><div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-br0"><br></span></span></div></div>The line I don't get is this: frames[1]->i_type = X264_TYPE_I;<br>Why
is is X264_TYPE_I but not X264_TYPE_KEYFRAME (which would then become I
or IDR depending on GOP settings like open/closed and min keyint)?<br><div>And it seems that it used to be like that before commit d020c4274:</div><div><br></div><div><div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace">@@ <span class="gmail-m_611049403920029085gmail-sy0">-</span><span class="gmail-m_611049403920029085gmail-nu0">1080</span><span class="gmail-m_611049403920029085gmail-sy0">,</span><span class="gmail-m_611049403920029085gmail-nu0">7</span> <span class="gmail-m_611049403920029085gmail-sy0">+</span><span class="gmail-m_611049403920029085gmail-nu0">1080</span><span class="gmail-m_611049403920029085gmail-sy0">,</span><span class="gmail-m_611049403920029085gmail-nu0">6</span> @@ <span class="gmail-m_611049403920029085gmail-kw4">void</span> x264_slicetype_analyse<span class="gmail-m_611049403920029085gmail-br0">(</span> x264_t <span class="gmail-m_611049403920029085gmail-sy0">*</span>h<span class="gmail-m_611049403920029085gmail-sy0">,</span> <span class="gmail-m_611049403920029085gmail-kw4">int</span> keyframe <span class="gmail-m_611049403920029085gmail-br0">)</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> orig_num_frames <span class="gmail-m_611049403920029085gmail-sy0">=</span> num_frames <span class="gmail-m_611049403920029085gmail-sy0">=</span> h<span class="gmail-m_611049403920029085gmail-sy0">-></span>param.<span class="gmail-m_611049403920029085gmail-me1">b_intra_refresh</span> <span class="gmail-m_611049403920029085gmail-sy0">?</span> framecnt <span class="gmail-m_611049403920029085gmail-sy0">:</span> X264_MIN<span class="gmail-m_611049403920029085gmail-br0">(</span> framecnt<span class="gmail-m_611049403920029085gmail-sy0">,</span> keyint_limit <span class="gmail-m_611049403920029085gmail-br0">)</span><span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> </span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> x264_lowres_context_init<span class="gmail-m_611049403920029085gmail-br0">(</span> h<span class="gmail-m_611049403920029085gmail-sy0">,</span> <span class="gmail-m_611049403920029085gmail-sy0">&</span>a <span class="gmail-m_611049403920029085gmail-br0">)</span><span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-sy0">-</span> idr_frame_type <span class="gmail-m_611049403920029085gmail-sy0">=</span> frames<span class="gmail-m_611049403920029085gmail-br0">[</span><span class="gmail-m_611049403920029085gmail-nu0">1</span><span class="gmail-m_611049403920029085gmail-br0">]</span><span class="gmail-m_611049403920029085gmail-sy0">-></span>i_frame <span class="gmail-m_611049403920029085gmail-sy0">-</span> h<span class="gmail-m_611049403920029085gmail-sy0">-></span>lookahead<span class="gmail-m_611049403920029085gmail-sy0">-></span>i_last_keyframe <span class="gmail-m_611049403920029085gmail-sy0">>=</span> h<span class="gmail-m_611049403920029085gmail-sy0">-></span>param.<span class="gmail-m_611049403920029085gmail-me1">i_keyint_min</span> <span class="gmail-m_611049403920029085gmail-sy0">?</span> X264_TYPE_IDR <span class="gmail-m_611049403920029085gmail-sy0">:</span> X264_TYPE_I<span class="gmail-m_611049403920029085gmail-sy0">;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> </span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"> <span class="gmail-m_611049403920029085gmail-coMULTI">/* This is important psy-wise: if we have a non-scenecut keyframe,</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> * there will be significant visual artifacts if the frames just before</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI">@@ -1092,12 +1091,12 @@ void x264_slicetype_analyse( x264_t *h, int keyframe )</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> {</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> frames[1]->i_type = X264_TYPE_P;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0, 1, 1, orig_num_frames ) )</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI">- frames[1]->i_type = idr_frame_type;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI">+ frames[1]->i_type = X264_TYPE_I;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> return;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> }</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> else if( num_frames == 0 )</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> {</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI">- frames[1]->i_type = idr_frame_type;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de2"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI">+ frames[1]->i_type = X264_TYPE_I;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> return;</span></span></div>
<div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"> }</span></span></div><div class="gmail-m_611049403920029085gmail-de1"><span style="font-family:courier new,monospace"><span class="gmail-m_611049403920029085gmail-coMULTI"><br></span></span></div></div>This code is located in encoder/slicetype.c.<br><div>Could anyone describe the reason why it is I but not KEYFRAME? Thank you.</div><div><br></div><div>Regards,</div><div>Matvey.</div></div>