26 lines
729 B
TypeScript
26 lines
729 B
TypeScript
import { createWasmCodec } from "./wasm-base.js";
|
|
|
|
function webmMagic(bytes: Uint8Array): boolean {
|
|
// EBML header: 0x1A 0x45 0xDF 0xA3
|
|
if (bytes.byteLength < 4) return false;
|
|
return (
|
|
bytes[0] === 0x1a &&
|
|
bytes[1] === 0x45 &&
|
|
bytes[2] === 0xdf &&
|
|
bytes[3] === 0xa3
|
|
);
|
|
}
|
|
|
|
/** Lazy WebM (audio track) codec backed by `@audio/decode-webm`. Decode-only. */
|
|
export const WebMCodec = createWasmCodec({
|
|
name: "webm",
|
|
extensions: ["webm"],
|
|
mimeTypes: ["audio/webm"],
|
|
module: "@audio/decode-webm",
|
|
magic: webmMagic,
|
|
supportsEncode: false,
|
|
load: () =>
|
|
// @ts-expect-error optional dependency resolved at runtime
|
|
import("@audio/decode-webm"),
|
|
});
|