Yahweasel / libav.js

This is a compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil, libswresample, and libswscale—for emscripten, and thus the web.
288 stars 18 forks source link

Support for AIFF #30

Closed maximedupre closed 10 months ago

maximedupre commented 12 months ago

I'm not sure if the lib supports AIFF or not, but I've tried all variants and it seems like I can't load such a file.

Error: Could not open source file

Error occurs at this call: avformat_open_input_js(filename, fmt ? fmt : null, null)

My end goal is to be able to convert an AIFF file to a WAV file.

My code so far is

const libav = await LibAV.LibAV({ noworker: true });

const arrayBuffer = new Uint8Array(
    await (await fetch('./sample.aiff')).arrayBuffer()
);

await libav.writeFile('sample.aiff', arrayBuffer);

const [fmt_ctx, [stream]] = await libav.ff_init_demuxer_file(
    'sample.aiff'
);
// ^ fails

Thanks 🙏

Yahweasel commented 12 months ago

None of the configurations as stands support AIFF, unfortunately, but it's fairly straightforward to add (assuming you have Emscripten and so can compile libav.js). To do that, you've got two direct options:

(1) Create your own configuration by copying one of the existing config/ directories, then add the relevant AIFF steps, or (2) Add a new entry in mkconfigs.js that has the following additions: "format-aiff", "codec-pcm_s16be", "codec-pcm_s32be", "codec-f32be", then just run mkconfigs.js to make your configuration.

You're not the first person to ask for AIFF, so maybe it's time to just have a variant that supports it (probably a "raw and lossless" variant). The variants that are here largely just reflect demand.

maximedupre commented 11 months ago

@Yahweasel should I do anything in particular when running emmake make? It's only compiling the default variant, so I must be missing something 😁

Yahweasel commented 11 months ago

Use make build-<variant>, e.g. make build-aiff if you named your variant aiff.

(By the way, although it's harmless, you don't need to use emmake make for libav.js. Its Makefile calls emconfigure and emmake for the subprojects automatically, since it's only built to build with Emscripten anyway.)