!(function (e, t) {
  "object" == typeof exports && "object" == typeof module
    ? (module.exports = t())
    : "function" == typeof define && define.amd
      ? define([], t)
      : "object" == typeof exports
        ? (exports.FFmpegWASM = t())
        : (e.FFmpegWASM = t())
})(self, () =>
  (() => {
    "use strict"
    var e = {
      m: {},
      d: (t, s) => {
        for (var r in s)
          e.o(s, r) &&
            !e.o(t, r) &&
            Object.defineProperty(t, r, { enumerable: !0, get: s[r] })
      },
      u: (e) => e + ".ffmpeg.js"
    }
    ;(e.g = (function () {
      if ("object" == typeof globalThis) return globalThis
      try {
        return this || new Function("return this")()
      } catch (e) {
        if ("object" == typeof window) return window
      }
    })()),
      (e.o = (e, t) => Object.prototype.hasOwnProperty.call(e, t)),
      (e.r = (e) => {
        "undefined" != typeof Symbol &&
          Symbol.toStringTag &&
          Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }),
          Object.defineProperty(e, "__esModule", { value: !0 })
      }),
      (() => {
        var t
        e.g.importScripts && (t = e.g.location + "")
        var s = e.g.document
        if (!t && s && (s.currentScript && (t = s.currentScript.src), !t)) {
          var r = s.getElementsByTagName("script")
          if (r.length)
            for (var a = r.length - 1; a > -1 && !t; ) t = r[a--].src
        }
        if (!t)
          throw new Error(
            "Automatic publicPath is not supported in this browser"
          )
        ;(t = t
          .replace(/#.*$/, "")
          .replace(/\?.*$/, "")
          .replace(/\/[^\/]+$/, "/")),
          (e.p = t)
      })(),
      (e.b = document.baseURI || self.location.href)
    var t,
      s = {}
    e.r(s),
      e.d(s, { FFFSType: () => n, FFmpeg: () => i }),
      (function (e) {
        ;(e.LOAD = "LOAD"),
          (e.EXEC = "EXEC"),
          (e.FFPROBE = "FFPROBE"),
          (e.WRITE_FILE = "WRITE_FILE"),
          (e.READ_FILE = "READ_FILE"),
          (e.DELETE_FILE = "DELETE_FILE"),
          (e.RENAME = "RENAME"),
          (e.CREATE_DIR = "CREATE_DIR"),
          (e.LIST_DIR = "LIST_DIR"),
          (e.DELETE_DIR = "DELETE_DIR"),
          (e.ERROR = "ERROR"),
          (e.DOWNLOAD = "DOWNLOAD"),
          (e.PROGRESS = "PROGRESS"),
          (e.LOG = "LOG"),
          (e.MOUNT = "MOUNT"),
          (e.UNMOUNT = "UNMOUNT")
      })(t || (t = {}))
    const r = (() => {
        let e = 0
        return () => e++
      })(),
      a =
        (new Error("unknown message type"),
        new Error("ffmpeg is not loaded, call `await ffmpeg.load()` first")),
      o = new Error("called FFmpeg.terminate()")
    new Error("failed to import ffmpeg-core.js")
    class i {
      #e = null
      #t = {}
      #s = {}
      #r = []
      #a = []
      loaded = !1
      #o = () => {
        this.#e &&
          (this.#e.onmessage = ({ data: { id: e, type: s, data: r } }) => {
            switch (s) {
              case t.LOAD:
                ;(this.loaded = !0), this.#t[e](r)
                break
              case t.MOUNT:
              case t.UNMOUNT:
              case t.EXEC:
              case t.FFPROBE:
              case t.WRITE_FILE:
              case t.READ_FILE:
              case t.DELETE_FILE:
              case t.RENAME:
              case t.CREATE_DIR:
              case t.LIST_DIR:
              case t.DELETE_DIR:
                this.#t[e](r)
                break
              case t.LOG:
                this.#r.forEach((e) => e(r))
                break
              case t.PROGRESS:
                this.#a.forEach((e) => e(r))
                break
              case t.ERROR:
                this.#s[e](r)
            }
            delete this.#t[e], delete this.#s[e]
          })
      }
      #i = ({ type: e, data: t }, s = [], o) =>
        this.#e
          ? new Promise((a, i) => {
              const n = r()
              this.#e && this.#e.postMessage({ id: n, type: e, data: t }, s),
                (this.#t[n] = a),
                (this.#s[n] = i),
                o?.addEventListener(
                  "abort",
                  () => {
                    i(
                      new DOMException(
                        `Message # ${n} was aborted`,
                        "AbortError"
                      )
                    )
                  },
                  { once: !0 }
                )
            })
          : Promise.reject(a)
      on(e, t) {
        "log" === e ? this.#r.push(t) : "progress" === e && this.#a.push(t)
      }
      off(e, t) {
        "log" === e
          ? (this.#r = this.#r.filter((e) => e !== t))
          : "progress" === e && (this.#a = this.#a.filter((e) => e !== t))
      }
      load = ({ classWorkerURL: s, ...r } = {}, { signal: a } = {}) => {
        if (!this.#e) {
          let workerURL;
      
          if (s) {
            // 显式传入 classWorkerURL
            workerURL = new URL(
              s,
              "file:///Users/focus/Projects/ffmpeg.wasm/packages/ffmpeg/dist/esm/classes.js"
            );
            // console.log("使用自定义 classWorkerURL:", workerURL.href);
            this.#e = new Worker(workerURL, { type: "module" });
          } else {
            // 使用嵌入的 Worker 脚本内容创建 Blob URL
            try {
              // 假设 Worker 脚本内容已嵌入
              const scriptContent = getWorkerScriptContent();
              const blob = new Blob([scriptContent], { type: 'application/javascript' });
              const blobURL = URL.createObjectURL(blob);
              console.log("使用 Blob URL 加载 Worker:", blobURL);
              this.#e = new Worker(blobURL);
              // this.#e.blobURL = blobURL; // 保存 Blob URL 以便后续清理
              //console.log(this.#e, 'worker');
            } catch (e) {
              //console.error("Error creating Worker:", e);
              throw new Error("无法创建 Worker，请检查脚本内容");
            }
          }

          this.#o();
        }

        return this.#i({ type: t.LOAD, data: r }, void 0, a);
      }
      exec = (e, s = -1, { signal: r } = {}) =>
        this.#i({ type: t.EXEC, data: { args: e, timeout: s } }, void 0, r)
      ffprobe = (e, s = -1, { signal: r } = {}) =>
        this.#i({ type: t.FFPROBE, data: { args: e, timeout: s } }, void 0, r)
      terminate = () => {
        const e = Object.keys(this.#s)
        for (const t of e) this.#s[t](o), delete this.#s[t], delete this.#t[t]
        this.#e && (this.#e.terminate(), (this.#e = null), (this.loaded = !1))
      }
      writeFile = (e, s, { signal: r } = {}) => {
        const a = []
        return (
          s instanceof Uint8Array && a.push(s.buffer),
          this.#i({ type: t.WRITE_FILE, data: { path: e, data: s } }, a, r)
        )
      }
      mount = (e, s, r) =>
        this.#i(
          { type: t.MOUNT, data: { fsType: e, options: s, mountPoint: r } },
          []
        )
      unmount = (e) => this.#i({ type: t.UNMOUNT, data: { mountPoint: e } }, [])
      readFile = (e, s = "binary", { signal: r } = {}) =>
        this.#i(
          { type: t.READ_FILE, data: { path: e, encoding: s } },
          void 0,
          r
        )
      deleteFile = (e, { signal: s } = {}) =>
        this.#i({ type: t.DELETE_FILE, data: { path: e } }, void 0, s)
      rename = (e, s, { signal: r } = {}) =>
        this.#i({ type: t.RENAME, data: { oldPath: e, newPath: s } }, void 0, r)
      createDir = (e, { signal: s } = {}) =>
        this.#i({ type: t.CREATE_DIR, data: { path: e } }, void 0, s)
      listDir = (e, { signal: s } = {}) =>
        this.#i({ type: t.LIST_DIR, data: { path: e } }, void 0, s)
      deleteDir = (e, { signal: s } = {}) =>
        this.#i({ type: t.DELETE_DIR, data: { path: e } }, void 0, s)
    }
    var n
    return (
      (function (e) {
        ;(e.MEMFS = "MEMFS"),
          (e.NODEFS = "NODEFS"),
          (e.NODERAWFS = "NODERAWFS"),
          (e.IDBFS = "IDBFS"),
          (e.WORKERFS = "WORKERFS"),
          (e.PROXYFS = "PROXYFS")
      })(n || (n = {})),
      s
    )
  })()
)
//# sourceMappingURL=ffmpeg.js.map

