Is H.264 AVC “better” than H265 HEVC ?
Under what conditions can H.264 outperform H.265?

 

Under what conditions can H.264 outperform H.265?

Generally, newer video compression standards will offer performance advantages compared to existing ones. For example, H.265 HEVC is known to be 40% more efficient than H.264 with the cost of 10x more complexity.

A NETINT customer observed under some circumstances H.264 AVC can outperform H.265 HEVC. The following PSNR test which utilizes the open source libx265 and libx264 encoders to encode identical test video illustrates this point.

Figure 1 PSNR compare between x265 and x264

With Quantization Parameter (QP)=27, the bitrate of H.265 and H.264 are similar (9.66Mbps vs 9.96Mbps) but the PSNR of the H.265 encoded video is lower (40.19 vs 41.8). Why is this occurring?

When compared to the original image, the H.265 image is missing small details.

Figure 2 – Utilizing WinMerge to compare the first frame for H.264 (left), H.265Center), original(right)

The following comparison illustrates the differences in how x264 and x265 encode video.

Figure 3 – Original image – Note presence of black pixel highlighted in white square

Figure 4 – Compressed with x264, note the pixel is still present

Figure 5  – Compressed with x265, the pixel is missing.

With a fixed QP=27, x265 encoding removed individual pixels that did not affect subjective visual performance but created a significant reduction in PSNR performance compared to the original image.

H.265 utilizes 16×16, 32×32 or 64×64 blocks. H264 use 4×4 or 8×8 blocks. H.264 encoding has some advantages for maintaining small details which may not be visually  detectable  but can be measured in PSNR tests.

All video compression algorithms are designed to preserve meaningful details that the human eye is sensitive to (compression algorithms for machine learning are on the way!).  For unnatural images including  visual artifacts or noise introduced during capturing or processing, H.265 may not be able to preserve the visual details of these images better than H.264.

An extreme example of the relative performance of H.265 and H.264 on unnatural images is a pure white noise image.

Figure 6 – A white noise 512×512 video

Tested with these commands for x264 and x265 respectively and with force all i-frames:

ffmpeg -i .\images\noise-%03d.png -c:v libx264 -x264-params frame-threads=4:keyint=1:ref=1:no-open-gop=1:weightp=0:weightb=0:cutree=0:rc-lookahead=0:bframes=0:scenecut=0:b-adapt=0:repeat-headers=1:qp=27 -pix_fmt yuv420p noise264alli.264

ffmpeg -i .\images\noise-%03d.png -c:v libx265 -x265-params frame-threads=4:keyint=1:ref=1:no-open-gop=1:weightp=0:weightb=0:cutree=0:rc-lookahead=0:bframes=0:scenecut=0:b-adapt=0:repeat-headers=1:qp=27 -pix_fmt yuv420p noise265alli.265

Figure 7 – White noise video encoded with x264 and x265, the PSNR and file size comparison

With fixed QP=27, x264 PSNR is 35.87dB and x265 PSNR is 23.02dB.  x264 has 12 dB better PSNR performance compared to x265 for this random noise image!

Benefitting from a smaller transform matrix (4×4), H.264 can be better for preserving more details than the larger matrix (16×16, or larger) in H265.

For images with more high frequency details which includes scattering noise or compression artifacts (for example, mosquito noise), H.264 will show higher SNR than H.265 with the same QP.

From this experiment, we can also understand the limitations of the PSNR test as an objective quality test which does not consistently align with actual perceived visual quality. Newer visual quality evaluation methods like SSIM, MS-SSIM, VMAF more accurately align with the human visual system and represent a more accurate assessment of visual quality.

To address the customer’s original observations, they agreed that the input video was heavily compressed and not suitable for being used in such an evaluation.

Please refer to NETINT website on more subjective test comparison: Subjective HEVC Transcoding Quality