Optimizing ffmpeg settings for high-entropy / HIGH-DETAIL ANIMATIONS towards uploading to youtube
do i get you wrong about you want a lossless compression?
https://trac.ffmpeg.org/wiki/Encode/H.264

Choose a CRF value
The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so ...

or
https://trac.ffmpeg.org/wiki/Encode/FFV1
FFV1 is a video codec developed within FFmpeg. It is lossless, meaning that it compresses video without introducing quantization degradations.
or
you can google lossless compression