<html><head><style>p{margin-top:0px;margin-bottom:0px;}</style></head><body><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; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; 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; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; 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="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; word-wrap: normal; padding: 16px; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 3px; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace; font-size: 11.9px; padding: 0px; margin: 0px; background: transparent; border-radius: 3px; word-break: normal; white-space: pre; border: 0px; display: inline; line-height: inherit; word-wrap: normal;">#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="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; word-wrap: normal; padding: 16px; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 3px; word-break: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span style="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; color: rgb(106, 115, 125);">/*</span> For each list, check to see whether we have lowres motion-searched this reference frame before. <span style="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; color: rgb(3, 47, 98);">"</span>[slicetype_frame_cost] p0: <span style="box-sizing: border-box; color: rgb(0, 92, 197);">%d</span>, p1: <span style="box-sizing: border-box; color: rgb(0, 92, 197);">%d</span>, b: <span style="box-sizing: border-box; color: rgb(0, 92, 197);">%d</span>, b-p0-1: <span style="box-sizing: border-box; color: rgb(0, 92, 197);">%d</span>, p1-b-1: <span style="box-sizing: border-box; color: rgb(0, 92, 197);">%d</span><span style="box-sizing: border-box;">\n</span><span style="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; word-wrap: normal; padding: 16px; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 3px; word-break: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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="box-sizing: border-box; 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 1530000000000000000000000000000000000000000000000 to 153553553553553553553553553553553553355333533555.</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><div style="line-height: 16px; font-family: 나눔고딕, NanumGothic, 돋움, dotum, 굴림, Gulim, AppleGothic, sans-serif;"></div></div></div></body></html><table style='display:none'><tr><td><img src="https://ack.mail.navercorp.com/readReceipt/notify/?img=m%2FnmKxgqaxFopAtYaqumpAi0pAu9pAu9p4uZM4MwKrtXaAUrazEZKA0vpoigMX%2B0MogZ74lRpzM5W4C5bX0q%2BzkR74FTWx%2FsDAUrFV9vpBp0WuIr1630WrwCWSlTb4b%3D.gif" border="0"/></td></tr></table>