Are there specific PHP libraries or tools that can assist in automatically detecting and loading the appropriate video format based on browser compatibility?

When serving videos on a website, it's important to ensure that the appropriate video format is loaded based on the browser's compatibility. One way to achieve this is by using PHP to detect the user's browser and serve the corresponding video format. This can be done by checking the user agent string and then selecting the appropriate video format to load.

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'Chrome') !== false) {
    // Load MP4 video for Chrome
    echo '<video controls><source src="video.mp4" type="video/mp4"></video>';
} elseif (strpos($user_agent, 'Firefox') !== false) {
    // Load WebM video for Firefox
    echo '<video controls><source src="video.webm" type="video/webm"></video>';
} else {
    // Load fallback video format for other browsers
    echo '<video controls><source src="video.mp4" type="video/mp4"></video>';
}