我想从Vimeo获得视频的缩略图。

当从Youtube上获得图像时,我只是这样做:

http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg

你知道如何处理Vimeo吗?

同样的问题,没有答案。


当前回答

更新:此解决方案于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';

其他回答

下面是一个如何在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

function getVimeoInfo($link)
 {
    if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) 
    {
        $id = $match[1];
    }
    else
    {
        $id = substr($link,10,strlen($link));
    }

    if (!function_exists('curl_init')) die('CURL is not installed!');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = unserialize(curl_exec($ch));
    $output = $output[0];
    curl_close($ch);
    return $output;
}`

//在下面的函数传递缩略图url。

function save_image_local($thumbnail_url)
    {

         //for save image at local server
         $filename = time().'_hbk.jpg';
         $fullpath = '../../app/webroot/img/videos/image/'.$filename;

         file_put_contents ($fullpath,file_get_contents($thumbnail_url));

        return $filename;
    }

这里有一个完美的解决方案

   URL Example : https://vumbnail.com/226020936.jpg
   URL method :  https://vumbnail.com/{video_id}.jpg

这对我很有效。

这似乎是一个老问题,但我有几个与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);
});

事实上,问这个问题的人张贴了他自己的答案。

“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下载文件。