Encode from your RGB source to lossless RGB ZMBV using ffmpeg. YouTube handles ZMBV perfectly and ZMBV is a very good lossless format. For this, download a static build of ffmpeg from
Zeranoe's ffmpeg builds page (32-bit or 64-bit; doesn't matter; the exe is in a "bin" subdirectory somewhere in the archive), then try the following ffmpeg command, which should result in a pretty small lossless RGB ZMBV with lossless FLAC audio, all of which YouTube will handle properly.
ffmpeg -i input.avs -c:a flac -compression_level 8 -c:v zmbv output.mkv
If you must use h264, you should give x264 RGB data because it now does the color conversion properly. You should be using bt470bg color matrix for everything to accurately reproduce colors when converting from RGB to YUV and back to RGB. YouTube will do the conversion to RGB properly with a tv-range YUV 4:2:0 video using bt470bg color matrix. The quality should be lossless so you don't get YouTube transcoding lossy to lossy.
For x264, the following is as good as you can make it without losing quality and without spending too much time ("placebo" is usually many times slower than "veryslow" without much file size reduction).
x264 --qp 0 --preset veryslow --keyint infinite --output-csp i420 --range tv --colormatrix bt470bg --output x264output.mkv input.avs
To help others, it would be useful to try both commands, compare file sizes, and post your findings here.
Edit: Note that the x264 command line doesn't handle audio at all. You'll need to mux audio after you use it if you want to make an accurate comparison. You can do this with ffmpeg. Simply add these lines after your x264 line in your batch script, making sure to modify the input and output filenames as appropriate, like this.
x264 --qp 0 --preset veryslow --keyint infinite --output-csp i420 --range tv --colormatrix bt470bg --output x264output.mkv input.avs
ffmpeg -i input.avs -c:a flac -compression_level 8 -vn audio.flac
ffmpeg -i x264output.mkv -c:v copy -i audio.flac -c:a copy finaloutput.mkv