If BZIP is compressing your MKV files, those are not very well-made MKV files. I'd be curious to examine one, if it isn't private.
Ok, this is a question that gets asked a lot here, and it's complicated. The MKV and MP4 formats don't actually do anything with compression directly: They are container formats, and the compression is an independent process. What you want to do is known as 're-encoding' or 'transcoding.' It's not difficult when you know what you are doing, but the learning curve can be a bit steep.
The easiest way is a program called Handbrake. https://handbrake.fr/ - it will do what you want, but you're probably going to have to spend a long time fiddling with settings and learning how to use it.
Here is a blog post I wrote a few years ago that explains how generation loss works: https://cloudinary.com/blog/why_jpeg_is_like_a_photocopier
Recompressing more intelligently would indeed be nice. It still happens that social media transcode images to produce even a larger file (that has extra artifacts).
One thing I've made sure we do at Cloudinary, is to have a different flow when recompressing what is already a lossy JPEG and no image manipulation operations are done (like downscaling or adding a text overlay). In that case, we'll actually estimate the JPEG quality based on the quantization tables, and only do lossless recompression if it's a low quality JPEG – if it's a sufficiently high-quality one we'll still do lossy recompression, but doing that repeatedly will only cause one extra generation, not an unbounded number of them.
That's a heavily-commented header file, it seems to contain entire unpacker code, that you just need to include and call it from your program. You may need some tools to be able to look into the matter. Currently I recommend VSCodium, which is VSC without M$ bloat (aside from privacy concerns, on larger projects this amounts to seconds of speedup).