klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

ffmpeg.wasm缓存在indexedb中 #718

Open klren0312 opened 1 year ago

klren0312 commented 1 year ago
import { get, set } from "idb-keyval";

const KEY = "ffmpeg-core.wasm";

async function getFfmpegWasmPath() {
  let buffer = await get(KEY);
  if (!buffer) {
    console.log("fetching wasm file...");
    const response = await fetch(
      "https://unpkg.com/@ffmpeg/core@0.11.0/dist/ffmpeg-core.wasm"
    );
    buffer = await response.arrayBuffer();
    set(KEY, buffer);
    console.log("wasm file fetched and stored in indexedDB");
  }
  console.log("wasm file loaded");
  const blob = new Blob([buffer], { type: "application/wasm" });
  const url = URL.createObjectURL(blob);

  return url;
}