Skip to content

Instantly share code, notes, and snippets.

@piyu-sh
Created August 19, 2023 10:05
Show Gist options
  • Save piyu-sh/de416fcab6a9e20bb69f9a2b1b4e60f7 to your computer and use it in GitHub Desktop.
Save piyu-sh/de416fcab6a9e20bb69f9a2b1b4e60f7 to your computer and use it in GitHub Desktop.
ffmpeg-worker.js
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/const.js":
/*!************************************************************************************************!*\
!*** ./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/const.js ***!
\************************************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "CORE_URL": () => (/* binding */ CORE_URL),
/* harmony export */ "CORE_VERSION": () => (/* binding */ CORE_VERSION),
/* harmony export */ "FFMessageType": () => (/* binding */ FFMessageType),
/* harmony export */ "MIME_TYPE_JAVASCRIPT": () => (/* binding */ MIME_TYPE_JAVASCRIPT),
/* harmony export */ "MIME_TYPE_WASM": () => (/* binding */ MIME_TYPE_WASM)
/* harmony export */ });
const MIME_TYPE_JAVASCRIPT = "text/javascript";
const MIME_TYPE_WASM = "application/wasm";
const CORE_VERSION = "0.12.1";
const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd/ffmpeg-core.js`;
var FFMessageType;
(function (FFMessageType) {
FFMessageType["LOAD"] = "LOAD";
FFMessageType["EXEC"] = "EXEC";
FFMessageType["WRITE_FILE"] = "WRITE_FILE";
FFMessageType["READ_FILE"] = "READ_FILE";
FFMessageType["DELETE_FILE"] = "DELETE_FILE";
FFMessageType["RENAME"] = "RENAME";
FFMessageType["CREATE_DIR"] = "CREATE_DIR";
FFMessageType["LIST_DIR"] = "LIST_DIR";
FFMessageType["DELETE_DIR"] = "DELETE_DIR";
FFMessageType["ERROR"] = "ERROR";
FFMessageType["DOWNLOAD"] = "DOWNLOAD";
FFMessageType["PROGRESS"] = "PROGRESS";
FFMessageType["LOG"] = "LOG";
})(FFMessageType || (FFMessageType = {}));
/***/ }),
/***/ "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/errors.js":
/*!*************************************************************************************************!*\
!*** ./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/errors.js ***!
\*************************************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "ERROR_IMPORT_FAILURE": () => (/* binding */ ERROR_IMPORT_FAILURE),
/* harmony export */ "ERROR_NOT_LOADED": () => (/* binding */ ERROR_NOT_LOADED),
/* harmony export */ "ERROR_TERMINATED": () => (/* binding */ ERROR_TERMINATED),
/* harmony export */ "ERROR_UNKNOWN_MESSAGE_TYPE": () => (/* binding */ ERROR_UNKNOWN_MESSAGE_TYPE)
/* harmony export */ });
const ERROR_UNKNOWN_MESSAGE_TYPE = new Error("unknown message type");
const ERROR_NOT_LOADED = new Error("ffmpeg is not loaded, call `await ffmpeg.load()` first");
const ERROR_TERMINATED = new Error("called FFmpeg.terminate()");
const ERROR_IMPORT_FAILURE = new Error("failed to import ffmpeg-core.js");
/***/ }),
/***/ "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm lazy recursive":
/*!**************************************************************************************************************!*\
!*** ./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/ lazy namespace object ***!
\**************************************************************************************************************/
/***/ ((module) => {
function webpackEmptyAsyncContext(req) {
// Here Promise.resolve().then() is used instead of new Promise() to prevent
// uncaught exception popping up in devtools
return Promise.resolve().then(() => {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
});
}
webpackEmptyAsyncContext.keys = () => ([]);
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
webpackEmptyAsyncContext.id = "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm lazy recursive";
module.exports = webpackEmptyAsyncContext;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
/*!*************************************************************************************************!*\
!*** ./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/worker.js ***!
\*************************************************************************************************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _const_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./const.js */ "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/const.js");
/* harmony import */ var _errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./errors.js */ "./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm/errors.js");
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="webworker" />
let ffmpeg;
const load = async ({ coreURL: _coreURL = _const_js__WEBPACK_IMPORTED_MODULE_0__.CORE_URL, wasmURL: _wasmURL, workerURL: _workerURL, }) => {
const first = !ffmpeg;
const coreURL = _coreURL;
const wasmURL = _wasmURL ? _wasmURL : _coreURL.replace(/.js$/g, ".wasm");
const workerURL = _workerURL
? _workerURL
: _coreURL.replace(/.js$/g, ".worker.js");
try {
// when web worker type is `classic`.
importScripts(coreURL);
}
catch {
// when web worker type is `module`.
self.createFFmpegCore = (await __webpack_require__("./node_modules/.pnpm/@[email protected]/node_modules/@ffmpeg/ffmpeg/dist/esm lazy recursive")(coreURL)).default;
if (!self.createFFmpegCore) {
throw _errors_js__WEBPACK_IMPORTED_MODULE_1__.ERROR_IMPORT_FAILURE;
}
}
ffmpeg = await self.createFFmpegCore({
// Fix `Overload resolution failed.` when using multi-threaded ffmpeg-core.
// Encoded wasmURL and workerURL in the URL as a hack to fix locateFile issue.
mainScriptUrlOrBlob: `${coreURL}#${btoa(JSON.stringify({ wasmURL, workerURL }))}`,
});
ffmpeg.setLogger((data) => self.postMessage({ type: _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.LOG, data }));
ffmpeg.setProgress((data) => self.postMessage({
type: _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.PROGRESS,
data,
}));
return first;
};
const exec = ({ args, timeout = -1 }) => {
ffmpeg.setTimeout(timeout);
ffmpeg.exec(...args);
const ret = ffmpeg.ret;
ffmpeg.reset();
return ret;
};
const writeFile = ({ path, data }) => {
ffmpeg.FS.writeFile(path, data);
return true;
};
const readFile = ({ path, encoding }) => ffmpeg.FS.readFile(path, { encoding });
// TODO: check if deletion works.
const deleteFile = ({ path }) => {
ffmpeg.FS.unlink(path);
return true;
};
const rename = ({ oldPath, newPath }) => {
ffmpeg.FS.rename(oldPath, newPath);
return true;
};
// TODO: check if creation works.
const createDir = ({ path }) => {
ffmpeg.FS.mkdir(path);
return true;
};
const listDir = ({ path }) => {
const names = ffmpeg.FS.readdir(path);
const nodes = [];
for (const name of names) {
const stat = ffmpeg.FS.stat(`${path}/${name}`);
const isDir = ffmpeg.FS.isDir(stat.mode);
nodes.push({ name, isDir });
}
return nodes;
};
// TODO: check if deletion works.
const deleteDir = ({ path }) => {
ffmpeg.FS.rmdir(path);
return true;
};
self.onmessage = async ({ data: { id, type, data: _data }, }) => {
const trans = [];
let data;
try {
if (type !== _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.LOAD && !ffmpeg)
throw _errors_js__WEBPACK_IMPORTED_MODULE_1__.ERROR_NOT_LOADED;
switch (type) {
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.LOAD:
data = await load(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.EXEC:
data = exec(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.WRITE_FILE:
data = writeFile(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.READ_FILE:
data = readFile(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.DELETE_FILE:
data = deleteFile(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.RENAME:
data = rename(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.CREATE_DIR:
data = createDir(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.LIST_DIR:
data = listDir(_data);
break;
case _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.DELETE_DIR:
data = deleteDir(_data);
break;
default:
throw _errors_js__WEBPACK_IMPORTED_MODULE_1__.ERROR_UNKNOWN_MESSAGE_TYPE;
}
}
catch (e) {
self.postMessage({
id,
type: _const_js__WEBPACK_IMPORTED_MODULE_0__.FFMessageType.ERROR,
data: e.toString(),
});
return;
}
if (data instanceof Uint8Array) {
trans.push(data.buffer);
}
self.postMessage({ id, type, data }, trans);
};
})();
/******/ })()
;
//# sourceMappingURL=beesy-node_modules_pnpm_ffmpeg_ffmpeg_0_12_4_node_modules_ffmpeg_ffmpeg_dist_esm_worker_js.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment