10:37, 2 июля 2018 г., "홍석진" <ssokjin.hong@navercorp.com>:<br /><blockquote><div style="font-size:13px;font-family:NanumGothic,나눔고딕,sans-serif;"><div>Hi. </div><div></div><div>I have a problem when I try to encode some 4K videos with libx264.</div><div></div><div>I'm using x264 options as below</div><div><span style="color:rgb(0,0,0);font-family:NanumGothic,나눔고딕,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-transform:none;white-space:normal;display:inline !important;float:none;">-c:v libx264 -profile:v high -x264opts bframes=2:b_adapt=2:rc_lookahead=48:keyint=60:keyint-min=30 -threads 21 -pix_fmt yuv420p -vf scale=3840:2160 -f mp4.</span></div><div><span style="color:rgb(0,0,0);font-family:NanumGothic,나눔고딕,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-transform:none;white-space:normal;display:inline !important;float:none;"></span></div><div>Actually, I tried to encode by changing arguments as below</div><div> - change number of threads (21 -> 16 or 10) </div><div>- add force_key_frames - delete bframe options </div><div>- change b_adapt (2 -> 1, it means that X264_B_ADAPT_TRELLIS to X264_B_ADAPT_FAST as you know)</div><div></div><div>Changing b_adapt option 2 to 1 works well.</div><div>Otherwise sometimes it occurs same seg fault issues.</div><div></div><div>I attached back trace info</div><pre style="margin-top:0px;margin-bottom:16px;padding:16px;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-transform:none;"><code style="font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;font-size:11.9px;padding:0px;margin:0px;background:transparent;border-radius:3px;white-space:pre;border:0px;display:inline;line-height:inherit;">#0 0x0000000001f5a721 in x264_slicetype_frame_cost ()
#1 0x0000000001f5c89e in x264_slicetype_analyse ()
#2 0x0000000001ef9be6 in x264_stack_align ()
#3 0x0000000001ef201c in x264_lookahead_slicetype_decide ()
#4 0x0000000001ef21d9 in x264_lookahead_thread ()
#5 0x00007ffff72a6e25 in start_thread () from /usr/lib64/libpthread.so.0
#6 0x00007ffff660034d in clone () from /usr/lib64/libc.so.6</code></pre><div>I tried to analyze x264 codes and found something weird situation.</div><div></div><div></div><pre style="margin-top:0px;margin-bottom:0px;padding:16px;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-transform:none;"><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">static</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> </span><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">int</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> </span><span style="color:rgb(111,66,193);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">slicetype_frame_cost</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">( </span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">x264_t</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> *h, </span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">x264_mb_analysis_t</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> *a,
</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">x264_frame_t</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> **frames, </span><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">int</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> p0, </span><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">int</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> p1, </span><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">int</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> b )
</span><span style="color:rgb(106,115,125);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;"><span style="color:rgb(106,115,125);">/*</span> For each list, check to see whether we have lowres motion-searched this reference frame before. <span style="color:rgb(106,115,125);">*/</span></span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">
x264_log( h, X264_LOG_INFO, </span><span style="color:rgb(3,47,98);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;"><span style="color:rgb(3,47,98);">"</span>[slicetype_frame_cost] p0: <span style="color:rgb(0,92,197);">%d</span>, p1: <span style="color:rgb(0,92,197);">%d</span>, b: <span style="color:rgb(0,92,197);">%d</span>, b-p0-1: <span style="color:rgb(0,92,197);">%d</span>, p1-b-1: <span style="color:rgb(0,92,197);">%d</span><span>\n</span><span style="color:rgb(3,47,98);">"</span></span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">, p0, p1, b, b-p0-</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">, p1-b-</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">);
do_search[</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">] = b != p0 && fenc->lowres_mvs[</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][b-p0-</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">] == </span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0x7FFF</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">;
do_search[</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">] = b != p1 && fenc->lowres_mvs[</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][p1-b-</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">1</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">][</span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">] == </span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0x7FFF</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">;</span></pre><div>I think this problem is array index out of range exception in x264_slicetype_frame_cost function.</div><div>Seg fault occurs when function parameters b=48, p0=44 and p1=48.</div><div>It means [b-p0-1] is 3. But fenc->lowres_mvs[0][3] is not allocated.</div><div></div><div></div><p></p><pre style="margin-top:0px;margin-bottom:0px;padding:16px;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;font-variant-ligatures:normal;font-variant-caps:normal;text-align:start;text-transform:none;"><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">cur_nonb = i; </span><span style="color:rgb(106,115,125);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;"><span style="color:rgb(106,115,125);">//</span> before segmentation fault, i is 47. (i = number of frames in frame buffer - 1)</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">
</span><span style="color:rgb(215,58,73);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">while</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);">( IS_X264_TYPE_B( frames[cur_nonb]->i_type ) && cur_nonb > </span><span style="color:rgb(0,92,197);font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;">0</span><span style="font-size:11.9px;font-style:normal;font-weight:400;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;color:rgb(36,41,46);"> )
cur_nonb--;</span></pre><div>I understood p0 means the index of non-bframe (reverse position) in frames, macroblock_tree function.</div><div></div><div>Before seg fault, frame types of frames changed <span>1530000000000000000000000000000000000000000000000</span> to <span>153553553553553553553553553553553553355333533555</span>.</div><div>So that, cur_nonb is calculated 44. After that b-p0-1 be 3.</div><div>Except in this case, b-p0-1 and p1-b-1 are always calculated -1 to 2.</div><div></div><div>When I changed frames->i_type X264_TYPE_B to X264_TYPE_P forced if greater than 2 consecutive b frames are exist, it solved.</div><div>But I'm not sure whether can be used or not because this solution is not cool.</div><div>(Anyway, because of this issue I changed b-adapt option 2 to 1)</div><div></div><div></div><div>To sum up, seg fault occurs when encode some 4K contents.</div><div>By changing x264 options, it can be avoided (especially b-adapt option).</div><div></div><div>Please let me know if you need more information.</div><div></div><div>Regards.</div><div style="line-height:16px;font-family:나눔고딕,NanumGothic,돋움,dotum,굴림,Gulim,AppleGothic,sans-serif;"></div></div><table style="display:none;"><tbody><tr><td><img src="https://ack.mail.navercorp.com/readReceipt/notify/?img=msYmKxgqaxFoM6tYaqumFx3SKqivKqI4Fr3oMoMwaAMXp6M%2FM4Uqa6i0tzFXp6UmKSl5W63474lcWNFlbX30WLloWrdQaX2ZFotRpzkrp6wg%2B40vp6enM6%2F5WXiN.gif" border="0" /></td></tr></tbody></table><p>_______________________________________________<br />x264-devel mailing list<br /><a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br /><a href="https://mailman.videolan.org/listinfo/x264-devel">https://mailman.videolan.org/listinfo/x264-devel</a><br /></p></blockquote>Hi. So you said to libx264 that you would use 2 b-frames but after that forced 3 consecutive frames to be b-frames?