blog-content/videocodecs.html
2019-04-13 15:16:45 +02:00

354 lines
24 KiB
HTML

<a href="/blog">
{% load static %}
<div class="bottom_right_div"><img src="{% static '2hu.png' %}"></div>
</a>
<div id="overlay" aria-hidden="true" onclick="removefull()"></div>
<div class="wrapper_article">
<p class="heading">Why and how to use x265</p>
<div class="content">
<ul>
<li><a href="#c_introduction">Introduction</a></li>
<li><a href="#filesize">File size comparision</a></li>
<li><a href="#settings">Useful parameters for encoding with x265</a></li>
</ul>
</div>
<p class="subhead"><a href="#c_introduction" id="c_introduction">Introduction</a></p>
<div class="content">
For many years x264 has been the standard video codec for video encoding and achieved the best results one
could get in terms of video compression and efficiency. But in 2013, when the initial version of x265
was released, it yielded far better results than were previously possible with x264. Now 2.0 stable version of
x265 is released and we are a few CPU and GPU generations farther than we were in 2013.
Additionally, the new PCs, notebooks, and even smartphones that are coming out are all receiving native
hardware support for decoding x265, so as of today, more and more people
can view HEVC encoded videos just the same as they can view AVC encoded videos.
The problem is that the encoders in the fansubbing community are only slowly adapting to
the new codec, effectively wasting the bandwidth of the viewer, or offering a lower quality than they could achieve
with x265. <br>
In the following section, I will explain why HEVC/x265 is superior to x264/AVC and why you should use it to encode your
videos.
</div>
<p class="subhead"><a id="filesize" href="#filesize">File size comparison</a></p>
<div class="content">
This section will be dedicated to comparing the difference in filesize between x264 and x265.
For x265, I used CRF 17 and the veryslow preset, which already yields very good results.
For x264, I used CRF 15, the preset veryslow and the parameters subme 11, me tesa, merange 32, and bframes 16.<br>
Both encodes also have aq-mode 3 enabled.<br>
Please note: CRF in x264 and x265 is NOT comparable, both encoders use a different way to calculate the CRF.
I found CRF 15 for x264 and CRF 17 for x265 to have nearly the same quality, but results may vary.
You have been warned. <br>
<table class="two_column_table">
<tr>
<td><img class="img_expandable rounded" src="/media/articles/res_mr/onepunchmane1f13487x264crf15.png"></td>
<td><img class="img_expandable rounded" src="/media/articles/res_mr/onepunchmane1f13487x265crf17.png"></td>
</tr>
<tr>
<td>One Punch Man episode 1, frame 13487 at CRF 15 in x264</td>
<td>And here in x265 at CRF 17</td>
</tr>
</table>
<br>
<p>
1. Static videos: The test clip consists of the first 1000 frames of Non Non Byori Repeat episode 1.<br><br>
<a href="/media/articles/res_mr/NNBR_Encodes.zip">Download the encodes</a><br>
</p>
<br>
Logfiles of the encodes (expandable):<br>
<div class="spoilerbox_expand_element">x264 log
<p class="code">
x264 [info]: 1920x1080p 0:0 @ 24000/1001 fps (cfr)<br>
x264 [info]: color matrix: undef<br>
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX<br>
x264 [info]: AVC Encoder x264 core 148 r2699+6+41 29a38aa Yuuki [10-bit@all X86_64][GCC 5.3.0]<br>
x264 [info]: profile: High 10, level: 5.1, subsampling: 4:2:0, bit-depth: 10-bit<br>
x264 [info]: cabac=1 ref=16 deblock=1:0:-1 analyse=0x3:0x133 me=tesa subme=11 psy=1 fade_compensate=0.00 psy_rd=1.00:0.00 mixed_ref=1 me_range=32 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=0 interlaced=0 bluray_compat=0 constrained_intra=0 fgo=0 bframes=16 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=15.0000 qcomp=0.60 qpmin=0:0:0 qpmax=81:81:81 qpstep=4 ip_ratio=1.40 aq=3:0.80<br>
x264 [info]: started at Sun Aug 07 23:46:37 2016<br>
x264 [info]: frame I:10 Avg QP:22.52 size:391771<br>
x264 [info]: frame P:236 Avg QP:26.76 size: 70531<br>
x264 [info]: frame B:754 Avg QP:28.05 size: 7533<br>
x264 [info]: consecutive B-frames: 1.1% 2.0% 45.0% 3.2% 6.0% 12.0% 4.2% 11.2% 8.1% 2.0% 1.1% 2.4% 0.0% 0.0% 0.0% 0.0% 1.7%<br>
x264 [info]: mb I I16..4: 49.8% 28.1% 22.1%<br>
x264 [info]: mb P I16..4: 4.6% 0.7% 0.7% P16..4: 44.1% 28.7% 10.7% 1.6% 0.2% skip: 8.7%<br>
x264 [info]: mb B I16..4: 0.4% 0.0% 0.1% B16..8: 28.4% 4.8% 0.3% direct: 1.5% skip:64.5% L0:42.1% L1:55.0% BI: 2.8%<br>
x264 [info]: 8x8 transform intra:16.7% inter:41.3%<br>
x264 [info]: direct mvs spatial:98.5% temporal:1.5%<br>
x264 [info]: coded y,uvDC,uvAC intra: 89.9% 87.5% 81.4% inter: 11.0% 15.1% 7.0%<br>
x264 [info]: i16 v,h,dc,p: 14% 10% 18% 57%<br>
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 12% 8% 8% 9% 11% 10% 9% 10%<br>
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 8% 30% 6% 7% 7% 7% 7% 9%<br>
x264 [info]: i8c dc,h,v,p: 52% 18% 11% 18%<br>
x264 [info]: Weighted P-Frames: Y:3.0% UV:3.0%<br>
x264 [info]: ref P L0: 58.3% 19.9% 5.7% 4.1% 1.6% 3.0% 1.3% 1.2% 0.6% 1.0% 0.6% 0.9% 0.5% 0.8% 0.5% 0.0%<br>
x264 [info]: ref B L0: 71.8% 11.7% 5.5% 2.5% 1.8% 1.7% 1.3% 0.7% 0.6% 0.5% 0.5% 0.5% 0.4% 0.3% 0.1%<br>
x264 [info]: ref B L1: 97.1% 2.9%<br>
x264 [info]: kb/s:5033.59<br>
x264 [info]: encoded 1000 frames, 0.5356 fps, 5033.74 kb/s, 25.03 MB<br>
x264 [info]: ended at Mon Aug 08 00:17:44 2016<br>
x264 [info]: encoding duration 0:31:07<br>
</p>
</div>
<div class="spoilerbox_expand_element">x265 log
<p class="code">
yuv [info]: 1920x1080 fps 24000/1001 i420p8 unknown frame count<br>
x265 [info]: Using preset veryslow & tune none<br>
x265 [info]: HEVC encoder version 2.0M+9-g457336f+14<br>
x265 [info]: build info [Windows][GCC 5.3.0][64 bit] Yuuki 10bit<br>
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX<br>
x265 [info]: Main 10 profile, Level-4 (Main tier)<br>
x265 [info]: Thread pool created using 4 threads<br>
x265 [info]: frame threads / pool features : 2 / wpp(17 rows)<br>
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8<br>
x265 [info]: Residual QT: max TU size, max depth : 32 / 3 inter / 3 intra<br>
x265 [info]: ME / range / subpel / merge : star / 57 / 4 / 4<br>
x265 [info]: Keyframe min / max / scenecut : 23 / 250 / 40<br>
x265 [info]: Lookahead / bframes / badapt : 40 / 8 / 2<br>
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 1<br>
x265 [info]: References / ref-limit cu / depth : 5 / off / on<br>
x265 [info]: AQ: mode / str / qg-size / cu-tree : 3 / 1.0 / 32 / 1<br>
x265 [info]: Rate Control / qCompress : CRF-17.0 / 0.60<br>
x265 [info]: tools: rect amp limit-modes rd=6 psy-rd=2.00 rdoq=2 psy-rdoq=1.00<br>
x265 [info]: tools: rskip signhide tmvp b-intra strong-intra-smoothing deblock<br>
x265 [info]: tools: sao<br>
x265 [info]: frame I: 9, Avg QP:14.24 kb/s: 32406.31<br>
x265 [info]: frame P: 178, Avg QP:14.40 kb/s: 6617.61<br>
x265 [info]: frame B: 813, Avg QP:23.03 kb/s: 326.86<br>
x265 [info]: Weighted P-Frames: Y:12.4% UV:12.4%<br>
x265 [info]: Weighted B-Frames: Y:14.9% UV:14.3%<br>
x265 [info]: consecutive B-frames: 5.9% 1.1% 21.4% 2.7% 9.6% 36.9% 4.8% 10.2% 7.5%<br>
encoded 1000 frames in 1010.58s (0.99 fps), 1735.33 kb/s, Avg QP:21.41<br>
</p>
</div>
<p>
The x264 encode has an average bitrate of 5033.74 kb/s resulting in a total filesize of 25.03 MB, while
the x265 encode has an average bitrate of 1735.33 kb/s resulting in a total filesize of 8.64 MB. This is an 66%
reduction, meaning the x265 file has only 1/3th the size of the x264 file whilst having the same visual quality.
</p>
<br>
<p>
2. High-motion videos: The test clip consists of 1000 frames of One Punch Man episode 1, beginning at frame 13000.<br><br>
<a href="/media/articles/res_mr/OPM_Encodes.zip">Download the encodes</a><br><br>
</p>
<br>
Logfiles of the encodes (expandable):<br>
<div class="spoilerbox_expand_element">x264 log
<p class="code">
x264 [info]: 1920x1080p 0:0 @ 24000/1001 fps (cfr)<br>
x264 [info]: color matrix: undef<br>
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX<br>
x264 [info]: AVC Encoder x264 core 148 r2699+6+41 29a38aa Yuuki [10-bit@all X86_64][GCC 5.3.0]<br>
x264 [info]: profile: High 10, level: 5.1, subsampling: 4:2:0, bit-depth: 10-bit<br>
x264 [info]: cabac=1 ref=16 deblock=1:0:-1 analyse=0x3:0x133 me=tesa subme=11 psy=1 fade_compensate=0.00 psy_rd=1.00:0.00 mixed_ref=1 me_range=32 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=0 interlaced=0 bluray_compat=0 constrained_intra=0 fgo=0 bframes=16 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=15.0000 qcomp=0.60 qpmin=0:0:0 qpmax=81:81:81 qpstep=4 ip_ratio=1.40 aq=3:0.80<br>
x264 [info]: started at Mon Aug 08 01:49:11 2016<br>
x264 [info]: frame I:8 Avg QP:25.24 size:284336<br>
x264 [info]: frame P:285 Avg QP:28.03 size: 95640<br>
x264 [info]: frame B:707 Avg QP:28.83 size: 40806<br>
x264 [info]: consecutive B-frames: 2.9% 5.4% 26.7% 44.8% 9.0% 9.0% 1.4% 0.8% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%<br>
x264 [info]: mb I I16..4: 0.5% 95.9% 3.6%<br>
x264 [info]: mb P I16..4: 0.5% 13.6% 1.3% P16..4: 35.8% 34.5% 12.1% 1.2% 0.1% skip: 1.0%<br>
x264 [info]: mb B I16..4: 0.1% 3.9% 0.1% B16..8: 37.8% 17.5% 2.6% direct: 8.1% skip:29.9% L0:53.2% L1:42.1% BI: 4.8%<br>
x264 [info]: 8x8 transform intra:91.7% inter:78.2%<br>
x264 [info]: direct mvs spatial:99.6% temporal:0.4%<br>
x264 [info]: coded y,uvDC,uvAC intra: 90.3% 91.1% 74.3% inter: 34.2% 38.3% 10.4%<br>
x264 [info]: i16 v,h,dc,p: 12% 22% 10% 55%<br>
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 7% 16% 10% 12% 11% 11% 10% 12%<br>
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 9% 3% 11% 18% 14% 13% 10% 11%<br>
x264 [info]: i8c dc,h,v,p: 47% 20% 19% 14%<br>
x264 [info]: Weighted P-Frames: Y:9.1% UV:7.0%<br>
x264 [info]: ref P L0: 41.9% 17.7% 9.6% 5.6% 5.2% 4.0% 2.8% 2.1% 1.5% 1.8% 2.1% 2.0% 1.4% 1.1% 0.9% 0.1%<br>
x264 [info]: ref B L0: 58.4% 11.5% 6.4% 4.0% 2.8% 4.0% 2.6% 1.5% 1.4% 1.4% 1.1% 2.0% 1.6% 1.0% 0.3%<br>
x264 [info]: ref B L1: 95.8% 4.2%<br>
x264 [info]: kb/s:11198.17<br>
x264 [info]: encoded 1000 frames, 0.2929 fps, 11198.33 kb/s, 55.68 MB<br>
x264 [info]: ended at Mon Aug 08 02:46:06 2016<br>
x264 [info]: encoding duration 0:56:55<br>
</p>
</div>
<div class="spoilerbox_expand_element">x265 log
<p class="code">
yuv [info]: 1920x1080 fps 24000/1001 i420p8 unknown frame count<br>
x265 [info]: Using preset veryslow & tune none<br>
x265 [info]: HEVC encoder version 2.0M+9-g457336f+14<br>
x265 [info]: build info [Windows][GCC 5.3.0][64 bit] Yuuki 10bit<br>
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX<br>
x265 [info]: Main 10 profile, Level-4 (Main tier)<br>
x265 [info]: Thread pool created using 4 threads<br>
x265 [info]: frame threads / pool features : 2 / wpp(17 rows)<br>
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8<br>
x265 [info]: Residual QT: max TU size, max depth : 32 / 3 inter / 3 intra<br>
x265 [info]: ME / range / subpel / merge : star / 57 / 4 / 4<br>
x265 [info]: Keyframe min / max / scenecut : 23 / 250 / 40<br>
x265 [info]: Lookahead / bframes / badapt : 40 / 8 / 2<br>
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 1<br>
x265 [info]: References / ref-limit cu / depth : 5 / off / on<br>
x265 [info]: AQ: mode / str / qg-size / cu-tree : 3 / 1.0 / 32 / 1<br>
x265 [info]: Rate Control / qCompress : CRF-17.0 / 0.60<br>
x265 [info]: tools: rect amp limit-modes rd=6 psy-rd=2.00 rdoq=2 psy-rdoq=1.00<br>
x265 [info]: tools: rskip signhide tmvp b-intra strong-intra-smoothing deblock<br>
x265 [info]: tools: sao<br>
x265 [info]: frame I: 14, Avg QP:14.37 kb/s: 18963.14<br>
x265 [info]: frame P: 253, Avg QP:15.76 kb/s: 12334.19<br>
x265 [info]: frame B: 733, Avg QP:19.84 kb/s: 3709.09<br>
x265 [info]: Weighted P-Frames: Y:9.5% UV:8.3%<br>
x265 [info]: Weighted B-Frames: Y:8.3% UV:6.8%<br>
x265 [info]: consecutive B-frames: 11.6% 9.4% 14.6% 43.1% 7.1% 10.5% 1.5% 1.1% 1.1%<br>
encoded 1000 frames in 2391.07s (0.42 fps), 6104.80 kb/s, Avg QP:18.73<br>
</p>
</div>
<br>
<p>
The x264 encode has an average bitrate of 11198.33 kb/s resulting in a total filesize of 55.68 MB, while
the x265 encode has an average bitrate of 6104.80 kb/s resulting in a total filesize of 30.3 MB. This is an 43%
reduction, meaning the x265 file has only 4/7th the size of the x264 file.<br><br>
Conclusion: x265 offers the same visual quality at significantly lower bitrates, meaning one can offer an encode with higher
visual quality than x264 at the same filesize, or reduce the filesize of the encoded videos by a large amount while
offering the same visual fidelity as a x264 encode. With no real downsides apart from a higher encoding time
and slightly less compatibility there really is no reason not to use it.
</p>
</div>
<p class="subhead"><a id="settings" href="#settings">Useful parameters for encoding with x265</a></p>
<div class="content">
<p>
Just as with x264, x265 has many parameters you can use if you don't want to stick to the presets and
are trying to get the best possible quality. In the following section, I will explain some of these
parameters and how to use them. You can click on each parameter to get more information about it.<br><br>
</p>
<div class="spoilerbox_expand_element">--preset
<p class="code">
Options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo<br>
What it does: The further to the right the preset on this list is, the higher the compression efficiency will be at the cost of slowing down your encode.<br>
What to use: Medium or slower are fine, but I would recommend slow or veryslow depending on how strong your encoding rig is.
Don't use placebo, it will result in greatly increased encoding time with diminishing returns in comparison to veryslow.
</p>
</div>
<div class="spoilerbox_expand_element">--ref
<p class="code">
Options: An integer from 1 to 16<br>
What it does: Max number of L0 references to be allowed. This number has a linear multiplier effect on the amount of work performed in motion search.<br>
What to use: If --b-pyramid is enabled(which is the default option), the HEVC specification only allows
ref 6 as a maximum, without --b-pyramid the maximum ref allowed by the specification is 7. Generally, you
want to use the highest number possible(within the specification), as it yields the best results.
</p>
</div>
<div class="spoilerbox_expand_element">--rd
<p class="code">
Options: An integer from 1 to 6<br>
What it does: The higher the value, the more exhaustive the RDO analysis is and the more rate distortion optimizations are used.<br>
What to use: The highest option you can afford, in general the rule: "the lower the value the faster the encode,
the higher the value the smaller the bitstream" applies. Please notice that, in the current version, rd 3 and 4 and rd 5 and 6 are the same.
</p>
</div>
<div class="spoilerbox_expand_element">--ctu
<p class="code">
Options: 64,32,16<br>
What it does: CTUs and CUs are the logical units in which the HEVC encoder divides a given picture. This
option sets the maximum CU size.<br>
What to use: No reason not to use 64, as it will give you large reductions in bitrate compared to the other two options
with an insignificant increase in computing time.
</p>
</div>
<div class="spoilerbox_expand_element">--min-cu-size
<p class="code">
Options: 64,32,16,8<br>
What it does: CTUs and CUs are the logical units in which the HEVC encoder divides a given picture. This
option sets the minimum CU size.<br>
What to use: Use 8, as it is an easy way to save bitrate without a significant increase in computing time.
</p>
</div>
<div class="spoilerbox_expand_element">--rect, --no-rect
<p class="code">
What it does: Enables the analysis of rectangular motion partitions.<br>
What to use: --rect for better encode results, --no-rect for faster encoding.
</p>
</div>
<div class="spoilerbox_expand_element">--amp, --no-amp
<p class="code">
What it does: Enables the analysis of asymmetric motion partitions.<br>
What to use: --amp for better encode results, --no-amp for faster encoding.
</p>
</div>
<div class="spoilerbox_expand_element">--rskip, --no-rskip
<p class="code">
What it does: This option determines early exit from CU depth recursion.<br>
What to use: Provides minimal quality degradation at good performance gains when enabled, so you can
choose what you want.
</p>
</div>
<div class="spoilerbox_expand_element">--rdoq-level
<p class="code">
Options: 0,1,2<br>
What it does: Specifys the amount of rate-distortion analysis to use within quantization.<br>
What to use: The standard is 2, which seems pretty good.
</p>
</div>
<div class="spoilerbox_expand_element">--max-merge
<p class="code">
Options: An integer from 1 to 5<br>
What it does: Maximum number of neighbor candidate blocks that the encoder may consider for merging motion predictions.<br>
What to use: Something from 3 to 5, depending if you are aiming for a faster encode or better results.
</p>
</div>
<div class="spoilerbox_expand_element">--me
<p class="code">
Options: dia, hex, umh, star, full<br>
What it does: Motion search method. Diamond search is the simplest. Hexagon search is a little better.
Uneven Multi-Hexagon is an adaption of the search method used by x264 for slower presets.
Star is a three step search adapted from the HM encoder and full is an exhaustive search.<br>
What to use: Umh for faster encoding, star for better encode results. Dia and hex are not worth the
quality loss and full gives diminishing returns.
</p>
</div>
<div class="spoilerbox_expand_element">--subme
<p class="code">
Options: An integer from 1 to 7<br>
What it does: This is the motion search range.<br>
What to use: Something from 4 to 7, depending on whether you are going for faster encoding or better results.
</p>
</div>
<div class="spoilerbox_expand_element">--merange
<p class="code">
Options: An integer from 0 to 32768<br>
What it does: Amount of subpel refinement to perform. The higher the number the more subpel iterations and steps are performed.<br>
What to use: The standard of 57 seems quite good, you can experiment with higher values if you want, but please
keep in mind that higher values will give you diminishing returns.
</p>
</div>
<div class="spoilerbox_expand_element">--constrained-intra, --no-constrained-intra
<p class="code">
What it does: Constrained intra prediction. The general idea is to block the propagation of reference
errors that may have resulted from lossy signals.<br>
What to use: --no-constrained-intra (which is default) unless you know what you're doing.
</p>
</div>
<div class="spoilerbox_expand_element">--psy-rd
<p class="code">
Options: A float from 0 to 5.0<br>
What it does: Turning on small amounts of psy-rd and psy-rdoq will improve the perceived visual quality,
trading distortion for bitrate. If it is too high, it will introduce visual artifacts.<br>
What to use: A value between 0.5 and 1.0 is a good starting point, you can experiment with higher values if you want, but
don't overdo it unless you like visual artifacts.
</p>
</div>
<div class="spoilerbox_expand_element">--psy-rdoq
<p class="code">
Options: A float from 0 to 50.0<br>
What it does: Turning on small amounts of psy-rd and psy-rdoq will improve the perceived visual quality,
trading distortion for bitrate. High levels of psy-rdoq can double the bitrate, so be careful.<br>
What to use: You should be good to go with a value between 0 and 5.0, but I wouldn't take a value much higher
than 1.0 because I haven't done enough tests yet.
</p>
</div>
<div class="spoilerbox_expand_element">--rc-grain, --no-rc-grain
<p class="code">
What it does: This parameter strictly minimizes QP fluctuations within and across frames and removes pulsing of grain.<br>
What to use: Use this whenever you need to encode grainy scenes, otherwise leave it disabled.
</p>
</div>
</div>
</div>