我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
当前回答
最简单的JavaScript方式,我发现,获得缩略图,无需搜索视频id是使用:
//Get the video thumbnail via Ajax
$.ajax({
type:'GET',
url: 'https://vimeo.com/api/oembed.json?url=' + encodeURIComponent(url),
dataType: 'json',
success: function(data) {
console.log(data.thumbnail_url);
}
});
注意:如果有人需要获得与视频id相关的视频缩略图,他可以将$id替换为视频id,并获得一个包含视频详细信息的XML:
http://vimeo.com/api/v2/video/$id.xml
例子:
http://vimeo.com/api/v2/video/198340486.xml
源
其他回答
事实上,问这个问题的人张贴了他自己的答案。
“Vimeo似乎想让我发出一个HTTP请求,并从他们返回的XML中提取缩略图URL……”
Vimeo API文档在这里:http://vimeo.com/api/docs/simple-api
简而言之,你的应用程序需要像下面这样对一个URL发出GET请求:
http://vimeo.com/api/v2/video/video_id.output
并解析返回的数据以获得所需的缩略图URL,然后在该URL下载文件。
下面是一个如何在ASP中做同样的事情的例子。NET使用c#。请随意使用不同的错误捕获图像:)
public string GetVimeoPreviewImage(string vimeoURL)
{
try
{
string vimeoUrl = System.Web.HttpContext.Current.Server.HtmlEncode(vimeoURL);
int pos = vimeoUrl.LastIndexOf(".com");
string videoID = vimeoUrl.Substring(pos + 4, 8);
XmlDocument doc = new XmlDocument();
doc.Load("http://vimeo.com/api/v2/video/" + videoID + ".xml");
XmlElement root = doc.DocumentElement;
string vimeoThumb = root.FirstChild.SelectSingleNode("thumbnail_medium").ChildNodes[0].Value;
string imageURL = vimeoThumb;
return imageURL;
}
catch
{
//cat with cheese on it's face fail
return "http://bestofepicfail.com/wp-content/uploads/2008/08/cheese_fail.jpg";
}
}
注意:当被请求时,你的API请求应该像这样:http://vimeo.com/api/v2/video/32660708.xml
使用Vimeo url(https://player.vimeo.com/video/30572181),下面是我的示例
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <title>Vimeo</title> </head> <body> <div> <img src="" id="thumbImg"> </div> <script> $(document).ready(function () { var vimeoVideoUrl = 'https://player.vimeo.com/video/30572181'; var match = /vimeo.*\/(\d+)/i.exec(vimeoVideoUrl); if (match) { var vimeoVideoID = match[1]; $.getJSON('http://www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=?', { format: "json" }, function (data) { featuredImg = data[0].thumbnail_large; $('#thumbImg').attr("src", featuredImg); }); } }); </script> </body> </html>
使用jQuery jsonp请求:
<script type="text/javascript">
$.ajax({
type:'GET',
url: 'http://vimeo.com/api/v2/video/' + video_id + '.json',
jsonp: 'callback',
dataType: 'jsonp',
success: function(data){
var thumbnail_src = data[0].thumbnail_large;
$('#thumb_wrapper').append('<img src="' + thumbnail_src + '"/>');
}
});
</script>
<div id="thumb_wrapper"></div>
更新:此解决方案于2018年12月停止工作。
我也在找同样的事情,看起来这里的大多数答案都过时了,因为Vimeo API v2已弃用。
我的PHP 2¢:
$vidID = 12345 // Vimeo Video ID
$tnLink = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/' . $vidID))->thumbnail_url;
通过上面的链接,你将得到Vimeo默认缩略图的链接。
如果你想使用不同大小的图像,你可以添加如下内容:
$tnLink = substr($tnLink, strrpos($tnLink, '/') + 1);
$tnLink = substr($tnLink, 0, strrpos($tnLink, '_')); // You now have the thumbnail ID, which is different from Video ID
// And you can use it with link to one of the sizes of crunched by Vimeo thumbnail image, for example:
$tnLink = 'https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F' . $tnLink . '_1280x720.jpg&src1=https%3A%2F%2Ff.vimeocdn.com%2Fimages_v6%2Fshare%2Fplay_icon_overlay.png';