How do I get a YouTube video thumbnail from the YouTube API?

后端 未结 30 2686
Happy的楠姐
Happy的楠姐 2020-11-21 07:06

If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 07:49

    YouTube is serving thumbnails from 2 servers. You just need to replace with your own YouTube video id. These days webP is best format for fast loading of images due to small image size.

    https://img.youtube.com https://i.ytimg.com

    Examples are with https://i.ytimg.com server just because it’s shorter, no other particular reason. You can use both.

    Player Background Thumbnail (480x360):

    WebP
    https://i.ytimg.com/vi_webp//0.webp
    
    JPG
    https://i.ytimg.com/vi//0.jpg
    

    Video frames thumbnails (120x90)

    WebP:
    Start: https://i.ytimg.com/vi_webp//1.webp
    Middle: https://i.ytimg.com/vi_webp//2.webp
    End: https://i.ytimg.com/vi_webp//3.webp
    
    JPG:
    Start: https://i.ytimg.com/vi//1.jpg
    Middle: https://i.ytimg.com/vi//2.jpg
    End: https://i.ytimg.com/vi//3.jpg
    

    Lowest quality thumbnail (120x90)

    WebP
    https://i.ytimg.com/vi_webp//default.webp
    
    JPG
    https://i.ytimg.com/vi//default.jpg
    

    Medium quality thumbnail (320x180)

    WebP
    https://i.ytimg.com/vi_webp//mqdefault.webp
    
    JPG
    https://i.ytimg.com/vi//mqdefault.jpg
    

    High quality thumbnail (480x360)

    WebP
    https://i.ytimg.com/vi_webp//hqdefault.webp
    
    JPG
    https://i.ytimg.com/vi//hqdefault.jpg
    

    Standard quality thumbnail (640x480)

    WebP
    https://i.ytimg.com/vi_webp//sddefault.webp
    
    JPG
    https://i.ytimg.com/vi//sddefault.jpg
    

    Unscaled thumbnail resolution

    WebP
    https://i.ytimg.com/vi_webp//maxresdefault.webp
    
    JPG
    https://i.ytimg.com/vi//maxresdefault.jpg
    

提交回复
热议问题