TAN'S Blog

if you obey all the rules you miss all the fun…


Leave a comment

Get Images in 16 : 9 Format

After lots of searching in Goggle, Stack exchange finally I am able to generate images in 16:9 format for youtube, dailymotion and vimeo. So lets have a look how can we simply get the thumb images from dailymotion, vimeo and youtube API.

Dailymotion

Step 1:
From the http://www.dailymotion.com/us if you will click on any video you will get the url in this format for that video:

http://www.dailymotion.com/video/<video_id>

Ex: Here is my url http://www.dailymotion.com/video/x267cnn_pree-two-feet-shy-indmusic-in-the-great-outdoors_music

Step 2:
To get the thumb image in 16:9 format, request dailymotion API in this format:

https://api.dailymotion.com/video/<video_id>?fields=thumbnail_360_url&thumbnail_ratio=widescreen

Ex: https://api.dailymotion.com/video/x267cnn_pree-two-feet-shy-indmusic-in-the-great-outdoors_music?fields=thumbnail_360_url&thumbnail_ratio=widescreen

Step 3:
In Step 2 you will get response like this: {“thumbnail_360_url”:”http:\/\/s2.dmcdn.net\/HphZA\/640×360-E1L.jpg”}

Reconstruct the thumbnail_360_url:
EX: http://s2.dmcdn.net/HPhZA/640×360-E1L.jpg

Image:

640x360-E1L

  640×360(16:9)



Vimeo

Step 1:
Get the vimeo video URL. Ex: http://vimeo.com/831365

Step 2:
To get data about a specific video, use the following url:

http://vimeo.com/api/v2/video/video_id.output

video_id : The ID of the video you want information for. output Specify the output type. VIMEO currently offer JSON, PHP, and XML formats.

So getting this URL http://vimeo.com/api/v2/video/831365.xml:


<videos>
  <video>
    [skipped]
    <thumbnail_small>http://i.vimeocdn.com/video/52914011_100x75.jpg</thumbnail_small>
    <thumbnail_medium>http://i.vimeocdn.com/video/52914011_200x150.jpg</thumbnail_medium>
    <thumbnail_large>http://i.vimeocdn.com/video/52914011_640.jpg</thumbnail_large>
   [skipped]
  </video>
</videos>

Parse this for every video to get the thumbnail.

Here’s approximate code in PHP:


<?php
  $videoid = 831365;

  $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$videoid.php"));

  $hash = $hash[0]['thumbnail_large'];

  $pieces = explode("_", $hash);

  echo "Your Image is here: " . $pieces[0] . "_640x360.jpg";
?>

O/P:
Your Image is here: http://i.vimeocdn.com/video/52914011_640x360.jpg

Image:-

52914011_640x360

     640×360(16:9)


Youtube

Step 1:
Get the youtube video url. Ex: http://www.youtube.com/watch?v=10OTg6lD4Jc

Step 2:
Request youtube API for 16:9 format:

http://img.youtube.com/vi/<video_id>/mqdefault.jpg or http://img.youtube.com/vi/<video_id>/maxresdefault.jpg

Ex(Medium quality image):
http://img.youtube.com/vi/10OTg6lD4Jc/mqdefault.jpg

Image:

mqdefault

320×180(16:9)

Ex(High quality image):
http://img.youtube.com/vi/10OTg6lD4Jc/maxresdefault.jpg

7788_91393518121913073

 1280×720(16:9)

References:
http://stackoverflow.com/questions/25740034/show-dailymotion-video-and-thumbnail-in-correct-169-format
http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo

/* Hope You will love it */