Quickly thrown together samples of some different ways you can use append (
appendBuffer
) with MediaSource SourceBuffers.
Make sure to see this blog post for details. This samples are mostly for illustrative / educational purposes, and more robust approaches should consider things like buffer size, garbage collection, adaptive quality, etc. For example, in place of my multi-file examples, you would normally use something like HLS or DASH.
You might also want to consider using an existing <video>
loading library, like video.js or Shaka Player.
Again, for a more in-depth discussion, make sure to check out my writeup: joshuatz.com/posts/2020/appending-videos-in-javascript-with-mediasource-buffers/
⚠ Currently, the multi-file demos use files with a
WEBM
container, withVP8 + Vorbis
as the codec, and the other demos useVP9 + Opus
. This means that they might not work for you if you are using an older browser, or Safari.
🐛 Firefox has been a little buggy for me with multi-file appends; I swapped over those demos from
VP9/Opus
toVP8/Vorbis
and it has seemed to improve things.sequence
mode pretty much only ever works in Chrome, but that is to be expected since that really shouldn't work with multi-track input anyways (and Chrome even warns about this in the log).
If you want to run the demos in your browser, the HTML and JS from this repo is deployed here:
mediasource-append-examples.netlify.app
If you are currently on that site, here are links back to:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。