我想从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的响应。没有办法用URL调用(如dailymotion或youtube)。
下面是我的PHP解决方案:
/**
* Gets a vimeo thumbnail url
* @param mixed $id A vimeo id (ie. 1185346)
* @return thumbnail's url
*/
function getVimeoThumb($id) {
$data = file_get_contents("http://vimeo.com/api/v2/video/$id.json");
$data = json_decode($data);
return $data[0]->thumbnail_medium;
}
其他回答
我写了一个函数在PHP让我这,我希望它对某人有用。缩略图的路径包含在视频页面的链接标记中。这似乎对我有用。
$video_url = "http://vimeo.com/7811853"
$file = fopen($video_url, "r");
$filedata = stream_get_contents($file);
$html_content = strpos($filedata,"<link rel=\"videothumbnail");
$link_string = substr($filedata, $html_content, 128);
$video_id_array = explode("\"", $link_string);
$thumbnail_url = $video_id_array[3];
echo $thumbnail_url;
希望能对大家有所帮助。
Foggson
事实上,问这个问题的人张贴了他自己的答案。
“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下载文件。
2020的解决方案:
我写了一个使用Vimeo Oembed API的PHP函数。
/**
* Get Vimeo.com video thumbnail URL
*
* Set the referer parameter if your video is domain restricted.
*
* @param int $videoid Video id
* @param URL $referer Your website domain
* @return bool/string Thumbnail URL or false if can't access the video
*/
function get_vimeo_thumbnail_url( $videoid, $referer=null ){
// if referer set, create context
$ctx = null;
if( isset($referer) ){
$ctxa = array(
'http' => array(
'header' => array("Referer: $referer\r\n"),
'request_fulluri' => true,
),
);
$ctx = stream_context_create($ctxa);
}
$resp = @file_get_contents("https://vimeo.com/api/oembed.json?url=https://vimeo.com/$videoid", False, $ctx);
$resp = json_decode($resp, true);
return $resp["thumbnail_url"]??false;
}
用法:
echo get_vimeo_thumbnail_url("1084537");
更新:此解决方案于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';
api/v2似乎已经死了。 为了使用新的API,您需要注册应用程序,base64将client_id和client_secret编码为授权标头。
$.ajax({
type:'GET',
url: 'https://api.vimeo.com/videos/' + video_id,
dataType: 'json',
headers: {
'Authorization': 'Basic ' + window.btoa(client_id + ":" + client_secret);
},
success: function(data) {
var thumbnail_src = data.pictures.sizes[2].link;
$('#thumbImg').attr('src', thumbnail_src);
}
});
为了安全起见,您可以返回已经从服务器编码的client_id和client_secret。