Hi,

First, some background.

I was reencoding my entire Blu-ray collection recently due to buying a 55" OLED TV and noticing how awful my old slow preset FullHD encodings looked on it from 7 feet away. The level of transparency a 4K OLED TV offers is a double-edged sword as any encoding deficiencies or artifacts become far more noticeable than on any other inferior display technology.

The antiquated x264 presets aren't particularly well balanced when it comes to making the most of highly detailed Blu-ray content (especially with the lack of aq-mode=3) whilst maintaining a high level of hardware decoder compatibility, so my first port of call was to create a custom x264-params string to use with ffmpeg. After much experimentation, I came up with this...

Code:
-x264-params aq-mode=3:aq-strength=1.3:b-adapt=2:bframes=5:me=umh:merange=32:no-dct-decimate=1:no-fast-pskip=1:opencl=true:partitions=all:psy-rd=1,0.15:rc-lookahead=50:subme=9
This provides superior results (to my eyes) when compared to any of the presets, and a crf value of 23 results in an average bitrate of around 3 to 5Mbps with most sources. Some pre-filtering may be required to achieve this with noisy sources. The only obvious (to me) difference between the source and the encoding most of the time is a lack of fine grain which I'm happy to sacrifice to achieve sensible file sizes.

For subpar sources that are still prone to banding and block noise, adding a little temporal Gaussian noise to the luma plane usually fixes it...

Code:
-vf noise=c0s=1:c0f=t
Particularly stubborn sources may need "1" raising to "2".


What about merange?

After ironing out the rest of the wrinkles, the effect of merange on encoding efficiency became my main area of interest. To test this, I chose ten 1080p movies at random and encoded the first 5 minutes of each (with -t 300) using me=umh with subme=9 and various values for merange. The results were as follows...

Code:
merange	bitrate	%delta	speed	%delta

16	6521	0	2.02x	0
20	6512	-0.10	1.98x	-2.0
24	6499	-0.34	1.90x	-6.3
28	6411	-1.72	1.87x	-7.4
32	6407	-1.78	1.82x	-11.0
36	6404	-1.83	1.79x	-12.8
40	6402	-1.86	1.74x	-16.1
44	6368	-2.40	1.69x	-19.5
48	6364	-2.47	1.63x	-23.9
52	6364	-2.47	1.61x	-25.5
56	6362	-2.50	1.58x	-27.8
60	6348	-2.73	1.51x	-33.8
64	6347	-2.74	1.47x	-37.4
All pre-filtering in my encoding script was disabled to make x264 performance the primary focus of speed measurements. The CPU is a 6-core AMD Ryzen 5 5600X.

Taking the default merange=16 as a reference, we can see that compression does improve with increasing range all the way up to (and possibly beyond) 64, but encoding speed suffers disproportionately at very high values.

It's a judgement call as to how much speed you're prepared to sacrifice for increased compression which translates to improved quality in 2-pass mode, but values beyond 32 will likely make less than a 1% difference. Therefore, my chosen sweetspot is merange=32 as it only incurs an 11% speed penalty over merange=16 for a worthwhile (to me) gain in compression of roughly 1.8%.

If anyone else has carried out similar tests at 1080p, I'd be interested to see if their results tally with mine.