Javascript 强制为 YouTube 提供高质量缩略图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9052750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force High Quality Thumbnails for YouTube
提问by SparrwHawk
Is there a way to force a high quality THUMBNAIL for YouTube?
有没有办法为 YouTube 强制使用高质量的缩略图?
My videos are of very high quality and once they start streaming they run fine in 720p, however the thumbnail for the video is of variable quality - sometimes it's high, other times it's really blurry.
我的视频质量非常高,一旦开始流式传输,它们就可以在 720p 下正常运行,但是视频的缩略图质量参差不齐 - 有时很高,有时很模糊。
Is there a way of forcing a high quality thumbnail? I've found this in the API docs - http://code.google.com/apis/youtube/2.0/reference.html#youtube%5Fdata%5Fapi%5Ftag%5Fmedia:thumbnailbut it doesn't detail how to use the media tag.
有没有办法强制高质量缩略图?我在 API 文档中找到了这个 - http://code.google.com/apis/youtube/2.0/reference.html#youtube%5Fdata%5Fapi%5Ftag%5Fmedia:thumbnail但它没有详细说明如何使用媒体标签。
回答by Johan Dettmar
There is a "maxres" version as well, which is a "full hd" picture in case that the video resolution is high enough.
还有一个“maxres”版本,它是一个“全高清”图片,以防视频分辨率足够高。
http://i.ytimg.com/vi/VIDEO_ID/maxresdefault.jpg
However, if the video resolution isn't high enough, this image doesn't seem to be created. So you might want to have a function that shows a lower quality version in case the "maxres" version doesn't exist.
但是,如果视频分辨率不够高,则似乎无法创建此图像。因此,如果“maxres”版本不存在,您可能希望有一个显示较低质量版本的功能。
Check out How do I get a YouTube video thumbnail from the YouTube API?for more info.
查看如何从 YouTube API 获取 YouTube 视频缩略图?了解更多信息。
回答by Evalds Urtans
Thanks, Johan for answer.
谢谢,约翰的回答。
http://i.ytimg.com/vi/VIDEO_ID/maxresdefault.jpg
If you also want set playback to HQ use Javascript API https://developers.google.com/youtube/js_api_reference?hl=fi-FI#Playback_quality
如果您还想将播放设置为 HQ,请使用 Javascript API https://developers.google.com/youtube/js_api_reference?hl=fi-FI#Playback_quality
var qualityLevels = self.players[iframeID].getAvailableQualityLevels();
/* Set highest quality */
self.players[iframeID].setPlaybackQuality(qualityLevels[0]);
In order for this to work we first need to call:
为了使其工作,我们首先需要调用:
self.players[iframeID].playVideo();
Then it will triggrer
然后它会触发
self.players[iframeID] = new YT.Player(iframeID, {
events: {
'onReady': function(event) {
var iframe = $(event.target.getIframe());
self.players[iframe.attr('id')].loaded = true;
},
'onStateChange': function(event) {
var iframe = $(event.target.getIframe());
var iframeID = iframe.attr('id');
if(event.data == 1) /* playing */
{
var qualityLevels = self.players[iframeID].getAvailableQualityLevels();
if(self.players[iframeID].getPlaybackQuality() != qualityLevels[0])
{
/* Set highest quality */
self.players[iframeID].setPlaybackQuality(qualityLevels[0]);
}
}
}
}
});
回答by Dmitriy Yusupov
Example:
例子:
http://img.youtube.com/vi/xjFouf6j81g/hqdefault.jpg
where xjFouf6j81g, videoid
其中 xjFouf6j81g, videoid
回答by Anentropic
Issue has been reported here:
https://code.google.com/p/gdata-issues/issues/detail?can=2&start=0&num=100&q=&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary&groupby=&sort=&id=4590
问题已在此处报告:https:
//code.google.com/p/gdata-issues/issues/detail?can=2&start=0&num=100&q=&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary&groupby= &sort=&id=4590
Not a fix or a workaround, but if you want to avoid getting the low-res thumbnail your player should be larger than 430px
wide.
不是修复或解决方法,但如果您想避免获得低分辨率缩略图,您的播放器应该大于430px
宽度。
So a suggested minimum size for perfect 16:9 aspect would be 432 x 243 pixels
and this should get a nice-looking thumbnail.
因此,对于完美的 16:9 宽高比,建议的最小尺寸是432 x 243 pixels
,这应该会得到一个漂亮的缩略图。
回答by Martti Laine
As far as I know, YouTube only offers 4 thumbnails:
据我所知,YouTube 只提供 4 个缩略图:
http://i.ytimg.com/vi/VIDEO_ID/default.jpg
http://i.ytimg.com/vi/VIDEO_ID/1.jpg
http://i.ytimg.com/vi/VIDEO_ID/2.jpg
http://i.ytimg.com/vi/VIDEO_ID/3.jpg
The thumbnails are generated once after the upload, so you can't alter the size of them in any way.
缩略图在上传后生成一次,因此您无法以任何方式更改它们的大小。
Edit:
YouTube JS API lets you force the quality of the video, but I don't know if it will affect the video preview. See the docsfor more info.
编辑:
YouTube JS API 可让您强制视频质量,但我不知道它是否会影响视频预览。有关更多信息,请参阅文档。