Why and how to use x265

Introduction

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.
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.

File size comparison

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.
Both encodes also have aq-mode 3 enabled.
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.
One Punch Man episode 1, frame 13487 at CRF 15 in x264 And here in x265 at CRF 17

1. Static videos: The test clip consists of the first 1000 frames of Non Non Byori Repeat episode 1.

Download the encodes


Logfiles of the encodes (expandable):
x264 log

x264 [info]: 1920x1080p 0:0 @ 24000/1001 fps (cfr)
x264 [info]: color matrix: undef
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x264 [info]: AVC Encoder x264 core 148 r2699+6+41 29a38aa Yuuki [10-bit@all X86_64][GCC 5.3.0]
x264 [info]: profile: High 10, level: 5.1, subsampling: 4:2:0, bit-depth: 10-bit
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
x264 [info]: started at Sun Aug 07 23:46:37 2016
x264 [info]: frame I:10 Avg QP:22.52 size:391771
x264 [info]: frame P:236 Avg QP:26.76 size: 70531
x264 [info]: frame B:754 Avg QP:28.05 size: 7533
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%
x264 [info]: mb I I16..4: 49.8% 28.1% 22.1%
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%
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%
x264 [info]: 8x8 transform intra:16.7% inter:41.3%
x264 [info]: direct mvs spatial:98.5% temporal:1.5%
x264 [info]: coded y,uvDC,uvAC intra: 89.9% 87.5% 81.4% inter: 11.0% 15.1% 7.0%
x264 [info]: i16 v,h,dc,p: 14% 10% 18% 57%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 12% 8% 8% 9% 11% 10% 9% 10%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 8% 30% 6% 7% 7% 7% 7% 9%
x264 [info]: i8c dc,h,v,p: 52% 18% 11% 18%
x264 [info]: Weighted P-Frames: Y:3.0% UV:3.0%
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%
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%
x264 [info]: ref B L1: 97.1% 2.9%
x264 [info]: kb/s:5033.59
x264 [info]: encoded 1000 frames, 0.5356 fps, 5033.74 kb/s, 25.03 MB
x264 [info]: ended at Mon Aug 08 00:17:44 2016
x264 [info]: encoding duration 0:31:07

x265 log

yuv [info]: 1920x1080 fps 24000/1001 i420p8 unknown frame count
x265 [info]: Using preset veryslow & tune none
x265 [info]: HEVC encoder version 2.0M+9-g457336f+14
x265 [info]: build info [Windows][GCC 5.3.0][64 bit] Yuuki 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x265 [info]: Main 10 profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 4 threads
x265 [info]: frame threads / pool features : 2 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 3 inter / 3 intra
x265 [info]: ME / range / subpel / merge : star / 57 / 4 / 4
x265 [info]: Keyframe min / max / scenecut : 23 / 250 / 40
x265 [info]: Lookahead / bframes / badapt : 40 / 8 / 2
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 1
x265 [info]: References / ref-limit cu / depth : 5 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree : 3 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress : CRF-17.0 / 0.60
x265 [info]: tools: rect amp limit-modes rd=6 psy-rd=2.00 rdoq=2 psy-rdoq=1.00
x265 [info]: tools: rskip signhide tmvp b-intra strong-intra-smoothing deblock
x265 [info]: tools: sao
x265 [info]: frame I: 9, Avg QP:14.24 kb/s: 32406.31
x265 [info]: frame P: 178, Avg QP:14.40 kb/s: 6617.61
x265 [info]: frame B: 813, Avg QP:23.03 kb/s: 326.86
x265 [info]: Weighted P-Frames: Y:12.4% UV:12.4%
x265 [info]: Weighted B-Frames: Y:14.9% UV:14.3%
x265 [info]: consecutive B-frames: 5.9% 1.1% 21.4% 2.7% 9.6% 36.9% 4.8% 10.2% 7.5%
encoded 1000 frames in 1010.58s (0.99 fps), 1735.33 kb/s, Avg QP:21.41

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.


2. High-motion videos: The test clip consists of 1000 frames of One Punch Man episode 1, beginning at frame 13000.

Download the encodes


Logfiles of the encodes (expandable):
x264 log

x264 [info]: 1920x1080p 0:0 @ 24000/1001 fps (cfr)
x264 [info]: color matrix: undef
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x264 [info]: AVC Encoder x264 core 148 r2699+6+41 29a38aa Yuuki [10-bit@all X86_64][GCC 5.3.0]
x264 [info]: profile: High 10, level: 5.1, subsampling: 4:2:0, bit-depth: 10-bit
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
x264 [info]: started at Mon Aug 08 01:49:11 2016
x264 [info]: frame I:8 Avg QP:25.24 size:284336
x264 [info]: frame P:285 Avg QP:28.03 size: 95640
x264 [info]: frame B:707 Avg QP:28.83 size: 40806
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%
x264 [info]: mb I I16..4: 0.5% 95.9% 3.6%
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%
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%
x264 [info]: 8x8 transform intra:91.7% inter:78.2%
x264 [info]: direct mvs spatial:99.6% temporal:0.4%
x264 [info]: coded y,uvDC,uvAC intra: 90.3% 91.1% 74.3% inter: 34.2% 38.3% 10.4%
x264 [info]: i16 v,h,dc,p: 12% 22% 10% 55%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 7% 16% 10% 12% 11% 11% 10% 12%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 9% 3% 11% 18% 14% 13% 10% 11%
x264 [info]: i8c dc,h,v,p: 47% 20% 19% 14%
x264 [info]: Weighted P-Frames: Y:9.1% UV:7.0%
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%
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%
x264 [info]: ref B L1: 95.8% 4.2%
x264 [info]: kb/s:11198.17
x264 [info]: encoded 1000 frames, 0.2929 fps, 11198.33 kb/s, 55.68 MB
x264 [info]: ended at Mon Aug 08 02:46:06 2016
x264 [info]: encoding duration 0:56:55

