HTML视频流大小超过文件大小,如何使用JavaScript缓存和优化HTML视频元素?

发布于 2025-01-18 16:53:03 字数 258 浏览 3 评论 0原文

我正在尝试从nodejs服务器流传输视频,并且正常工作。但是问题在于视频尺寸为61MB。当我更改我的HTML视频元素中的范围时,它再次获取,如果继续,则导致循环和提取尺寸将超过100 MB。在视频满载并将流尺寸最大化为视频尺寸之后,如何不再加载视频?

networks

I am trying to stream a video from a NodeJS server and it is working fine. But the problem is with the video size, which is 61MB. As I change my range in the html video element it fetches again, which causes a loop and fetch size will exceed 100 mb if continued. How not to load the video anymore, after the video is fully loaded and keep stream size maximum to video size?

networks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

家住魔仙堡 2025-01-25 16:53:03

但问题是视频大小为 61MB

这不是问题。

当我更改 html 视频元素中的范围时,它会再次获取进入循环的内容,并且如果继续,获取大小将超过 100 mb

浏览器正在尝试优化要获取的内容,并对视频的播放方式做出假设。理想情况下,它只想下载实际使用的视频,而不下载其他视频。

如果视频已完全加载,如何不再加载视频并保持流大小最大为视频大小

您需要对缓存行为进行更严格的控制。幸运的是,您可以使用 Service Worker 来完成此操作。可以构建 Service Worker 来拦截来自媒体元素的请求,并将范围内的请求一起缓存到单个资源中。如果稍后再次需要该资源,Service Worker 将控制直接从本地缓存获取该资源。

but the problem is video size is 61MB

This is not a problem.

as i change my range in html video element it again fetches which goes in loop and fetch size exceeds 100 mb if continued

The browser is trying to optimize what to fetch, making assumptions about the way a video will be played. Ideally, it only wants to download the video that's actually used and no additional video.

how not to load video anymore if the video is fully loaded and keep stream size maximum to video size

You need tighter control over the caching behavior. Fortunately, you can do this with a Service Worker. The Service Worker can be built to intercept requests form the media elements, and cache ranged requests together into a single resource. If the resource is needed again later, the Service Worker will control fetching it directly from local cache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文