Toniq
Toniq

Reputation: 5016

Youtube api V3 get video resolution

Some videos come with letterbox / pillarbox black frames like these for example:

https://www.youtube.com/watch?v=pSZofb3VKGU

https://www.youtube.com/watch?v=glGjB3nTmqw

compared to full size video 16/9:

https://www.youtube.com/watch?v=_ZAZD3ylG6Y

I wanted to get video resolution from youtube using their api, but after some investigating I think I am out of luck because I need fileDetails part from Youtube which can only be retrieved by video owner.

Can anybody think of another way to detect video comes in letterbox / pillarbox frame and detect dimensions? ( so I can scale the video myself when embedding, thus removing black borders )

Upvotes: 2

Views: 2618

Answers (1)

Saumini Navaratnam
Saumini Navaratnam

Reputation: 8860

Reference

By default, the height of the returned in the player.embedHtml property is 360px. The width adjusts to match the video's aspect ratio, thereby ensuring that the embedded player does not have black bars framing the video. So, for example, if a video's aspect ratio is 16:9, the player's width would be 640px.

You have to user player part when retrieving video. For example

Following request

GET https://www.googleapis.com/youtube/v3/videos?part=player&id=pSZofb3VKGUkey={YOUR_API_KEY}

will give you following response. Once you embed this video you can see the black border is not there.

"player":{
    "embedHtml":"\u003ciframe width=\"480\" height=\"360\"    src=\"//www.youtube.com/embed/pSZofb3VKGU\" frameborder=\"0\"  allowfullscreen\u003e\u003c/iframe\u003e"
}

This is not working with the video id glGjB3nTmqw may be Youtube is not scaling the height I guess, not sure.

My opinion you don't need to worry about the dimensions. You use the player to get the embed html & render it. Youtube will do all the work of removing the black bars.

Upvotes: 1

Related Questions