Html 强制 youtube 嵌入以 720p 开始

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7582336/
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 10:50:30  来源:igfitidea点击:

Force youtube embed to start in 720p

htmlyoutubeembed

提问by Mark Kramer

There are a few methods suggested for doing this online, but none of them seem to work.

有一些建议用于在线执行此操作的方法,但它们似乎都不起作用。

For example:

例如:

http://blog.makezine.com/archive/2008/11/youtube-in-720p-hd-viewin.html

http://blog.makezine.com/archive/2008/11/youtube-in-720p-hd-viewin.html

That article is about making it start in 720p, but it doesn't even work on their own video.

那篇文章是关于让它以 720p 开始,但它甚至不适用于他们自己的视频。

Does anyone here know how to do it?

这里有人知道怎么做吗?

回答by TrySpace

(This answer was updated, as the previous method using vqisn't recognized anymore.)

(此答案已更新,因为vq不再识别使用以前的方法。)

Specifying the height of the video will change the quality accordingly. example for html 5;

指定视频的高度将相应地改变质量。html 5 的示例;

<iframe style='width:100%; height:800px;' src='https://www.youtube.com/embed/xxxxxxxx'></iframe>

If you don't want to hardcode the width and height you can add a class to the iframe for css media queries.

如果您不想硬编码宽度和高度,您可以为 css 媒体查询向 iframe 添加一个类。

Tested on a working server + passes the w3.org nuhtml validator.

在工作服务器上测试 + 通过 w3.org nuhtml 验证器。

回答by Mob

You can do this by adding a parameter &hd=1to the video URL. That forces the video to start in the highest resolution available for the video. However you cannot specifically set it to 720p, because not every video has that hd ish.

您可以通过向&hd=1视频 URL添加参数来实现此目的。这会强制视频以视频可用的最高分辨率开始。但是,您不能专门将其设置为 720p,因为并非每个视频都有那种高清格式。

http://www.youtube.com/watch?v=VIDEO_ID&hd=1

http://www.youtube.com/watch?v=VIDEO_ID&hd=1

http://code.google.com/apis/youtube/player_parameters.html

http://code.google.com/apis/youtube/player_parameters.html

UPDATE: as of 2014, hd is deprecated https://developers.google.com/youtube/player_parameters?csw=1#Deprecated_Parameters

更新:截至 2014 年,高清已弃用 https://developers.google.com/youtube/player_parameters?csw=1#Deprecated_Parameters

回答by Costantin Busuioceanu

This is an embed example of video played in HD 1080.

这是在 HD 1080 中播放的视频的嵌入示例。

<iframe width="560" height="315" src="http://youtube.com/v/IplDUxTQxsE&vq=hd1080" frameborder="0" allowfullscreen="1"></iframe>

Let's break apart the code:http://youtube.com/v/video_id&vq=hd1080

让我们分解代码:http://youtube.com/v/video_id&vq=hd1080

Video id for that video: IplDUxTQxsE you will see this type of random code in the link of every YouTube video.

该视频的视频 ID:IplDUxTQxsE 您将在每个 YouTube 视频的链接中看到这种类型的随机代码。

So far so good, this trick works for playing full HD videos directly on webpages!

到目前为止一切顺利,这个技巧适用于直接在网页上播放全高清视频!

You can change the quality to 720 too. &vq=hd720

您也可以将质量更改为 720。 &vq=hd720

回答by t1gor

I've managed to get this working by the following fix:

我设法通过以下修复使其正常工作:

//www.youtube.com/embed/_YOUR_VIDEO_CODE_/?vq=hd720

You video should have the hd720 resolution to do so.

您的视频应该具有 hd720 分辨率才能这样做。

I was using the embedding via iframe, BTW. Hope someone will find this helpful.

我通过 iframe 使用嵌入,顺便说一句。希望有人会发现这有帮助。

回答by Brian Armstrong

The first example below does not work for me, but the second one does (in Chrome).

下面的第一个例子对我不起作用,但第二个例子(在 Chrome 中)。

<iframe width="720" height="405" src="//www.youtube.com/embed/GX_c566xYcQ?rel=0&vq=hd1080" frameborder="0" allowfullscreen="1"></iframe>
<iframe width="720" height="405" src="//youtube.com/v/IplDUxTQxsE?rel=0&vq=hd1080" frameborder="0" allowfullscreen="1"></iframe>

I believe the first one uses the new HTML5 youtube player whereas the bottom one (which works) uses the older flash player. However, the second one doesn't seem to load correctly in Safari/Firefox etc so probably not usable.

我相信第一个使用新的 HTML5 youtube 播放器,而底部的(有效)使用旧的 Flash 播放器。但是,第二个似乎无法在 Safari/Firefox 等中正确加载,因此可能无法使用。

回答by rcz

None of the above solutions seem to work if the width/height is less than the line resolution of quality you select. For example, the following doesn't work for me in Chrome:

如果宽度/高度小于您选择的质量线分辨率,上述解决方案似乎都不起作用。例如,以下在 Chrome 中对我不起作用:

<iframe width="720" height="480" src="//youtube.com/embed/hUezoHa1ZF4?autoplay=true&rel=0&vq=hd720" frameborder="0" allowfullscreen></iframe>

I want to show the high quality video, but notuse up 1280 x 720 pixels on the webpage.

我想显示高质量的视频,但不要在网页上使用 1280 x 720 像素。

When I go to youtube itself, playing 720p video in a 720x480 window looks better than 480p at the same size. I want to play 720p in a 720x480 window (downsampled better quality). There is no good solution yet afaik.

当我访问 youtube 本身时,在 720x480 窗口中播放 720p 视频看起来比相同大小的 480p 更好。我想在 720x480 窗口中播放 720p(下采样质量更好)。还没有很好的解决方案afaik。

回答by whatever61

In case you're still wondering how to do it, then add: &feature=youtu.be&hd=1 Actually now I checked, this works only when you're sending the URL to someone else, not on embed.

如果您仍然想知道该怎么做,请添加: &feature=youtu.be&hd=1 实际上现在我检查过,这仅在您将 URL 发送给其他人时才有效,而不是在嵌入时。

回答by user3053317

Use this, it works 100% _your_videocode?rel=0&vq=hd1080"

使用这个,它可以 100% _your_videocode?rel=0&vq=hd1080"