I guess you would be talking about transcoding? Anytime you change a file, you are looking at a loss of quality. You probably want to use HandBrake, https://handbrake.fr/ I came across this article that should get you started. http://www.lighterra.com/papers/videoencodingh264/ and https://www.techspot.com/article/1131-hevc-h256-enconding-playback/ which mentions StaxRip https://staxrip.readthedocs.io/introduction.html I have not tried it.
You may want to try XMedia Recode https://www.xmedia-recode.de/en/ which I like.