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

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

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

你知道如何处理Vimeo吗?

同样的问题,没有答案。


当前回答

对于那些仍然想要通过URL获取缩略图的人,就像Youtube一样,我构建了一个小应用程序,只使用Vimeo ID获取缩略图。

https://vumbnail.com/358629078.jpg

只要插入你的视频ID,它就会提取视频并缓存28天,所以它的服务速度很快。

下面是一些HTML中的例子:

简单图像示例 <img src="https://vumbnail.com/358629078.jpg" /> < br > < br > 现代响应图像示例 < img srcset = " https://vumbnail.com/358629078_large.jpg 640 w, https://vumbnail.com/358629078_medium.jpg 200 w, https://vumbnail.com/358629078_small.jpg 100 w " 尺寸="(max-width: 640px) 100vw, 640px" src = " https://vumbnail.com/358629078.jpg " />

如果你想自己旋转你可以在这里这样做。

Repo

其他回答

function parseVideo(url) {
    // - Supported YouTube URL formats:
    //   - http://www.youtube.com/watch?v=My2FRPA3Gf8
    //   - http://youtu.be/My2FRPA3Gf8
    //   - https://youtube.googleapis.com/v/My2FRPA3Gf8
    // - Supported Vimeo URL formats:
    //   - http://vimeo.com/25451551
    //   - http://player.vimeo.com/video/25451551
    // - Also supports relative URLs:
    //   - //player.vimeo.com/video/25451551

    url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);

    if (RegExp.$3.indexOf('youtu') > -1) {
        var type = 'youtube';
    } else if (RegExp.$3.indexOf('vimeo') > -1) {
        var type = 'vimeo';
    }

    return {
        type: type,
        id: RegExp.$6
    };
}

function getVideoThumbnail(url, cb) {
    var videoObj = parseVideo(url);
    if (videoObj.type == 'youtube') {
        cb('//img.youtube.com/vi/' + videoObj.id + '/maxresdefault.jpg');
    } else if (videoObj.type == 'vimeo') {
        $.get('http://vimeo.com/api/v2/video/' + videoObj.id + '.json', function(data) {
            cb(data[0].thumbnail_large);
        });
    }
}

我写了一个函数在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

这是一种快速巧妙的方法,也是一种选择自定义大小的方法。

我去这里:

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

把它粘贴到你的浏览器搜索栏上,享受吧。

欢呼,

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。

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");