I think having a compression app that takes best advantage of the codecs and settings you’d need to use.
Any bitrate calculator will help you figure out what the data rate needs to be to target a specific size.
There’s still a lot of user intervention to get that best quality at a given size. This might include profile (baseline vs main vs high) entropy (CAVLC vs CABAC), CBR vs VBR, single vs multi-pass and when doing VBR whether there’s a need to constrain the peaks. There’s also B-frame and reference frames and on and on.
Basically at a given bitrate (and size) you can get a could or a crappy encode. Any “automatic” targeting may compromise the results.
Keep in mind that “exact” size targeting is difficult because the specific content can impact the decisions and encoder implementation makes in getting their. Often targets can over/under shoot. A good example is Apple Compressor which will give you an estimated file size for a one hour encode using given parameters. I find it always underestimates the size by as much as 10% to 20%
Basically use a bit rate calculator to determine the data rate needed. Make the decision on the settings on how to get the best encode at that data rate and targeted use. Understand that the result may be off a bit depending on those other settings and the source content itself.