This repo contains a Safari extension that triggers picture-in-picture mode on any (the first) HTML5 video on the currently visisted web page.
P.S. Because of API limitations, the video must have been interacted with by the user at least once before the extension will work.