The quick answer is to use a trial and test solution to find a compression value that gives you a value close to less than 300k.
The file sizes for JPEGs are highly dependent on the details of the image, so if you don't take pictures with the same detail (not all black images, etc.), then the best compression rating will be different.
Maybe use a binary search algorithm to find a good solution? Start at 50, then if it's too big, go down to 25, otherwise to 75. Then when you go in, say, 270-300 just stop?
Kurru source share