feat: restore Node.js support via worker_threads#936
Open
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
Open
feat: restore Node.js support via worker_threads#936JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
Conversation
Replace the error-throwing empty.mts stub with a full Node.js FFmpeg implementation that mirrors the browser API using worker_threads. New files: - node-classes.ts: FFmpeg class using worker_threads.Worker - node-worker.ts: Worker script using parentPort message passing - util/node.ts: Node.js fetchFile (fs.readFile + fetch for URLs) - tests/node-ffmpeg.test.mjs: Integration test for Node.js The public API is identical to the browser version — existing code works without changes, just swap the import. The worker_threads approach keeps transcoding off the main thread, preserving Node.js async behavior. Resolves: ffmpegwasm#897 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for ffmpegwasm canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #897 — restores Node.js support that was removed in v0.12.0.
With both
fluent-ffmpeg(archived May 2025) andffmpeg-kit(archived June 2025) now dead, there is no maintained way to use FFmpeg from Node.js without native binaries. This PR brings ffmpeg.wasm back to Node.js with a zero-change API — existing browser code works in Node.js by swapping the import.What's included
node-classes.ts—FFmpegclass usingworker_threads.Workerinstead of Web Workers. Same public API as the browser version.node-worker.ts— Worker script usingparentPortmessage passing. Mirrors the browserworker.tsexactly.@ffmpeg/util/node— Node.jsfetchFile()supporting local file paths (fs.readFile), URLs (fetch), Buffers, and base64 data URIs.empty.mts— Now re-exports the real Node.js implementation instead of throwing.tests/node-ffmpeg.test.mjsDesign decisions
worker_threadsover direct execution — Keeps transcoding off the main thread, preserving Node.js async behavior. The message-passing protocol is identical to Web Workers.worker_threads,fs,url).package.jsonexports field routes Node.js to the new implementation via the existing"node"condition. Browser builds are unchanged.Usage
Test plan
node-classes.tscorrectly spawnsnode-worker.tsviaworker_threadsfetchFilewith local paths, URLs, base64, and Bufferstests/node-ffmpeg.test.mjswith@ffmpeg/coreinstalledterminate()cleanly shuts down the worker thread🤖 Generated with Claude Code