x265 log

yuv [info]: 1920x1080 fps 24000/1001 i420p8 unknown frame count
x265 [info]: Using preset veryslow & tune none
x265 [info]: HEVC encoder version 2.0M+9-g457336f+14
x265 [info]: build info [Windows][GCC 5.3.0][64 bit] Yuuki 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x265 [info]: Main 10 profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 4 threads
x265 [info]: frame threads / pool features : 2 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 3 inter / 3 intra
x265 [info]: ME / range / subpel / merge : star / 57 / 4 / 4
x265 [info]: Keyframe min / max / scenecut : 23 / 250 / 40
x265 [info]: Lookahead / bframes / badapt : 40 / 8 / 2
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 1
x265 [info]: References / ref-limit cu / depth : 5 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree : 3 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress : CRF-17.0 / 0.60
x265 [info]: tools: rect amp limit-modes rd=6 psy-rd=2.00 rdoq=2 psy-rdoq=1.00
x265 [info]: tools: rskip signhide tmvp b-intra strong-intra-smoothing deblock
x265 [info]: tools: sao
x265 [info]: frame I: 14, Avg QP:14.37 kb/s: 18963.14
x265 [info]: frame P: 253, Avg QP:15.76 kb/s: 12334.19
x265 [info]: frame B: 733, Avg QP:19.84 kb/s: 3709.09
x265 [info]: Weighted P-Frames: Y:9.5% UV:8.3%
x265 [info]: Weighted B-Frames: Y:8.3% UV:6.8%
x265 [info]: consecutive B-frames: 11.6% 9.4% 14.6% 43.1% 7.1% 10.5% 1.5% 1.1% 1.1%
encoded 1000 frames in 2391.07s (0.42 fps), 6104.80 kb/s, Avg QP:18.73


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.

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.

Useful parameters for encoding with x265

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.

--preset

Options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
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.
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.

--ref

Options: An integer from 1 to 16
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.
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.

--rd

Options: An integer from 1 to 6
What it does: The higher the value, the more exhaustive the RDO analysis is and the more rate distortion optimizations are used.
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.

--ctu

Options: 64,32,16
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.
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.

--min-cu-size

Options: 64,32,16,8
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.
What to use: Use 8, as it is an easy way to save bitrate without a significant increase in computing time.

--rect, --no-rect

What it does: Enables the analysis of rectangular motion partitions.
What to use: --rect for better encode results, --no-rect for faster encoding.

--amp, --no-amp

What it does: Enables the analysis of asymmetric motion partitions.
What to use: --amp for better encode results, --no-amp for faster encoding.

--rskip, --no-rskip

What it does: This option determines early exit from CU depth recursion.
What to use: Provides minimal quality degradation at good performance gains when enabled, so you can choose what you want.

--rdoq-level

Options: 0,1,2
What it does: Specifys the amount of rate-distortion analysis to use within quantization.
What to use: The standard is 2, which seems pretty good.

--max-merge

Options: An integer from 1 to 5
What it does: Maximum number of neighbor candidate blocks that the encoder may consider for merging motion predictions.
What to use: Something from 3 to 5, depending if you are aiming for a faster encode or better results.

--me

Options: dia, hex, umh, star, full
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.
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.

--subme

Options: An integer from 1 to 7
What it does: This is the motion search range.
What to use: Something from 4 to 7, depending on whether you are going for faster encoding or better results.

--merange

Options: An integer from 0 to 32768
What it does: Amount of subpel refinement to perform. The higher the number the more subpel iterations and steps are performed.
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.

--constrained-intra, --no-constrained-intra

What it does: Constrained intra prediction. The general idea is to block the propagation of reference errors that may have resulted from lossy signals.
What to use: --no-constrained-intra (which is default) unless you know what you're doing.

--psy-rd

Options: A float from 0 to 5.0
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.
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.

--psy-rdoq

Options: A float from 0 to 50.0
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.
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.

--rc-grain, --no-rc-grain

What it does: This parameter strictly minimizes QP fluctuations within and across frames and removes pulsing of grain.
What to use: Use this whenever you need to encode grainy scenes, otherwise leave it disabled.

Leave a comment



26. Oct 2018 um 15:47 by --sao

--limit-sao --no-sao




25. Oct 2018 um 17:09 by Attila

Hi




25. Oct 2018 um 17:08 by Attila

Hi