Html 如何强制 youtube 播放高清视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26032397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:46:21  来源:igfitidea点击:

How to force youtube to play HD videos

htmlvideoyoutubeyoutube-api

提问by Pramod

I have below video in youtube iframe and forcefully wants to run it on High Quality at first go

我在 youtube iframe 中有以下视频,并且强烈希望一开始就以高质量运行它

https://www.youtube.com/embed/3nmnMtbzzjE

https://www.youtube.com/embed/3nmnMtbzzjE

I tried Parameters like hd=1 and vq=hd720 and vq=hd1080 But i think these are outdated or not in function.

我尝试过像 hd=1 和 vq=hd720 和 vq=hd1080 这样的参数,但我认为这些参数已经过时或不起作用。

Please suggest. Regards

请建议。问候

采纳答案by Zupecki

I just solved this problem for a website I was working on.

我刚刚为我正在开发的网站解决了这个问题。

I have embedded iframes with youtube videos in them and they, annoyingly, auto-played at a low resolution despite my wanting them to auto-play at 720p. This issue is caused by the actual size of the video, on your page, being detected by YouTube which will trigger an auto-selection of a lower res.

我在 iframe 中嵌入了 youtube 视频,尽管我希望它们以 720p 自动播放,但令人讨厌的是,它们以低分辨率自动播放。此问题是由 YouTube 检测到您页面上视频的实际大小引起的,这将触发自动选择较低的分辨率。

Here's what I did to keep my video embed small, but have it auto play on 720p etc -

这是我为保持视频嵌入较小而做的事情,但让它在 720p 等上自动播放 -

  1. You need to add ?vq=hd720 at the end of your video id, as you have done.
  2. Manually set the iframe width to width="1280" height="720" - which will make the video huge on your site.
  3. Wrap the iframe in a div and give it a class selector so you can style it with css.
  4. Use CSS to tell your div wrapper to be the size you actually want the video to be.
  5. Use CSS to set the iframe width:100% and height:100%.
  1. 您需要在视频 ID 的末尾添加 ?vq=hd720,就像您所做的那样。
  2. 手动将 iframe 宽度设置为 width="1280" height="720" - 这将使您网站上的视频变得巨大。
  3. 将 iframe 包装在一个 div 中并为其提供一个类选择器,以便您可以使用 css 对其进行样式设置。
  4. 使用 CSS 告诉您的 div 包装器是您实际希望视频的大小。
  5. 使用 CSS 设置 iframe 的宽度:100% 和高度:100%。

This code will basically set the video size to be that of the resolution you want it to auto-play on, which will trick YouTube into setting this for you. Then the CSS dynamically resizes the video to be whatever actual size you need.

此代码基本上会将视频大小设置为您希望它自动播放的分辨率,这将诱使 YouTube 为您设置。然后 CSS 动态地将视频大小调整为您需要的任何实际大小。

And that's all there is to it :)

这就是它的全部:)

CODE EXAMPLE:

代码示例:

HTML

HTML

<div class="youtube-embed">
    <iframe width="1280" height="720" src="https://www.youtube.com/embed/VIDEOID?vq=hd720" frameborder="0" allowfullscreen></iframe>
</div>

CSS

CSS

.youtube-embed {
    width  : 740px;
    height : 400px;
}

.youtube-embed iframe {
    width  : 100%;
    height : 100%;
}

回答by Eddie Caplan

YouTube may be altering the quality of the playback based on your window size. See this article: http://demosthenes.info/blog/717/Force-Embedded-YouTube-Videos-To-Play-In-HD

YouTube 可能会根据您的窗口大小改变播放质量。请参阅这篇文章:http: //demosthenes.info/blog/717/Force-Embedded-YouTube-Videos-To-Play-In-HD

回答by John the Traveler

Pls see this article: http://www.reddit.com/r/youtube/comments/2fckq3/did_youtube_disable_hdlinking_adding_hd1_at_the/

请参阅这篇文章:http: //www.reddit.com/r/youtube/comments/2fckq3/did_youtube_disable_hdlinking_adding_hd1_at_the/

it seems that you could use vq=1080 to suggest the use of hd video, but the HD will be used only when the video window is large enough

好像可以用vq=1080来建议使用高清视频,但是只有视频窗口足够大时才会使用高清