How to built OpenCV with a useful h264 codec?

Recently I needed to save the manipulation of OpenCV as a file.
It is too big for a lossless format, so I chose h264
with “quality” parameters.
Having built OpenCV (4.8.0) by myself (Code::Blocks/ mingw64/ Windows)
it obviously uses OpenH264 from Cisco Systems,
as if I don’t provide openh264-1.8.0-win64.dll running my prog it says:

Failed to load OpenH264 library: openh264-1.8.0-win64.dll
Please check environment and/or download library: Releases · cisco/openh264 · GitHub

[libopenh264 @ 000000000050eec0] Incorrect library version loaded [ERROR:0@0.018] global cap_ffmpeg_impl.hpp:3076 open Could not open codec libopenh264, error: Unspecified error (-22)
[ERROR:0@0.018] global cap_ffmpeg_impl.hpp:3093 open VIDEOIO/FFMPEG: Failed to initialize VideoWriter

Setting OPENCV_FFMPEG_WRITER_OPTIONS to “crf;18|tune;grain” has no effect.

The quality of the generated file is very (!) bad,
and I was told the reason for this would be the bad OpenH264 codec.
I shall “build OpenCV with ffmpeg directly” (or use the second so).

At this point I’m at a loss (as I’m no OpenCV dev but only a user).

Can somebody please explain how to achieve the basic operation:
Writing out a h264 movie with a good quality.

What do I have to do to “built OpenCV with ffmpeg”?
(ffmpeg lib has been downloaded at the CMake process anyway).

CMake’s output:

Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES

My Code

VideoWriter VW (“output.mp4”, CAP_FFMPEG, VideoWriter::fourcc(‘a’,‘v’,‘c’,‘1’), capt.get(CAP_PROP_FPS), refS);