The next-generation file converter. Open source, fully local* and free forever.
feat: serve ffmpeg from host
JovannMC40b293888466
diff --git a/.env.example b/.env.exampleindex ad199da..0f542e9 100644--- a/.env.example+++ b/.env.example@@ -12,7 +12,6 @@ PUB_VERTD_URL=https://vertd.vert.sh# Set to true to disable all external requests (vertd, Stripe, Plausible, etc.)# Useful for privacy-focused deployments or air-gapped environments-# Note: the ffmpeg worker is still downloaded via a CDN (cdn.jsdelivr.net)PUB_DISABLE_ALL_EXTERNAL_REQUESTS=false# Set to true to disable blocking video conversions of an uploaded file when repeated failuresdiff --git a/bun.lock b/bun.lockindex 8c7c2f3..3bbbdbe 100644--- a/bun.lock+++ b/bun.lock@@ -6,6 +6,7 @@"name": "vert","dependencies": {"@bjorn3/browser_wasi_shim": "^0.4.2",+ "@ffmpeg/core": "0.12.10","@ffmpeg/ffmpeg": "^0.12.15","@ffmpeg/util": "^0.12.2","@fontsource/azeret-mono": "^5.3.0",@@ -126,6 +127,8 @@"@eslint/plugin-kit": ["@eslint/[email protected]", "", { "dependencies": { "@eslint/core": "^1.2.1", "levn": "^0.4.1" } }, "sha512-IkO+/KEUvwbVpiURZg+P7zF74z5Jxe0UgJxVni+RtoHQ6IZieXaO02kmadomap/q+l6bc/jdPGGqTjhuZnuz1Q=="],+ "@ffmpeg/core": ["@ffmpeg/[email protected]", "", {}, "sha512-dzNplnn2Nxle2c2i2rrDhqcB19q9cglCkWnoMTDN9Q9l3PvdjZWd1HfSPjCNWc/p8Q3CT+Es9fWOR0UhAeYQZA=="],+"@ffmpeg/ffmpeg": ["@ffmpeg/[email protected]", "", { "dependencies": { "@ffmpeg/types": "^0.12.4" } }, "sha512-1C8Obr4GsN3xw+/1Ww6PFM84wSQAGsdoTuTWPOj2OizsRDLT4CXTaVjPhkw6ARyDus1B9X/L2LiXHqYYsGnRFw=="],"@ffmpeg/types": ["@ffmpeg/[email protected]", "", {}, "sha512-k9vJQNBGTxE5AhYDtOYR5rO5fKsspbg51gbcwtbkw2lCdoIILzklulcjJfIDwrtn7XhDeF2M+THwJ2FGrLeV6A=="],diff --git a/docs/FAQ.md b/docs/FAQ.mdindex e5d6ed1..6dd2816 100644--- a/docs/FAQ.md+++ b/docs/FAQ.md@@ -31,8 +31,6 @@ We use [Plausible](https://plausible.io/privacy-focused-web-analytics), a privacYes! If you would prefer VERT to not make any requests to external services (video conversion, analytics, among others), you can set the `PUB_DISABLE_ALL_EXTERNAL_REQUESTS` environment variable to `true` **during build time**.-The only external request VERT will make with this option is to `cdn.jsdelivr.net`, which is used to download FFmpeg's WebAssembly build.-### What libraries does VERT use?VERT uses FFmpeg for audio and video conversion, imagemagick for images and Pandoc for documents. A big thanks to them for maintaining such excellent libraries for so many years.diff --git a/package.json b/package.jsonindex 62af6b2..fcb1585 100644--- a/package.json+++ b/package.json@@ -44,6 +44,7 @@},"dependencies": {"@bjorn3/browser_wasi_shim": "^0.4.2",+ "@ffmpeg/core": "0.12.10","@ffmpeg/ffmpeg": "^0.12.15","@ffmpeg/util": "^0.12.2","@fontsource/azeret-mono": "^5.3.0",diff --git a/src/lib/converters/converter.svelte.ts b/src/lib/converters/converter.svelte.tsindex 2b2f390..5d7e2ff 100644--- a/src/lib/converters/converter.svelte.ts+++ b/src/lib/converters/converter.svelte.ts@@ -54,6 +54,13 @@ export class Converter {this.startTimeout();}+ /**+ * Downloads (if necessary) and initializes the converter.+ */+ public async init(): Promise<void> {+ this.status = "ready";+ }+/*** Get available settings for this converter.* Can be overridden per converter for format-specific settings.diff --git a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts b/src/lib/converters/ffmpeg/ffmpeg.svelte.tsindex 6da775d..0bf7555 100644--- a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts+++ b/src/lib/converters/ffmpeg/ffmpeg.svelte.ts@@ -10,6 +10,8 @@ import { ToastManager } from "#lib/util/toast.svelte";import { getCodecs, toArgs } from "./ffmpeg.codecs";import { buildImageSequenceCommand } from "./ffmpeg.animated";import { extractAlbumArt, avWithArt, avWithBg } from "./utils/ffmpeg";+import ffmpegCoreURL from "@ffmpeg/core?url";+import ffmpegWasmURL from "@ffmpeg/core/wasm?url";import type {SettingCategories,SettingDefinition,@@ -18,6 +20,9 @@ import type {} from "#lib/types/conversion-settings";import { videoFormats } from "../vertd/vertd.svelte";+const coreURL = new URL(ffmpegCoreURL, import.meta.url).href;+const wasmURL = new URL(ffmpegWasmURL, import.meta.url).href;+// TODO: differentiate in UI? (not native formats)export class FFmpegConverter extends Converter {private ffmpeg: FFmpeg = null!;@@ -76,40 +81,33 @@ export class FFmpegConverter extends Converter {constructor() {super();+ if (!browser) return;this.log = (msg) => log(["converters", this.name], msg);this.error = (msg) => error(["converters", this.name], msg);this.log(`created converter`);- if (!browser) return;+ }+ public async init(): Promise<void> {// this is just to cache the wasm and js for when we actually use it. we're not using this ffmpeg instance+ if (!browser) return;this.ffmpeg = new FFmpeg();- void (async () => {- try {- const baseURL =- "https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm";-- this.status = "downloading";-- await this.ffmpeg.load({- coreURL: `${baseURL}/ffmpeg-core.js`,- wasmURL: `${baseURL}/ffmpeg-core.wasm`,- });-- this.status = "ready";- this.ffmpeg.terminate();- this.log(- "preloaded ffmpeg assets and released the cache instance",- );- } catch (err) {- this.error(`Error loading ffmpeg: ${err}`);- this.status = "error";- this.ffmpeg.terminate();- ToastManager.add({- type: "error",- message: m["workers.errors.ffmpeg"](),- });- }- })();+ try {+ this.status = "downloading";++ await this.ffmpeg.load({ coreURL, wasmURL });++ this.status = "ready";+ this.ffmpeg.terminate();+ this.log("preloaded ffmpeg assets and released the cache instance");+ } catch (err) {+ this.error(`Error loading ffmpeg: ${err}`);+ this.status = "error";+ this.ffmpeg.terminate();+ ToastManager.add({+ type: "error",+ message: m["workers.errors.ffmpeg"](),+ });+ }}public async getAvailableSettings(): Promise<SettingCategories> {@@ -358,12 +356,7 @@ export class FFmpegConverter extends Converter {});}- const baseURL =- "https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm";- await ffmpeg.load({- coreURL: `${baseURL}/ffmpeg-core.js`,- wasmURL: `${baseURL}/ffmpeg-core.wasm`,- });+ await ffmpeg.load({ coreURL, wasmURL });return ffmpeg;}diff --git a/static/sw.js b/static/sw.jsindex 6b5b9d3..a5b57ae 100644--- a/static/sw.js+++ b/static/sw.js@@ -1,15 +1,14 @@-const CACHE_NAME = "vert-wasm-cache-v3"; // updated when workers update+const CACHE_NAME = "vert-wasm-cache-v4"; // updated when workers updateconst WASM_FILES = ["/pandoc.wasm", // from https://github.com/haskell-wasm/pandoc-wasm- "https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm/ffmpeg-core.js",- "https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm/ffmpeg-core.wasm",];const WASM_URL_PATTERNS = [/\/src\/lib\/workers\/.*\.js$/, // dev mode worker files/\/assets\/.*worker.*\.js$/, // prod worker files/magick.*\.wasm$/, // magick-wasm (unneeded?)+ /\/ffmpeg-core[^/]*\.(js|wasm)$/, // ffmpeg wasm core];function shouldCacheUrl(url) {diff --git a/vite.config.ts b/vite.config.tsindex d0abbdd..e61978b 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -60,7 +60,12 @@ export default defineConfig(({ command }) => {format: "es",},optimizeDeps: {- exclude: ["@ffmpeg/core-mt", "@ffmpeg/ffmpeg", "@ffmpeg/util"],+ exclude: [+ "@ffmpeg/core",+ "@ffmpeg/core-mt",+ "@ffmpeg/ffmpeg",+ "@ffmpeg/util",+ ],},build: {target: "esnext",