让Safari在HTML 5视频标签中更喜欢HEVC [英] Get Safari to prefer HEVC in HTML 5 video tag

查看:703
本文介绍了让Safari在HTML 5视频标签中更喜欢HEVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究为视频添加HEVC支持的可行性,但遇到了Safari问题.这是示例源:

I'm currently investigating the feasibility of adding HEVC support to videos but am hitting a problem with Safari. Here's the sample source:

<video autobuffer="true" autoloop="" loop="" controls="">
    <source src="film_WebM.webm" type="video/webm">
    <source src="film_HEVC.mp4" type="video/mp4">
    <source src="film.mp4" type="video/mp4">
</video>

理想情况下,浏览器应该阅读源代码并说出它认为可以读取的 first 文件,这应该使Firefox和Chromium可以显示VP9影片,Safari可以显示HEVC,Internet Explorer可以显示H264.但是,Safari不能很好地播放,并且如果存在H264,将忽略HEVC电影.我尝试用编解码器信息注释源,但这无济于事.将HEVC设置为视频元素的默认来源可用于Safari,但会导致其他所有浏览器出现问题.

Ideally a browser should read the sources and takt the first file that it thinks it can read and this should allow Firefox and Chromium to show the VP9 film, Safari the HEVC and Internet Explorer the H264. However, Safari doesn't play nicely and will ignore the HEVC film if the H264 is present. I've tried annotating the source with codec information but this doesn't help. Setting HEVC as the default source for the video element works for Safari but causes problems for every other browser.

有什么方法可以解决此问题,而无需使用特征检测来操纵src元素?

Is there any way to solve this without using feature detection to manipulate the src element?

作为Safari的错误在苹果公司提交的#37821806

Filed with Apple as a Safari bug #37821806

下面的讨论表明,尽管有苹果自己的发行说明,但Safari仍可以基于硬件考虑决定使用AVC源.尚不清楚如何在没有编解码器提示或明显的mime类型嗅探的情况下做到这一点.如果人们可以测试 codepen演示并在注释中注明编解码器的功能和Mac硬件,这将非常有用.信息.

The discussion below suggests that Safari could, despite Apple's own release notes, be deciding to use an AVC source based on hardware considerations. How it manages to do this without codec hint or apparent mime-type sniffing is unclear. It would be useful if people could test the codepen demo and note in comments what codec play and Mac hardware info.

推荐答案

首先请确保您的HEVC视频编码正确,以便Safari可以播放.通过从视频标签中删除除指向HEVC视频的源以外的所有源进行测试,以进行测试.如果Safari可以播放,请继续下一步,否则请修复视频文件.

First make sure your HEVC video is encoded correctly so it can be played back by Safari. Test this by removing all sources from the video tag except the one pointing to your HEVC video. If Safari plays it, continue to the next step, otherwise fix the video file.

一旦确定HEVC视频与Safari兼容,请使用source标签中的type属性为浏览器提供有关编解码器的提示.到目前为止,您只告诉浏览器HEVC和H.264源都使用了MP4容器.浏览器必须下载文件的一部分才能确定哪些文件兼容,通常是按source标记的顺序.

Once you are sure the HEVC video is compatible with Safari, give the browser a hint about the codecs by using the type property in the source tags. So far you're only telling the browser that a MP4 container is used for both the HEVC and the H.264 source. Browsers would have to download parts of the files in order to figure out which of the files are compatible, usually in order of the source tags.

您可以/应该指定所有使用的编解码器的详细信息,包括视频编解码器,如果涉及音频,则还应指定音频编解码器.

You can/should specify details about all codecs used, including video codec and if audio is involved, the audio codecs as well.

  • avc1代表H.264
  • hvc1代表H.265(HEVC)
  • avc1 stands for H.264
  • hvc1 stands for H.265 (HEVC)

对于您的示例,最短的版本是这样的:

For your example, the shortest version would be this:

<video>
    <source src="film_WebM.webm" type="video/webm">
    <source src="film_HEVC.mp4" type='video/mp4; codecs="hvc1"'>
    <source src="film.mp4" type='video/mp4; codecs="avc1"'>
</video>

另请参见:在CodePen上演示感谢您在评论中的反馈,我想我已经知道发生了什么事:Safari似乎考虑使用您的硬件来选择最佳的视频源,而这实际上是非常聪明的.对H.264的硬件支持已经广泛使用,即使在较旧的硬件上也是如此,而对HEVC/H.265的硬件支持则不行,并且需要更多的CPU,最终也将需要更多的能量(电池).

Thanks to your feedback in the comments, I think I figured out what's going on: Safari seems to consider your hardware to choose the best video source, which is actually quite clever. Hardware support for H.264 is widely available, even on older hardware, whereas HEVC/H.265 hardware support isn't and requires more CPU and will ultimately require more energy (battery) as well.

因此,尽管您的设备(例如MBP)和软件可以解码和播放HEVC视频,但Safari可能更喜欢H.264视频源(如果有).

So, although your device (e.g. MBP) and software can decode and play the HEVC video, Safari may prefer the H.264 video source if available.

我还做了一些测试:

  • iMac 2014年末(5K):✅HEVC
  • iPhone X(iOS 12 Beta):✅HEVC
  • iPhone 7 Plus(iOS 11):✅HEVC
  • 旧版iPad Air(iOS 11):⚠️更喜欢H.264,但如果没有H.264来源,将播放HEVC视频

这篇关于让Safari在HTML 5视频标签中更喜欢HEVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