Initial Commit
This commit is contained in:
25
packages/media/audio/audio-codecs/src/codecs/webm.ts
Normal file
25
packages/media/audio/audio-codecs/src/codecs/webm.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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"),
|
||||
});
|
||||
Reference in New Issue
Block a user