YouTube视频提供缩略图(没有黑条)?

时间:2022-02-01 18:57:33

I have managed using the YouTube API to fetch thumbnails for my list of videos, however they have black bars top and bottom of the UIImage I get. Can anyone help me work out how to fetch a thumbnail without these bars and even better a higher quality thumbnail?

我已经使用YouTube API为我的视频列表获取缩略图,但是它们在UIImage的顶部和底部都有黑条。有谁能帮我弄出一个没有这些条条的缩略图,更好的是一个高质量的缩略图?

Here is the code I use currently:

以下是我目前使用的代码:

GDataEntryBase *entry = [[feed entries] objectAtIndex:i];
        NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
        UIImage *thumbnail = [UIImage imageWithData:data];

Thanks.

谢谢。

2 个解决方案

#1


2  

It's also worth noting that all thumbnails are currently in a 4:3 aspect ratio, for historical purposes. If the underlying video is 16:9 and you plan on using a 16:9 player, then it makes sense to position the thumbnail so that the top and bottom black bars are hidden. That's independent of whether you use a lower-resolution or higher-resolution thumbnail.

同样值得注意的是,从历史的角度来看,目前所有的缩略图都是4:3的。如果下面的视频是16:9,而你打算使用16:9播放器,那么将缩略图放置在顶部和底部的黑条隐藏起来是有意义的。这与使用低分辨率或高分辨率的缩略图无关。

#2


1  

Well this answer gave me the hint, so I went ahead and took a guess.

这个答案给了我提示,所以我继续猜。

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

如何从YouTube API获得YouTube视频的缩略图?

Turns out if I just change the index from 0, to 1 of my data object I get a higher quality thumbnail. Magic, easy.

如果我只是将索引从0更改为1,我得到一个更高质量的缩略图。魔法,容易。

#1


2  

It's also worth noting that all thumbnails are currently in a 4:3 aspect ratio, for historical purposes. If the underlying video is 16:9 and you plan on using a 16:9 player, then it makes sense to position the thumbnail so that the top and bottom black bars are hidden. That's independent of whether you use a lower-resolution or higher-resolution thumbnail.

同样值得注意的是,从历史的角度来看,目前所有的缩略图都是4:3的。如果下面的视频是16:9,而你打算使用16:9播放器,那么将缩略图放置在顶部和底部的黑条隐藏起来是有意义的。这与使用低分辨率或高分辨率的缩略图无关。

#2


1  

Well this answer gave me the hint, so I went ahead and took a guess.

这个答案给了我提示,所以我继续猜。

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

如何从YouTube API获得YouTube视频的缩略图?

Turns out if I just change the index from 0, to 1 of my data object I get a higher quality thumbnail. Magic, easy.

如果我只是将索引从0更改为1,我得到一个更高质量的缩略图。魔法,容易。