I'm looking to use Vimeo as a CDN for my own video player on my website, but I've been unable to figure out how to request specific video URLs for each quality. What I hope to do is to retrieve 3 specific video links for 3 specific qualities: 4k, 3k and 2k.
The problem is that Vimeo supplies the video data as an array, and the video qualities seem to be indexed at random. The following code will print a video URL for the specific Vimeo ID, but the video with 0 index could be the 4k version, the 1080 hd version, the 3k version... it's random. Is there a way I can filter this to request a specific video quality? Vimeo's API documentation is not very clear on filtering options.
$config = require(__DIR__ . '/init.php');
$lib = new Vimeo($config['client_id'], $config['client_secret']);
if (!empty($config['access_token'])) {
$lib->setToken($config['access_token']);
$video = $lib->request('/me/videos/250665164');
} else {
$user = $lib->request('/me');
}
?>
<?php print_r($video['body']['files'][0]['link']); ?>
This is a snippet of the array result. I have truncated it and also removed the actual URLs. I had considered looping through the array to extract a related value based on the [width] parameter, but I assume there must be a simpler way to do this with the API commands.
[files] => Array
(
[0] => Array
(
[quality] => sd
[type] => video/mp4
[width] => 960
[height] => 480
[link] => http://...
[created_time] => 2018-01-11T18:49:01+00:00
[fps] => 29.97
[size] => 5566399
[md5] => ba7546b1aa42aea63b9adad9d2d62b09
[link_secure] => https://...
)
[1] => Array
(
[quality] => hd
[type] => video/mp4
[width] => 4096
[height] => 2048
[link] => http://...
[created_time] => 2018-01-11T18:49:01+00:00
[fps] => 29.97
[size] => 82082650
[md5] => 0ba6049bb2aa75d52ddb934fde208cbc
[link_secure] => https://...
)
Currently there is no way to request a specific video file quality from the Vimeo API. The videos are not returned in any specific order - some qualities may complete transcoding before others, depending on the resolution of the original video, the visual complexity of the video, the server load on our transcoding machines at the time, and a whole host of other variables. For now, you'll need to get the whole files
response and take out the video file links you need.
Additionally, when grabbing those specific video files, it's best to retrieve them or filter them according to their height/width dimensions, and not by their quality
. All files with dimensions over 720p are marked as "quality":"hd"
from Vimeo.
Finally, note that Vimeo doesn't transcode a "3K" version; for a UHD resolution source video, Vimeo transcodes into 360p, 540p, 720p, 1080p, 1440p (2K), and 3840p (4K). More info here: https://vimeo.com/help/compression