Youtube oembed: How does it calculate the width and height values?

When I use the oembed URL in my PHP code and extract to $video->widthand $video->heightfrom my uploaded video, I return values ​​that do not match what I saw associated with my Youtube video.

  • http://youtu.be/p7ftPYU2_0w

  • Original dimensions of the videos uploaded to Youtube: 640 x 336

  • oembed returns: 480 x 270

  • The smallest implementation option when sharing from the user interface of a Youtube page: 560 x 316

Does anyone know where oembed gets these values? Why is it defaulted to 480? Is there a way to get true video sizes or the minimum default value - up to 640 x [proportional_height]?

My goal is to preserve my own video sizes (without scaling) when embedding on my website, without having to re-enter the video sizes.

+5
source share
3 answers

Youtube can generate content that it could provide to embed content instead of the original video. The width and height of the generated content can be 480 x 270 . So oEmbed api can always return this value. AFIK there is no way to get the initial measurement of the video value from the api side unless the provider provides it before or until.

You can try adjusting the width and size of the video using jquery and css.

oEmbed spec maxwidth maxheight api. , .

, !

+2

CSS.

0

Try something like this

<iframe title="YouTube video player" width="727" height="430" src='http://www.youtube.com/embed/p7ftPYU2_0w' frameborder="0"></iframe>

As far as I know, there is no way to get the height of the video from embedding. You can use jquery to get the height of the player when the page loads and goes from there.

0
source

All Articles