ffmpegwasm / ffmpegwasm/ffmpeg.wasm

toBlobURL / downloadWithProgress method don't handle compressed files

Open
#803 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
17.8k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hey,
in short: I have a problem with handling progress in `toBlobURL` method, when downloading a compressed wasm module.

Some observations:
* if we pass a progress block, the `downloadWithProgress` implementation is used under-the-hood,
* the display of the progress block is based on the `Content-Length` header
* the `Content-Length` header is related to `Content-Encoding` (which is controlled by the client, e.g.: `Accept-Encoding: gzip, deflate, br, zstd`)
* the `fetch` method downloads the compressed module, but returns the uncompressed one,

This causes this exception to occur in this `downloadWithProgress` method:
```
if (total != -1 && total !== received)
throw ERROR_INCOMPLETED_DOWNLOAD;
```

Then in the `catch` block, we call `buf = await resp.arrayBuffer()`, and this causes a second exception on the already downloaded file:
```
ffmpegwasm Failed to execute 'arrayBuffer' on 'Response': body stream already read…
```
Which effectively makes it impossible to download this wasm module.

Wasm files compress very well, for example, the `ffmpeg-core.wasm` module compresses from ~30MB to ~7MB using brotli.

Personally, I don't know how to fix this properly, that the `downloadWithProgress` method handles compressed files.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.