检测 H.265 HEVC 不兼容性
我试图检测浏览器何时不会播放特定视频。一个很好的例子是尝试检测 Chrome 无法播放 H.265/HEVC 编码的视频。
我尝试使用视频回退:
<video>
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Browser does not support the HTML5 Video element.
</video>
但是我了解到回退仅在浏览器不支持视频时才有效。因此,对于支持视频的Chrome,不会执行回退,但视频将无法播放。
接下来,我尝试监听 error 事件
<video (error)="onError($event)">
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Browser does not support the HTML5 Video element.
</video>
,但是我也没有看到错误事件。
为了好玩,我还附加了 onplay 事件,以确保事件正在触发。这个事件确实发生了。
<video (canplay)="onCanPlay($event)">
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Your browser does not support the HTML5 Video element.
</video>
是否可以在没有外部库的情况下检测浏览器是否支持视频和特定编解码器?
I am trying to detect when a browser will not play a specific video. A good example is trying to detect that Chrome cannot play H.265/HEVC encoded video.
I tried using the video fallback:
<video>
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Browser does not support the HTML5 Video element.
</video>
However I learned that the fallback only works if the browser does not support video. So in the case of Chrome which does support video, the fallback is not executed, but the video will fail to play.
Next up I tried to listen for the error event
<video (error)="onError($event)">
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Browser does not support the HTML5 Video element.
</video>
However I am also not seeing the error event.
For fun I attached the onplay event as well to make sure that events are firing. This event does fire.
<video (canplay)="onCanPlay($event)">
<source [src]="attachmentVideo" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
Your browser does not support the HTML5 Video element.
</video>
Is it possible without an external library to detect if the browser supports a video and specific codec?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要检查 JavaScript 是否支持编解码器,请查看以下选项是否对您有用:
(即:将您选择的选项转换为 Angular 语法/代码)
(1) 如果编解码器已知... 使用
canPlayType
检查编解码器兼容性。(2) 如果编解码器未知... 检查文件字节的编解码器类型(然后执行步骤 (1) 确认可玩性)
这意味着获取一大块文件的字节(例如获取前 64kb 或后 64kb,取决于 MP4 标头位于文件的前面还是后面)。
将数据读入数组,然后在该数组中搜索
stsd
部分,MP4 在此部分保存 H264 数据的序列参数集 (SPS)您可以获得提取编解码器信息。a) 找到
stsd
位置。b) 从该位置开始,跳过
+16
字节以查找avc1
或hev1
。c) 从
+16
位置,从这里向前跳+91
以获取SPS(3字节)。这是一个使用所选(本地)的示例通过 FileReader API 读入数组的文件。
For checking if a codec is supported via JavaScript, see if the options below are useful to you:
(ie: convert your chosen one into Angular syntax/code)
(1) If codec is known... Use
canPlayType
to check codec compatibility.(2) If codec is unknown... Check file bytes for codec type (then do step (1) to confirm playability)
This means getting a chunk of the file's bytes (for example getting the first 64kb or last 64kb, depends if MP4 header is at front or back of file).
Read the data into an Array and then search that Array for the
stsd
section, which is where MP4 keeps the Sequence Parameter Set (SPS) of the H264 data, from that section you can get extract the codec info.a) Find
stsd
position.b) From that position, skip
+16
bytes to find eitheravc1
orhev1
.c) From the
+16
pos, skip forward from here+91
to get the SPS (3 bytes).Here is an example using a selected (local) file which is read into an Array via FileReader API.