Unfortunately being opensource does not exclude it from patent restrictions. It's actually the algorithms itself which are patented. So if Valve or Linux distros were to include H.264/5, they will need to pay royalties.
As for AV1, it's actually royalty free, so yes, we should switch to it.