function getWorkerScriptContent() {
  return "let createTrustedScriptURL = (url) => url;\n" +
      "if (typeof trustedTypes !== 'undefined' && trustedTypes.createPolicy) {\n" +
      "  const policy = trustedTypes.createPolicy('ffmpeg-core-policy', {\n" +
      "    createScriptURL: (url) => {\n" +
      "      if (url.startsWith('blob:') || url.includes('ffmpeg-core.js')) {\n" +
      "        return url;\n" +
      "      }\n" +
      "      throw new TypeError('无效的脚本 URL');\n" +
      "    }\n" +
      "  });\n" +
      "  createTrustedScriptURL = (url) => policy.createScriptURL(url);\n" +
      "}\n" +
      "\n" +
      "const genBlobUrl = async (url) => {\n" +
      "  console.log(url, 'fetch resource url')\n" +
      "  let resp = await fetch(url);\n" +
      "  if (!resp.ok) throw new Error('failed to fetch ffmpeg-core.js');\n" +
      "  // console.log(resp, 'resp')\n" +
      "  let jsCode = await resp.text();\n" +
      "  // console.log(jsCode, 'jsCode')\n" +
      "  // 创建 Blob URL 并通过 importScripts 加载\n" +
      "  const blob = new Blob([jsCode], { type: \"application/javascript\" })\n" +
      "  return URL.createObjectURL(blob);\n" +
      "}\n" +
      "\n" +
      "!(function (e, t) {\n" +
      "  \"object\" == typeof exports && \"object\" == typeof module\n" +
      "    ? (module.exports = t())\n" +
      "    : \"function\" == typeof define && define.amd\n" +
      "      ? define([], t)\n" +
      "      : \"object\" == typeof exports\n" +
      "        ? (exports.FFmpegWASM = t())\n" +
      "        : (e.FFmpegWASM = t())\n" +
      "})(self, () =>\n" +
      "  (() => {\n" +
      "    var e = {\n" +
      "        454: (e) => {\n" +
      "          function t(e) {\n" +
      "            return Promise.resolve().then(() => {\n" +
      "              var t = new Error(\"Cannot find module '\" + e + \"'\")\n" +
      "              throw ((t.code = \"MODULE_NOT_FOUND\"), t)\n" +
      "            })\n" +
      "          }\n" +
      "\n" +
      "          ;(t.keys = () => []), (t.resolve = t), (t.id = 454), (e.exports = t)\n" +
      "        }\n" +
      "      },\n" +
      "      t = {}\n" +
      "\n" +
      "    function r(o) {\n" +
      "      var s = t[o]\n" +
      "      if (void 0 !== s) return s.exports\n" +
      "      var a = (t[o] = { exports: {} })\n" +
      "      return e[o](a, a.exports, r), a.exports\n" +
      "    }\n" +
      "\n" +
      "    return (\n" +
      "      (r.o = (e, t) => Object.prototype.hasOwnProperty.call(e, t)),\n" +
      "      (() => {\n" +
      "        \"use strict\"\n" +
      "        const e =\n" +
      "          \"https://unpkg.com/@ffmpeg/core@0.12.9/dist/umd/ffmpeg-core.js\"\n" +
      "        var t\n" +
      "        !(function (e) {\n" +
      "          ;(e.LOAD = \"LOAD\"),\n" +
      "            (e.EXEC = \"EXEC\"),\n" +
      "            (e.FFPROBE = \"FFPROBE\"),\n" +
      "            (e.WRITE_FILE = \"WRITE_FILE\"),\n" +
      "            (e.READ_FILE = \"READ_FILE\"),\n" +
      "            (e.DELETE_FILE = \"DELETE_FILE\"),\n" +
      "            (e.RENAME = \"RENAME\"),\n" +
      "            (e.CREATE_DIR = \"CREATE_DIR\"),\n" +
      "            (e.LIST_DIR = \"LIST_DIR\"),\n" +
      "            (e.DELETE_DIR = \"DELETE_DIR\"),\n" +
      "            (e.ERROR = \"ERROR\"),\n" +
      "            (e.DOWNLOAD = \"DOWNLOAD\"),\n" +
      "            (e.PROGRESS = \"PROGRESS\"),\n" +
      "            (e.LOG = \"LOG\"),\n" +
      "            (e.MOUNT = \"MOUNT\"),\n" +
      "            (e.UNMOUNT = \"UNMOUNT\")\n" +
      "        })(t || (t = {}))\n" +
      "        const o = new Error(\"unknown message type\"),\n" +
      "          s = new Error(\n" +
      "            \"ffmpeg is not loaded, call `await ffmpeg.load()` first\"\n" +
      "          ),\n" +
      "          a =\n" +
      "            (new Error(\"called FFmpeg.terminate()\"),\n" +
      "            new Error(\"failed to import ffmpeg-core.js\"))\n" +
      "        let n\n" +
      "        self.onmessage = async ({ data: { id: E, type: c, data: i } }) => {\n" +
      "          const p = []\n" +
      "          let f\n" +
      "          try {\n" +
      "            if (c !== t.LOAD && !n) throw s\n" +
      "            switch (c) {\n" +
      "              case t.LOAD:\n" +
      "                f = await (async ({ coreURL: o, wasmURL: s, workerURL: E }) => {\n" +
      "                  const c = !n\n" +
      "                  try {\n" +
      "                    if (!o) {\n" +
      "                      o = e;\n" +
      "                    }\n" +
      "                    for (let i = 0; i < 3; i++) {\n" +
      "                      try {\n" +
      "                        const blobURL = await genBlobUrl(o)\n" +
      "                        console.log('Importing blob URL:', blobURL);\n" +
      "                        importScripts(createTrustedScriptURL(blobURL));\n" +
      "                        URL.revokeObjectURL(blobURL); // 清理 Blob URL\n" +
      "                        break;\n" +
      "                      } catch (e) {\n" +
      "                        console.log(e, 'importScripts error')\n" +
      "                        if (i === 2) throw e\n" +
      "                      }\n" +
      "                    }\n" +
      "                  } catch (error){\n" +
      "                    console.log(error, 'importScripts error')\n" +
      "                    if (\n" +
      "                      ((o && o !== e) || (o = e.replace(\"/umd/\", \"/esm/\")),\n" +
      "                      (self.createFFmpegCore = (await r(454)(o)).default),\n" +
      "                      !self.createFFmpegCore)\n" +
      "                    )\n" +
      "                      throw a\n" +
      "                  }\n" +
      "                  const i = o,\n" +
      "                    p = s || o.replace(/.js$/g, \".wasm\"),\n" +
      "                    f = E || o.replace(/.js$/g, \".worker.js\")\n" +
      "                  const blobWorkerURL = await genBlobUrl(f)\n" +
      "\n" +
      "                  return (\n" +
      "                    (n = await self.createFFmpegCore({\n" +
      "                      mainScriptUrlOrBlob: `${i}#${btoa(\n" +
      "                        JSON.stringify({\n" +
      "                          wasmURL: p,\n" +
      "                          workerURL: blobWorkerURL\n" +
      "                        })\n" +
      "                      )}`\n" +
      "                    })),\n" +
      "                    n.setLogger((e) =>\n" +
      "                      self.postMessage({\n" +
      "                        type: t.LOG,\n" +
      "                        data: e\n" +
      "                      })\n" +
      "                    ),\n" +
      "                    n.setProgress((e) =>\n" +
      "                      self.postMessage({ type: t.PROGRESS, data: e })\n" +
      "                    ),\n" +
      "                    c\n" +
      "                  )\n" +
      "                })(i)\n" +
      "                break\n" +
      "              case t.EXEC:\n" +
      "                f = (({ args: e, timeout: t = -1 }) => {\n" +
      "                  n.setTimeout(t), n.exec(...e)\n" +
      "                  const r = n.ret\n" +
      "                  return n.reset(), r\n" +
      "                })(i)\n" +
      "                break\n" +
      "              case t.FFPROBE:\n" +
      "                f = (({ args: e, timeout: t = -1 }) => {\n" +
      "                  n.setTimeout(t), n.ffprobe(...e)\n" +
      "                  const r = n.ret\n" +
      "                  return n.reset(), r\n" +
      "                })(i)\n" +
      "                break\n" +
      "              case t.WRITE_FILE:\n" +
      "                f = (({ path: e, data: t }) => (n.FS.writeFile(e, t), !0))(i)\n" +
      "                break\n" +
      "              case t.READ_FILE:\n" +
      "                f = (({ path: e, encoding: t }) =>\n" +
      "                  n.FS.readFile(e, { encoding: t }))(i)\n" +
      "                break\n" +
      "              case t.DELETE_FILE:\n" +
      "                f = (({ path: e }) => (n.FS.unlink(e), !0))(i)\n" +
      "                break\n" +
      "              case t.RENAME:\n" +
      "                f = (({ oldPath: e, newPath: t }) => (n.FS.rename(e, t), !0))(i)\n" +
      "                break\n" +
      "              case t.CREATE_DIR:\n" +
      "                f = (({ path: e }) => (n.FS.mkdir(e), !0))(i)\n" +
      "                break\n" +
      "              case t.LIST_DIR:\n" +
      "                f = (({ path: e }) => {\n" +
      "                  const t = n.FS.readdir(e),\n" +
      "                    r = []\n" +
      "                  for (const o of t) {\n" +
      "                    const t = n.FS.stat(`${e}/${o}`),\n" +
      "                      s = n.FS.isDir(t.mode)\n" +
      "                    r.push({ name: o, isDir: s })\n" +
      "                  }\n" +
      "                  return r\n" +
      "                })(i)\n" +
      "                break\n" +
      "              case t.DELETE_DIR:\n" +
      "                f = (({ path: e }) => (n.FS.rmdir(e), !0))(i)\n" +
      "                break\n" +
      "              case t.MOUNT:\n" +
      "                f = (({ fsType: e, options: t, mountPoint: r }) => {\n" +
      "                  const o = e,\n" +
      "                    s = n.FS.filesystems[o]\n" +
      "                  return !!s && (n.FS.mount(s, t, r), !0)\n" +
      "                })(i)\n" +
      "                break\n" +
      "              case t.UNMOUNT:\n" +
      "                f = (({ mountPoint: e }) => (n.FS.unmount(e), !0))(i)\n" +
      "                break\n" +
      "              default:\n" +
      "                throw o\n" +
      "            }\n" +
      "          } catch (e) {\n" +
      "            return void self.postMessage({\n" +
      "              id: E,\n" +
      "              type: t.ERROR,\n" +
      "              data: e.toString()\n" +
      "            })\n" +
      "          }\n" +
      "          f instanceof Uint8Array && p.push(f.buffer),\n" +
      "            self.postMessage({ id: E, type: c, data: f }, p)\n" +
      "        }\n" +
      "      })(),\n" +
      "      {}\n" +
      "    )\n" +
      "  })()\n" +
      ")\n" +
      "//# sourceMappingURL=814.ffmpeg.js.map";
}
