-
-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work in Firefox 79+ because SharedArrayBuffer is undefined #106
Comments
Could it be because of missing COOP/COEP headers? I faced the same issue in the ffmpeg.wasm demo in its Github page. Some casual searching led me to this issue in Bugzilla which led me to this page on web.dev. Also the Firefox 79 for developers page which @amn linked says the same thing. I guess the Github page needs to be configured to send the correct headers? |
Yes, it is the retriction in github page, please reference this issue for more details: #102 |
I have tried to host the page in Google App Engine, in firefox the SharedArrayBuffer is detected but there is an OOM error in the end, for those who are interested, please check this link: https://ffmpegwasm.et.r.appspot.com |
This kind of usage will always raise an OOM with any relatively large video, rather the transcoded chunks should be streamed into an MSE container. |
The interesting part is that the exactly same code works fine on Chrome, so I think there is some limitation inside Firefox that makes it OOM. |
This OOM detour isn't FFmpeg specific per se, but I'd still want to point out the following. When in doubt, look at the spec -- https://w3c.github.io/FileAPI/#blob-section -- does the spec mandate anything that would say, force a user agent vendor to implement My point is that this is browser specific since the spec does not say anything of the "you must allocate memory for each blob" sort. A naive implementation would certainly do, but there are ways to avoid that. For instance, let's say you already have a big number of smaller blobs, you then construct a large blob using an array of the smaller blobs. How much additional memory must a user agent allocate? There is no definite answer to that -- beyond the allocation of an array of what amounts to trivial references to existing blobs, even the large blob constructed may simply reference existing blobs in a way that is transparent to the Blob API consumer, including other facilities in the user agent itself, that use blobs. Practically, and exactly because the spec also does not mandate blobs reuse references to data they were constructed with (no mandating copy-on-write), you cannot guarantee there won't be OOM errors. Most likely there will be, even in Chrome, given sufficient amount and sizes of blobs. Memory is finite resource. The only way out is another API, a |
If you "stream chunks to an MSE container" ( What you could do, and this is speculation now on my part, is look into the Cache API to see if you could construct a "cached" version of the resulting resource, which is allocated on disk (being that the Cache API uses persistent storage), and then construct a URL to the cached resource and/or |
Blobs in Chrome may be disk-based, so using them may doesn't hit an OOM like in Firefox, memory is finite just like persistent/disk storage or given the restrictions browser vendors may impose on this (beyond what is stated in an specification), hence any browser including Chrome can face an OOM depending the amount of data you feed it. Did anybody tested this with a +3GB video? Here MSE shall be used if the end purpose is streaming the video as in the demo, in a nutshell that is by appending the transcoded chunks in real-time until a certain threshold is reached to prevent the MSE's SourceBuffer from reaching a quota error (i.e. ala-OOM). This way should certainly be much more cross-browser reliable and UX-friendly than loading/transcoding the whole video in memory and then start playing it, by using MSE it could start playing within a few seconds. |
See #102 (comment) on how to fix the header issue in Firefox. |
Hello, I am trying http://ffmpegwasm.et.r.appspot.com/ with Firefox 83 and it is saying that SharedArrayBuffer is undefined, as in the issue title. I can confirm from the inspector tools that the headers are set appropriately mentioned in #102. They are included in the lower right of the screenshot below: I see the last comment on this issue is recent (18 days ago)...so I'm wondering if it's something that just broke, or if it's just something weird about my Firefox? My settings in |
I think I figured out the problem...it is because of having an http link instead of https. (It seems that demo URL is not automatically forwarding to the secure site if you have a non-secure link.) |
The header issue in Firefox is also coming to Chrome: https://blog.chromium.org/2021/02/restriction-on-sharedarraybuffers.html |
Yep can confirm. I get a warning about this in chrome in dev tools:
|
I've managed to add the headers necessary to get ffmpeg.wasm running in Firefox, but now I need to serve the files locally (because they're very restrictive). Is there a distribution that can be served locally? It'd be nice to have a tar.gz or .zip to serve them directly. |
Also the SharedArrayBuffer behaviour of Firefox will come to chrome and (since it depends on it) to edge, blocking all major browsers. Maybe the fix of @AndrewDubya is helpfull?! |
You can upload it to your website (but it needs to have https enabled). But yeah no local usage will be possible I guess (or non https). |
Sorry, I should've been more clear. When I said locally, I meant serving them locally as opposed to from unpkg.com. Starting in May, the unpkg cdn will be broken for everyone because the headers required restrict including assets from other URLs. Here's the hack I came up with to serve it from the same domain: #166 (comment) I totally get that this is a tech demo and bleeding edge. I think the long term solution would be to fallback to a single thread without SharedArrayBuffer. But I have no idea how complex that is in practice :) A non-shared array fallback would make it work for most browsers, and more cases where developers don't have access to web server configs. |
Actually you are right. For some reason it worked on mine before I looked at the code lol |
To enable SharedArrayBuffer, the website needs to adopt "cross-origin isolation". Here's a guide to enable it: https://web.dev/cross-origin-isolation-guide/ The downside of this is all resources loaded onto the same page needs to opt-in by sending You can try emulating the headers on this demo site: https://first-party-test.glitch.me/ What I would recommend is to determine whether the page is cross-origin isolated by examining |
Chrome 92 was just released and do need cross-origin-isolation. I think the doc has to be updated : https://ffmpegwasm.github.io/ |
Yes, now we are using a new URL now: https://ffmpegwasm.netlify.app
|
I'm getting this same issue in chrome under local development using the vite bundler. tried adding the headers to no luck. |
For local development, I recommend using |
I was able to fix this in Chrome for a react project on netlify by creating a
|
After enabling cross-origin isolated , |
For those that want to host a demo/app on a domain where you can't control the headers, with a service worker you can actually set the required COOP and COEP headers. See the coi-serviceworker repo, and this blog post that explains the approach. It's a bit crazy, but it's a solution for demos hosted on Github pages. |
need add http header in server,here is node server example
|
If someone is using vite as a dev environment, I managed with this. |
Describe the bug
The front page says:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
As
SharedArrayBuffer
is available in the aforementioned versions of Firefox (on certain conditions), I think it is fair we don't fall into the "this only works in Chrome" bane of Web applications made today, especially if the application may in fact work in Firefox and the latter only refuses to provide the object for security reasons: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/79#JavaScriptDesktop (please complete the following information):
The text was updated successfully, but these errors were encountered: