How to get best/max mp4 video resolution twitter api
stdClass Object ( [bitrate] => 320000 [content_type] => video/mp4 [url] => https://video.twimg.com/ext_tw_video/4565654656538862849/pu/vid/320x180/8tkyfOGWAsk463643.mp4 ) [1] => stdClass Object ( [content_type] => application/x-mpegURL [url] => https://video.twimg.com/ext_tw_video/8234513464436343/pu/pl/UbTspZ_h6W143643zC.m3u8 ) [2] => stdClass Object ( [bitrate] => 832000 [content_type] => video/mp4 [url] => https://video.twimg.com/ext_tw_video/823451433633464364/pu/vid/640x360/051dcpN_Z9nE346.mp4 ) )
i want to getting mp4 with best resolution 640×360 (not same resolution on other posts and different array[0][1][2][…] )
how i get it?
this my code show all video variants
echo ($media->video_info->variants[0]->url .'<br>') ;
echo($media->video_info->variants[1]->url).'<br>' ;
echo ($media->video_info->variants[2]->url).'<br>';
echo ($media->video_info->variants[3]->url) .'<br>';
echo ($media->video_info->variants[4]->url) .'<br>';
2
Answers
Search this question on how to download a file to your server using PHP from another web resource.
The second task is to grab the resolution out of the URL. The URLs seem to follow a pattern:
With a regular expression, you can extract the X and Y resolutions from the mp4 video links:
For each of your URLs you can thus compute the resolution.
If the URL does not contain a resolution, then you would need to download the file to find out. The code above uses the special value ‘0’ to indicate this.
Finding out what the resolution of a particular video file is depends on its file format. As there are a massive amount of video containers, codecs, and so on, I won’t go into details here. The best solution here is to determine which formats are actually relevant to you and implement code for only those formats.
You may want to look at the code of an open-source media player and how it determines resolution.
To solve the simple case:
$pixels
value.This might be late, but consider the following
now you have the highest quality