简体   繁体   English

HTML5 视频在循环中卡顿?

[英]HTML5 video stutters on loop?

I have an HTML5 video element on my page, it's scaled to fill the entire background with the idea being that it will loop as it plays.我的页面上有一个 HTML5 视频元素,它被缩放以填充整个背景,其想法是它会在播放时循环播放。 This works fine in Chrome but Safari and Firefox have stutter on loop.这在 Chrome 中运行良好,但 Safari 和 Firefox 在循环中出现卡顿。 It's a good half a second in Firefox.在 Firefox 中这是一个很好的半秒。 Any ideas?有任何想法吗?

Here's my markup for the video player:这是我对视频播放器的标记:

<video id="vid" preload="auto" autoplay loop onended="this.play();">
  <source src="vid.mp4" type="video/mp4"/>
  <source src="vid.webm" type="video/webm"/>
</video>

I've tried a number of things, like controlling the playback entirely with JS instead of relying on the browser to figure it out.我尝试了很多东西,比如完全用 JS 控制播放,而不是依靠浏览器来解决。 But there's always the stutter.但总是有口吃。 I don't think it's an issue with preloading because if I do it all locally the video loads instantly (obviously) but there's still the same loop.我不认为这是预加载的问题,因为如果我在本地进行所有操作,视频会立即加载(显然)但仍然存在相同的循环。 Is this just an issue inherent in these browsers?这只是这些浏览器固有的问题吗?

I'm tempted to create two instances of the video and simply toggle them with JS after each finishes.我很想创建视频的两个实例,并在每个完成后简单地用 JS 切换它们。 It'd be really dirty but I'm not sure what my other options are.它真的很脏,但我不确定我的其他选择是什么。

I solved it by removing the audio track of the .mp4 during encoding.我通过在编码过程中删除 .mp4 的音轨来解决它。 Not Ideal if you need the audio but it worked well in my case.如果您需要音频,则不理想,但在我的情况下效果很好。

I had this issue and I actually fixed it by putting the webm source before the mp4 source.我遇到了这个问题,实际上我通过将 webm 源放在 mp4 源之前来解决它。 That way it tried to load the webm video format first, and it had less stutters when I was testing it.这样它首先尝试加载 webm 视频格式,并且在我测试时它的卡顿更少。 mp4 and ogv files both had stutters in Firefox and it drove me nuts, so I was amazed when webm files seemed to work as intended. mp4 和 ogv 文件在 Firefox 中都出现卡顿现象,这让我抓狂,所以当 webm 文件似乎按预期工作时,我感到很惊讶。

<video id="vid" preload="auto" autoplay loop>
  <source src="vid.webm" type="video/webm"/>
  <source src="vid.mp4" type="video/mp4"/>
</video>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM