webcodecs-encoder
Advanced tools
| diff --git a/node_modules/@types/dom-webcodecs/mediastream-processor.d.ts b/node_modules/@types/dom-webcodecs/mediastream-processor.d.ts | ||
| new file mode 100644 | ||
| index 0000000..caa332d | ||
| --- /dev/null | ||
| +++ b/node_modules/@types/dom-webcodecs/mediastream-processor.d.ts | ||
| @@ -0,0 +1,12 @@ | ||
| +interface MediaStreamTrackProcessorInit { | ||
| + track: MediaStreamTrack; | ||
| +} | ||
| + | ||
| +declare class MediaStreamTrackProcessor { | ||
| + constructor(init: MediaStreamTrackProcessorInit); | ||
| + readonly readable: ReadableStream; | ||
| +} | ||
| + | ||
| +interface Window { | ||
| + MediaStreamTrackProcessor: typeof MediaStreamTrackProcessor; | ||
| +} | ||
| \ No newline at end of file | ||
| diff --git a/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts b/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts | ||
| index b614234..2622d23 100644 | ||
| --- a/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts | ||
| +++ b/node_modules/@types/dom-webcodecs/webcodecs.generated.d.ts | ||
| @@ -462,10 +462,24 @@ interface WebCodecsErrorCallback { | ||
| // type BitrateMode = "constant" | "variable"; | ||
| // type ImageBufferSource = ArrayBuffer | ArrayBufferView | ReadableStream; | ||
| // type AlphaOption = "discard" | "keep"; | ||
| -// type AudioSampleFormat = "f32" | "f32-planar" | "s16" | "s16-planar" | "s32" | "s32-planar" | "u8" | "u8-planar"; | ||
| +type AudioSampleFormat = "f32" | "f32-planar" | "s16" | "s16-planar" | "s32" | "s32-planar" | "u8" | "u8-planar"; | ||
| // type AvcBitstreamFormat = "annexb" | "avc"; | ||
| // type CodecState = "closed" | "configured" | "unconfigured"; | ||
| // type EncodedAudioChunkType = "delta" | "key"; | ||
| + | ||
| +interface MediaStreamTrackProcessorInit { | ||
| + track: MediaStreamTrack; | ||
| +} | ||
| + | ||
| +declare class MediaStreamTrackProcessor { | ||
| + constructor(init: MediaStreamTrackProcessorInit); | ||
| + readonly readable: ReadableStream; | ||
| +} | ||
| + | ||
| +interface Window { | ||
| + MediaStreamTrackProcessor: typeof MediaStreamTrackProcessor; | ||
| +} | ||
| + | ||
| // type EncodedVideoChunkType = "delta" | "key"; | ||
| type HardwarePreference = "no-preference" | "prefer-hardware" | "prefer-software"; | ||
| // type LatencyMode = "quality" | "realtime"; |
| #!/usr/bin/env node | ||
| import { execSync } from 'child_process'; | ||
| import { createRequire } from 'module'; | ||
| const require = createRequire(import.meta.url); | ||
| try { | ||
| require.resolve('patch-package'); | ||
| } catch (err) { | ||
| console.log('patch-package not installed, skipping patches.'); | ||
| process.exit(0); | ||
| } | ||
| try { | ||
| execSync('patch-package', { stdio: 'inherit' }); | ||
| } catch (err) { | ||
| console.error('Failed to apply patches:', err); | ||
| } |
+5
-4
| { | ||
| "name": "webcodecs-encoder", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "description": "A TypeScript library to encode video (H.264/AVC, VP9, VP8) and audio (AAC, Opus) using the WebCodecs API and mux them into MP4 or WebM containers with real-time streaming support.", | ||
@@ -30,3 +30,3 @@ "homepage": "https://github.com/romot-co/webcodecs-encoder", | ||
| "prepare": "npm run build", | ||
| "postinstall": "node scripts/postinstall.js && patch-package", | ||
| "postinstall": "node scripts/postinstall.js && node scripts/apply-patches.js", | ||
| "test": "vitest run --coverage", | ||
@@ -61,3 +61,4 @@ "test:int": "npm run build && DEBUG=pw:api RUNNING_INTEGRATION_TESTS=true vitest run test/integration/encode-browser.test.ts", | ||
| "mp4-muxer": "^2.0.2", | ||
| "webm-muxer": "^1.2.0" | ||
| "webm-muxer": "^1.2.0", | ||
| "patch-package": "^8.0.0" | ||
| }, | ||
@@ -73,3 +74,2 @@ "devDependencies": { | ||
| "jsdom": "^26.1.0", | ||
| "patch-package": "^8.0.0", | ||
| "playwright": "^1.52.0", | ||
@@ -84,2 +84,3 @@ "prettier": "^3.2.5", | ||
| "scripts", | ||
| "patches", | ||
| "README.md", | ||
@@ -86,0 +87,0 @@ "LICENSE", |
+31
-0
@@ -44,2 +44,4 @@ # WebCodecs MP4/WebM Encoder (MP4 & WebM Muxers) | ||
| The same `postinstall` script also tries to copy the Web Worker and AudioWorklet files into a `public/` directory. If your environment disables lifecycle scripts (for example using `--ignore-scripts` or Yarn Plug'n'Play), this step won't run. In that case you can copy `node_modules/webcodecs-encoder/dist/worker.js` and `node_modules/webcodecs-encoder/dist/audio-worklet-processor.js` to your public folder manually or run `node scripts/postinstall.js` yourself. Set the environment variable `WEB_CODECS_ENCODER_SKIP_COPY=1` before installing to disable the automatic copy. | ||
| ## ⨠Zero-Config Setup (Automatic) | ||
@@ -68,2 +70,16 @@ | ||
| ```cmd | ||
| # Windows equivalent | ||
| copy node_modules\webcodecs-encoder\dist\worker.js public\webcodecs-worker.js | ||
| ``` | ||
| ```bash | ||
| # Cross-platform Node script (requires fs-extra) | ||
| node -e "require('fs-extra').copySync('node_modules/webcodecs-encoder/dist/worker.js', 'public/webcodecs-worker.js')" | ||
| ``` | ||
| ### Disable Automatic Worker Copy | ||
| Set `WEB_CODECS_ENCODER_SKIP_COPY=1` before installation if you want to skip the copy performed by the `postinstall` script. | ||
| ### Or Specify Custom Worker URL | ||
@@ -89,2 +105,17 @@ | ||
| ## Setup for Vite/PWA projects | ||
| If you're bundling your application with tools like **Vite**, **Webpack**, or **Rollup**, you can let the bundler resolve the worker file directly instead of copying it manually. Construct the worker URL using `import.meta.url`: | ||
| ```ts | ||
| const workerUrl = new URL( | ||
| './node_modules/webcodecs-encoder/dist/worker.js', | ||
| import.meta.url | ||
| ).toString(); | ||
| await encoder.initialize({ workerScriptUrl: workerUrl }); | ||
| ``` | ||
| This allows your bundler to include the worker script in the build and serve it correctly without any manual steps. | ||
| ## Basic Usage | ||
@@ -91,0 +122,0 @@ |
@@ -55,2 +55,6 @@ #!/usr/bin/env node | ||
| function installWorker() { | ||
| if (process.env.WEB_CODECS_ENCODER_SKIP_COPY) { | ||
| console.log('WEB_CODECS_ENCODER_SKIP_COPY is set, skipping worker copy.'); | ||
| return; | ||
| } | ||
| // Check if we're being run from within node_modules via package path | ||
@@ -57,0 +61,0 @@ const cwd = process.cwd(); |
Install scripts
Supply chain riskInstall scripts are run when the package is installed or built. Malicious packages often use scripts that run automatically to execute payloads or fetch additional code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed or built. Malicious packages often use scripts that run automatically to execute payloads or fetch additional code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1097411
0.38%13
-7.14%44
4.76%7406
0.26%1016
3.15%3
50%16
14.29%10
11.11%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added