Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube thumbnail link doesn't work in all cases

Tags:

youtube

An application I'm working on needs to get HQ YouTube thumbnails given a URL. Using this answer, I tried using the maxresdefault.jpg to get the maximum resolution of the thumbnail but on some videos (seemingly random), the request 404's.

Here are some examples:

  • http://img.youtube.com/vi/zIez5QVE3NI/maxresdefault.jpg works
  • http://img.youtube.com/vi/DaAfe5xTm8w/maxresdefault.jpg doesn't work

Using the same URL's, other requests using the same video keys do work:

  • http://img.youtube.com/vi/zIez5QVE3NI/default.jpg works
  • http://img.youtube.com/vi/DaAfe5xTm8w/default.jpg works

Why doesn't maxresdefault.jpg reliably return the image? Both of those videos are public and can be embedded.

I'd use 0.jpg but it has black bars on the top and bottom of the image.

like image 311
anjunatl Avatar asked Jul 04 '12 19:07

anjunatl


People also ask

Why thumbnail is not showing in YouTube link?

If you disable thumbnails when sharing the video, they will not show once you post the video link. To fix the problem, ensure you have deselected the “no thumbnails” option before sharing your video.

Why is my YouTube channel thumbnail not changing?

Your YouTube account doesn't come with the ability to upload custom thumbnails by default. In order for your account to gain this ability, you need to first enable the custom thumbnail option.


2 Answers

As I understand it, YouTube only generates high-res stills for high-res videos. The first one you link was uploaded at a resolution of at least 1080p, while the second was less than 720p.

Looks like the only thing you can do is pull the video feed, check that to see if a high-res still has been generated and up-scale the smaller one yourself if not.

All¹ YouTube stills are presented in the 4:3 aspect ratio, so will always have black bars at the top and bottom if the video is 16:9. In HTML/CSS, this is easily combated by setting the image as the background of a div and sizing the div to the correct aspect.

¹ Except the mqdefault.jpg stills, which are all in 16:9 aspect (320x180)

like image 116
Andrew Dinmore Avatar answered Sep 30 '22 19:09

Andrew Dinmore


Update 2015 : None of your 'maxresdefault' link seems to be working

Try these:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
like image 21
kchetan Avatar answered Sep 30 '22 17:09

kchetan