我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
当前回答
这似乎是一个老问题,但我有几个与Vimeo缩略图相关的项目,所以在前几个月,它与我非常相关。所有的API V2都不适合我,i.vimeocdn.com链接每个月都被弃用。我需要这个可持续的解决方案,为此我使用了oEmbed API: https://developer.vimeo.com/api/oembed
注意:当试图从禁止域访问时,您将得到403错误。只使用目标域或将登台/本地域列入白名单。
下面是我如何用JS得到图像:
async function getThumb (videoId) {
var url = 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/'+videoId+'&width=480&height=360';
try {
let res = await fetch(url);
return await res.json();
} catch (error) {
console.log(error);
}
Result变量将从oEmbed API获得一个JSON。
接下来,在我自己的用例中,我需要这些作为视频存档的缩略图。我为每个缩略图包装器DIV添加了一个ID, ID为“thumbnail-{{ID}}”(例如,“thumbnail-123456789”),并将图像插入到DIV中。
getThumb(videoId).then(function(result) {
var img = document.createElement('img');
img.src = result.thumbnail_url;
document.getElementById('thumbnail-'+videoId).appendChild(img);
});
其他回答
这是一种快速巧妙的方法,也是一种选择自定义大小的方法。
我去这里:
http://vimeo.com/api/v2/video/[VIDEO ID].php
下载文件,打开它,找到640像素宽的缩略图,它的格式如下:
https://i.vimeocdn.com/video/[LONG NUMBER HERE]_640.jpg
你拿这个链接,把640改成——比如——1400,你就会得到这样的东西:
https://i.vimeocdn.com/video/[LONG NUMBER HERE]_1400.jpg
把它粘贴到你的浏览器搜索栏上,享受吧。
欢呼,
更新:此解决方案于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';
使用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>
事实上,问这个问题的人张贴了他自己的答案。
“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下载文件。
在javascript中(使用jQuery):
function vimeoLoadingThumb(id){
var url = "http://vimeo.com/api/v2/video/" + id + ".json?callback=showThumb";
var id_img = "#vimeo-" + id;
var script = document.createElement( 'script' );
script.src = url;
$(id_img).before(script);
}
function showThumb(data){
var id_img = "#vimeo-" + data[0].id;
$(id_img).attr('src',data[0].thumbnail_medium);
}
要显示它:
<img id="vimeo-{{ video.id_video }}" src="" alt="{{ video.title }}" />
<script type="text/javascript">
vimeoLoadingThumb({{ video.id_video }});
</script>