bvibber / ogv.js

JavaScript media player using Ogg/Vorbis/Theora/Opus/WebM libs compiled with Emscripten
https://brooke.vibber.net/misc/ogv.js/demo/
Other
1.2k stars 101 forks source link

How can I modify the source code so it's possible to load .wasm code not from file? #628

Open VladiStep opened 10 months ago

VladiStep commented 10 months ago

I am trying to embed "ogv.js" files into one JS-file, but it seems like I can't load .wasm code not from file. The generated code for "ogv-demuxer-ogg-wasm.js" contains hardcoded string "ogv-demuxer-ogg-wasm.wasm": image

Also, I can't find where it comes from (there's no "ogv-demuxer-ogg-wasm.wasm" in the source code anywhere).

VladiStep commented 10 months ago

I just want to add it to a Tampermonkey script that will replace all <audio> elements with .ogg audio with OGVPlayer. It's for Safari.

bvibber commented 6 months ago

Use the -s SINGLE_FILE=1 option in the emscripten build and modify the Makefile to avoid copying the wasm files. This will increase the size of the javascript package because it has to base64 the wasm.

// If set to 1, embeds all subresources in the emitted file as base64 string
// literals. Embedded subresources may include (but aren't limited to) wasm,
// asm.js, and static memory initialization code.
//
// When using code that depends on this option, your Content Security Policy may
// need to be updated. Specifically, embedding asm.js requires the script-src
// directive to allow 'unsafe-inline', and using a Worker requires the
// child-src directive to allow blob:. If you aren't using Content Security
// Policy, or your CSP header doesn't include either script-src or child-src,
// then you can safely ignore this warning.
// [link]
var SINGLE_FILE = false;
bvibber commented 6 months ago

On main branch (work in progress refactoring, so beware it is not stable) you can undo this commit:

https://github.com/bvibber/ogv.js/commit/d03dce9e8dd48d71ba63024a4a886e7329a5fe22

to turn single-file mode on, as I was experimenting with it for simplifying packaging.