Just a simple code  
   $video_url = 'https://www.youtube.com/watch?v=2nO8KRtAqjA&t=3s';
    $video_id = '';
    // Extract the YouTube video ID
    if (preg_match('/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/]+\/.+\/|       (?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i', $video_url, $matches)) {
        $video_id = $matches[1];
    }
    $card_image = $video_id ? "https://img.youtube.com/vi/{$video_id}/hqdefault.jpg"
   
  echo $card_image;