Are there any best practices for validating video files in PHP, similar to using getimagesize for images?

When working with video files in PHP, it is important to validate the file to ensure it is indeed a valid video file before processing it further. One way to do this is by checking the file's MIME type or using a library like FFmpeg to extract metadata from the video file.

function validateVideoFile($file_path) {
    $allowed_mime_types = ['video/mp4', 'video/mpeg', 'video/quicktime'];
    
    $mime_type = mime_content_type($file_path);
    
    if (in_array($mime_type, $allowed_mime_types)) {
        // Valid video file
        return true;
    } else {
        // Invalid video file
        return false;
    }
}

// Example usage
$file_path = 'path/to/video.mp4';

if (validateVideoFile($file_path)) {
    echo 'Valid video file';
} else {
    echo 'Invalid video file';
}