2011-02-15 132 views

回答

7

在Data API调用中唯一显示精确视频维度的地方是在您通过使用v3 API进行videos.list(part=fileDetails, id=VIDEO_ID)调用,同时作为视频所有者进行身份验证时。它在video.fileDetails.videoStreams[].aspectRatio属性中返回。这不是特别有用,因为您需要通过视频所有者的身份验证才能获取该信息。

如果你只是有一个网页,并希望使一个JSONP电话获取有关给定的视频是否是16一个提示:9或4:3,你可以做到这一点通过类似

http://gdata.youtube.com/feeds/api/videos/VIDEO_ID? v = 2 & alt = jsonc & callback = myCallback

Eg

http://gdata.youtube.com/feeds/api/videos/F1IVb2_FYxQ?v=2&alt=jsonc&callback=myCallback

在其响应,这是一个暗示该视频是16 "aspectRatio":"widescreen"组:9(或接近16:9)。

http://gdata.youtube.com/feeds/api/videos/u1zgFlCw8Aw?v=2&alt=jsonc&callback=myCallback

没有aspectRatio集在所有,这意味着该视频为4:3(或接近4:3)。这并不总是确切的长宽比,但它足够接近绝大多数视频的用处。

1

宽高比显然取决于质量水平。采取从YouTube Docs

Quality level small: Player height is 240px, and player dimensions are at least 320px by 240px for 4:3 aspect ratio. 
Quality level medium: Player height is 360px, and player dimensions are 640px by 360px (for 16:9 aspect ratio) or 480px by 360px (for 4:3 aspect ratio). 
Quality level large: Player height is 480px, and player dimensions are 853px by 480px (for 16:9 aspect ratio) or 640px by 480px (for 4:3 aspect ratio). 
Quality level hd720: Player height is 720px, and player dimensions are 1280px by 720px (for 16:9 aspect ratio) or 960px by 720px (for 4:3 aspect ratio). 
Quality level hd1080: Player height is 1080px, and player dimensions are 1920px by 1080px (for 16:9 aspect ratio) or 1440px by 1080px (for 4:3 aspect ratio). 
Quality level highres: Player height is greater than 1080px, which means that the player's aspect ratio is greater than 1920px by 1080px. 
+1

这篇文档说每个质量级别可以有16:9或4:3的宽高比。 – infojunkie 2011-02-15 23:02:46

+0

不包括第一个和最后一个。我找不到任何其他宽高比的文档。但看看不同的宽度和高度。当然,你可以用它来确定比例? – Shaz 2011-02-15 23:04:37

+0

这是我的代码,设置播放器的宽度和高度 - 使用它们来推导纵横比是没有意义的。 – infojunkie 2011-02-15 23:55:58

3

这是我如何做到这一点。我从YouTube图像中获得纵横比。

<img id"nnS7G3Y-IDc-img" src="http://i.ytimg.com/vi/nnS7G3Y-IDc/default.jpg" /> 
<script> 
//using jquery 
var height = $('#nnS7G3Y-IDc-img').css('height'); 
var width = $('#nnS7G3Y-IDc-img').css('width'); 
height = height.replace('px', ''); 
width = width.replace('px', ''); 
var arB = height/3; 
var arT = width/arB; 
if (arT == 4) { 
    //do what you need to with the aspect ratio info from here 
    //just demonstrating with an alert 
    alert ("4:3"); 
} 
else {alert ("16:9");} 
</script> 

我把所有的视频信息通过YouTube API,然后存储在数据库中的所有视频信息提前,所以,如果你这样做是在飞行中,你可能必须隐藏页面上的图像和然后获得纵横比。

编辑**另一个选项,可能是最好的,将使用youtube's api。 搜索视频,并检查是否设置了data-> items-> aspectRatio。我不认为它是在4:3视频上设置的,但在16:9上设置为宽屏。应该如此简单if (data->items->aspectRatio) {ratio= "16:9"} else {ratio="4:3"}

0

也许不是一个好的答案,但似乎有一个假设,其他答案是YouTube视频是16:9或4:3。

但是他们可以有一个非常随意的长宽比,而且纵向手机视频已经变得非常普遍,对YouTube上的视频变得不那么稀有了。

对于这些非标准的长宽比,作为一个快速的手动软糖,我使用全屏播放,做屏幕截图,裁剪图像。

我已经在http://youtube-aspect-ratios.xtra.ink上提供了几个任意方面视频的例子。

相关问题