我希望能够从 Vimeo 获取视频缩略图。
获取 Youtube 的图片只需要这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
有没有关于如何在Vimeo上实现的想法?
我希望能够从 Vimeo 获取视频缩略图。
获取 Youtube 的图片只需要这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
有没有关于如何在Vimeo上实现的想法?
我在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;
这里是完美的解决方案 -
URL Example : https://vumbnail.com/226020936.jpg
URL method : https://vumbnail.com/{video_id}.jpg
对我来说起作用了。
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);
}
结果变量将从oEmbed API获得JSON。
接下来,在我的使用情况中,我需要将其作为视频归档的缩略图。我为每个缩略图包装器DIV添加了一个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);
});
你可能想看一下Matt Hooks的Gem。https://github.com/matthooks/vimeo
它提供了一个简单的vimeo api包装器。
你只需要存储视频ID(如果你还要处理其他视频网站,则还需提供其提供商)。
你可以像这样提取vimeo视频ID:
def
get_vimeo_video_id (link)
vimeo_video_id = nil
vimeo_regex = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/
vimeo_match = vimeo_regex.match(link)
if vimeo_match.nil?
vimeo_regex = /http:\/\/player.vimeo.com\/video\/([a-z0-9-]+)/
vimeo_match = vimeo_regex.match(link)
end
vimeo_video_id = vimeo_match[2] unless vimeo_match.nil?
return vimeo_video_id
end
如果您需要使用YouTube,您可能会发现这很有用。
def
get_youtube_video_id (link)
youtube_video_id = nil
youtube_regex = /^(https?:\/\/)?(www\.)?youtu.be\/([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtube_regex.match(link)
if youtube_match.nil?
youtubecom_regex = /^(https?:\/\/)?(www\.)?youtube.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtubecom_regex.match(link)
end
youtube_video_id = youtube_match[3] unless youtube_match.nil?
return youtube_video_id
end
对于像我这样最近试图弄清楚这个问题的人来说,
https://i.vimeocdn.com/video/[video_id]_[dimension].webp
对我很有效。
(其中dimension
= 200x150 | 640)
http://i.vimeocdn.com/video/201990344.webp
它会返回错误的缩略图。这是我的测试视频链接https://vimeo.com/201990344
。 - Farmer