You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Server struggles with remote streaming of compressed video/audio #27
This isn't quite a bug, but could be in some cases considered as such - the server included with the cli struggles to stream video and audio files that are compressed inside of a ZIP-based container, such as EPUB. This was encountered for example with one of the IDPF sample publications: https://github.com/IDPF/epub3-samples/releases/download/20230704/cc-shared-culture.epub
This publication contains compressed videos:
When an asset is compressed using DEFLATE, it becomes impossible to seek to a specific position in the file without first decompressing all content before that offset (in practice, basically the entire file due to ZIP APIs in Golang). Modern browsers' native video players attempt to use byte ranges to buffer a portion of the video (or audio), so it can start playing and save data for the client. However because the video file is compressed, every time a small range is read, the entire video file must be decompressed over and over again. And because the video file is large, it is not cached by our remote streaming caching logic, which currently defaults to 1MB as the max file size for cache eligibility. This leads to a very inefficient and resource-heavy process on the server-side, and a slow loading for the user:
This is also definitely something we should include in our optimization of EPUBs, as compressing of any media content (image, video, audio) make streaming worse
Thanks for raising that issue @chocolatkey, it's also something that we'll want to address in the future optimize command (by using store rather than deflate on all media resources).
The way I see it, there are two different (and maybe complementary ways) to look at this:
should we disable support for byte ranges on such media?
and can we cache something to optimize for this use case?
First of all, although browsers default to byte ranges for <audio> and <video> elements, they can't expect all servers to support them. Do we know how they behave in this case? Do they buffer the whole file?
When an asset is compressed using DEFLATE, it becomes impossible to seek to a specific position in the file without first decompressing all content before that offset (in practice, basically the entire file due to ZIP APIs in Golang).
Once we've done that, couldn't we cache this information in the manifest for further use though?
Activity
HadrienGardeur commentedon May 14, 2025
Thanks for raising that issue @chocolatkey, it's also something that we'll want to address in the future
optimizecommand (by usingstorerather thandeflateon all media resources).The way I see it, there are two different (and maybe complementary ways) to look at this:
First of all, although browsers default to byte ranges for
<audio>and<video>elements, they can't expect all servers to support them. Do we know how they behave in this case? Do they buffer the whole file?Once we've done that, couldn't we cache this information in the manifest for further use though?