webcodecs-node 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +656 -0
- package/README.md +607 -0
- package/dist/AudioData.d.ts +6 -0
- package/dist/AudioData.d.ts.map +1 -0
- package/dist/AudioData.js +6 -0
- package/dist/AudioData.js.map +1 -0
- package/dist/AudioDecoder.d.ts +6 -0
- package/dist/AudioDecoder.d.ts.map +1 -0
- package/dist/AudioDecoder.js +6 -0
- package/dist/AudioDecoder.js.map +1 -0
- package/dist/AudioEncoder.d.ts +6 -0
- package/dist/AudioEncoder.d.ts.map +1 -0
- package/dist/AudioEncoder.js +6 -0
- package/dist/AudioEncoder.js.map +1 -0
- package/dist/EncodedAudioChunk.d.ts +6 -0
- package/dist/EncodedAudioChunk.d.ts.map +1 -0
- package/dist/EncodedAudioChunk.js +6 -0
- package/dist/EncodedAudioChunk.js.map +1 -0
- package/dist/EncodedVideoChunk.d.ts +6 -0
- package/dist/EncodedVideoChunk.d.ts.map +1 -0
- package/dist/EncodedVideoChunk.js +6 -0
- package/dist/EncodedVideoChunk.js.map +1 -0
- package/dist/FFmpegProcess.d.ts +6 -0
- package/dist/FFmpegProcess.d.ts.map +1 -0
- package/dist/FFmpegProcess.js +6 -0
- package/dist/FFmpegProcess.js.map +1 -0
- package/dist/HardwareAcceleration.d.ts +6 -0
- package/dist/HardwareAcceleration.d.ts.map +1 -0
- package/dist/HardwareAcceleration.js +6 -0
- package/dist/HardwareAcceleration.js.map +1 -0
- package/dist/ImageDecoder.d.ts +6 -0
- package/dist/ImageDecoder.d.ts.map +1 -0
- package/dist/ImageDecoder.js +6 -0
- package/dist/ImageDecoder.js.map +1 -0
- package/dist/Logger.d.ts +6 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js +6 -0
- package/dist/Logger.js.map +1 -0
- package/dist/MediaCapabilities.d.ts +9 -0
- package/dist/MediaCapabilities.d.ts.map +1 -0
- package/dist/MediaCapabilities.js +8 -0
- package/dist/MediaCapabilities.js.map +1 -0
- package/dist/VideoDecoder.d.ts +6 -0
- package/dist/VideoDecoder.d.ts.map +1 -0
- package/dist/VideoDecoder.js +6 -0
- package/dist/VideoDecoder.js.map +1 -0
- package/dist/VideoEncoder.d.ts +6 -0
- package/dist/VideoEncoder.d.ts.map +1 -0
- package/dist/VideoEncoder.js +6 -0
- package/dist/VideoEncoder.js.map +1 -0
- package/dist/VideoFrame.d.ts +10 -0
- package/dist/VideoFrame.d.ts.map +1 -0
- package/dist/VideoFrame.js +9 -0
- package/dist/VideoFrame.js.map +1 -0
- package/dist/__tests__/AudioData.test.d.ts +5 -0
- package/dist/__tests__/AudioData.test.d.ts.map +1 -0
- package/dist/__tests__/AudioData.test.js +179 -0
- package/dist/__tests__/AudioData.test.js.map +1 -0
- package/dist/__tests__/AudioDecoder.test.d.ts +5 -0
- package/dist/__tests__/AudioDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/AudioDecoder.test.js +733 -0
- package/dist/__tests__/AudioDecoder.test.js.map +1 -0
- package/dist/__tests__/AudioEncoder.test.d.ts +5 -0
- package/dist/__tests__/AudioEncoder.test.d.ts.map +1 -0
- package/dist/__tests__/AudioEncoder.test.js +247 -0
- package/dist/__tests__/AudioEncoder.test.js.map +1 -0
- package/dist/__tests__/EncodedChunks.test.d.ts +5 -0
- package/dist/__tests__/EncodedChunks.test.d.ts.map +1 -0
- package/dist/__tests__/EncodedChunks.test.js +99 -0
- package/dist/__tests__/EncodedChunks.test.js.map +1 -0
- package/dist/__tests__/HardwareAcceleration.test.d.ts +5 -0
- package/dist/__tests__/HardwareAcceleration.test.d.ts.map +1 -0
- package/dist/__tests__/HardwareAcceleration.test.js +84 -0
- package/dist/__tests__/HardwareAcceleration.test.js.map +1 -0
- package/dist/__tests__/ImageDecoder.test.d.ts +5 -0
- package/dist/__tests__/ImageDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/ImageDecoder.test.js +587 -0
- package/dist/__tests__/ImageDecoder.test.js.map +1 -0
- package/dist/__tests__/MediaCapabilities.test.d.ts +5 -0
- package/dist/__tests__/MediaCapabilities.test.d.ts.map +1 -0
- package/dist/__tests__/MediaCapabilities.test.js +346 -0
- package/dist/__tests__/MediaCapabilities.test.js.map +1 -0
- package/dist/__tests__/VideoDecoder.test.d.ts +5 -0
- package/dist/__tests__/VideoDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/VideoDecoder.test.js +675 -0
- package/dist/__tests__/VideoDecoder.test.js.map +1 -0
- package/dist/__tests__/VideoEncoder.test.d.ts +5 -0
- package/dist/__tests__/VideoEncoder.test.d.ts.map +1 -0
- package/dist/__tests__/VideoEncoder.test.js +468 -0
- package/dist/__tests__/VideoEncoder.test.js.map +1 -0
- package/dist/__tests__/VideoFrame.test.d.ts +5 -0
- package/dist/__tests__/VideoFrame.test.d.ts.map +1 -0
- package/dist/__tests__/VideoFrame.test.js +243 -0
- package/dist/__tests__/VideoFrame.test.js.map +1 -0
- package/dist/__tests__/aac-utils.test.d.ts +2 -0
- package/dist/__tests__/aac-utils.test.d.ts.map +1 -0
- package/dist/__tests__/aac-utils.test.js +37 -0
- package/dist/__tests__/aac-utils.test.js.map +1 -0
- package/dist/__tests__/avc-utils.test.d.ts +2 -0
- package/dist/__tests__/avc-utils.test.d.ts.map +1 -0
- package/dist/__tests__/avc-utils.test.js +63 -0
- package/dist/__tests__/avc-utils.test.js.map +1 -0
- package/dist/__tests__/hevc-utils.test.d.ts +2 -0
- package/dist/__tests__/hevc-utils.test.d.ts.map +1 -0
- package/dist/__tests__/hevc-utils.test.js +78 -0
- package/dist/__tests__/hevc-utils.test.js.map +1 -0
- package/dist/capabilities/MediaCapabilities.d.ts +78 -0
- package/dist/capabilities/MediaCapabilities.d.ts.map +1 -0
- package/dist/capabilities/MediaCapabilities.js +276 -0
- package/dist/capabilities/MediaCapabilities.js.map +1 -0
- package/dist/capabilities/codecs.d.ts +72 -0
- package/dist/capabilities/codecs.d.ts.map +1 -0
- package/dist/capabilities/codecs.js +153 -0
- package/dist/capabilities/codecs.js.map +1 -0
- package/dist/capabilities/index.d.ts +7 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +8 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/types.d.ts +77 -0
- package/dist/capabilities/types.d.ts.map +1 -0
- package/dist/capabilities/types.js +5 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/core/AudioData.d.ts +36 -0
- package/dist/core/AudioData.d.ts.map +1 -0
- package/dist/core/AudioData.js +229 -0
- package/dist/core/AudioData.js.map +1 -0
- package/dist/core/EncodedAudioChunk.d.ts +26 -0
- package/dist/core/EncodedAudioChunk.d.ts.map +1 -0
- package/dist/core/EncodedAudioChunk.js +58 -0
- package/dist/core/EncodedAudioChunk.js.map +1 -0
- package/dist/core/EncodedVideoChunk.d.ts +23 -0
- package/dist/core/EncodedVideoChunk.d.ts.map +1 -0
- package/dist/core/EncodedVideoChunk.js +55 -0
- package/dist/core/EncodedVideoChunk.js.map +1 -0
- package/dist/core/VideoFrame.d.ts +61 -0
- package/dist/core/VideoFrame.d.ts.map +1 -0
- package/dist/core/VideoFrame.js +385 -0
- package/dist/core/VideoFrame.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/debug-h264.d.ts +5 -0
- package/dist/debug-h264.d.ts.map +1 -0
- package/dist/debug-h264.js +103 -0
- package/dist/debug-h264.js.map +1 -0
- package/dist/decoders/AudioDecoder.d.ts +57 -0
- package/dist/decoders/AudioDecoder.d.ts.map +1 -0
- package/dist/decoders/AudioDecoder.js +333 -0
- package/dist/decoders/AudioDecoder.js.map +1 -0
- package/dist/decoders/ImageDecoder.d.ts +111 -0
- package/dist/decoders/ImageDecoder.d.ts.map +1 -0
- package/dist/decoders/ImageDecoder.js +686 -0
- package/dist/decoders/ImageDecoder.js.map +1 -0
- package/dist/decoders/VideoDecoder.d.ts +70 -0
- package/dist/decoders/VideoDecoder.d.ts.map +1 -0
- package/dist/decoders/VideoDecoder.js +410 -0
- package/dist/decoders/VideoDecoder.js.map +1 -0
- package/dist/decoders/index.d.ts +8 -0
- package/dist/decoders/index.d.ts.map +1 -0
- package/dist/decoders/index.js +7 -0
- package/dist/decoders/index.js.map +1 -0
- package/dist/demos/demo-audio-opus.d.ts +5 -0
- package/dist/demos/demo-audio-opus.d.ts.map +1 -0
- package/dist/demos/demo-audio-opus.js +107 -0
- package/dist/demos/demo-audio-opus.js.map +1 -0
- package/dist/demos/demo-audio.d.ts +10 -0
- package/dist/demos/demo-audio.d.ts.map +1 -0
- package/dist/demos/demo-audio.js +135 -0
- package/dist/demos/demo-audio.js.map +1 -0
- package/dist/demos/demo-conversion.d.ts +13 -0
- package/dist/demos/demo-conversion.d.ts.map +1 -0
- package/dist/demos/demo-conversion.js +301 -0
- package/dist/demos/demo-conversion.js.map +1 -0
- package/dist/demos/demo-h264.d.ts +7 -0
- package/dist/demos/demo-h264.d.ts.map +1 -0
- package/dist/demos/demo-h264.js +134 -0
- package/dist/demos/demo-h264.js.map +1 -0
- package/dist/demos/demo-hwaccel-conversion.d.ts +8 -0
- package/dist/demos/demo-hwaccel-conversion.d.ts.map +1 -0
- package/dist/demos/demo-hwaccel-conversion.js +161 -0
- package/dist/demos/demo-hwaccel-conversion.js.map +1 -0
- package/dist/demos/demo-hwaccel.d.ts +7 -0
- package/dist/demos/demo-hwaccel.d.ts.map +1 -0
- package/dist/demos/demo-hwaccel.js +51 -0
- package/dist/demos/demo-hwaccel.js.map +1 -0
- package/dist/demos/demo-image.d.ts +12 -0
- package/dist/demos/demo-image.d.ts.map +1 -0
- package/dist/demos/demo-image.js +178 -0
- package/dist/demos/demo-image.js.map +1 -0
- package/dist/demos/demo-mediabunny.d.ts +7 -0
- package/dist/demos/demo-mediabunny.d.ts.map +1 -0
- package/dist/demos/demo-mediabunny.js +78 -0
- package/dist/demos/demo-mediabunny.js.map +1 -0
- package/dist/demos/demo-pipeline.d.ts +8 -0
- package/dist/demos/demo-pipeline.d.ts.map +1 -0
- package/dist/demos/demo-pipeline.js +83 -0
- package/dist/demos/demo-pipeline.js.map +1 -0
- package/dist/demos/demo-samples.d.ts +9 -0
- package/dist/demos/demo-samples.d.ts.map +1 -0
- package/dist/demos/demo-samples.js +413 -0
- package/dist/demos/demo-samples.js.map +1 -0
- package/dist/demos/demo-streaming.d.ts +8 -0
- package/dist/demos/demo-streaming.d.ts.map +1 -0
- package/dist/demos/demo-streaming.js +299 -0
- package/dist/demos/demo-streaming.js.map +1 -0
- package/dist/demos/demo-webcodecs.d.ts +8 -0
- package/dist/demos/demo-webcodecs.d.ts.map +1 -0
- package/dist/demos/demo-webcodecs.js +316 -0
- package/dist/demos/demo-webcodecs.js.map +1 -0
- package/dist/demos/demo.d.ts +10 -0
- package/dist/demos/demo.d.ts.map +1 -0
- package/dist/demos/demo.js +123 -0
- package/dist/demos/demo.js.map +1 -0
- package/dist/encoders/AudioEncoder.d.ts +69 -0
- package/dist/encoders/AudioEncoder.d.ts.map +1 -0
- package/dist/encoders/AudioEncoder.js +425 -0
- package/dist/encoders/AudioEncoder.js.map +1 -0
- package/dist/encoders/VideoEncoder.d.ts +80 -0
- package/dist/encoders/VideoEncoder.d.ts.map +1 -0
- package/dist/encoders/VideoEncoder.js +386 -0
- package/dist/encoders/VideoEncoder.js.map +1 -0
- package/dist/encoders/codecs/av1.d.ts +31 -0
- package/dist/encoders/codecs/av1.d.ts.map +1 -0
- package/dist/encoders/codecs/av1.js +66 -0
- package/dist/encoders/codecs/av1.js.map +1 -0
- package/dist/encoders/codecs/h264.d.ts +28 -0
- package/dist/encoders/codecs/h264.d.ts.map +1 -0
- package/dist/encoders/codecs/h264.js +95 -0
- package/dist/encoders/codecs/h264.js.map +1 -0
- package/dist/encoders/codecs/hevc.d.ts +28 -0
- package/dist/encoders/codecs/hevc.d.ts.map +1 -0
- package/dist/encoders/codecs/hevc.js +73 -0
- package/dist/encoders/codecs/hevc.js.map +1 -0
- package/dist/encoders/codecs/index.d.ts +19 -0
- package/dist/encoders/codecs/index.d.ts.map +1 -0
- package/dist/encoders/codecs/index.js +60 -0
- package/dist/encoders/codecs/index.js.map +1 -0
- package/dist/encoders/codecs/vp9.d.ts +29 -0
- package/dist/encoders/codecs/vp9.d.ts.map +1 -0
- package/dist/encoders/codecs/vp9.js +58 -0
- package/dist/encoders/codecs/vp9.js.map +1 -0
- package/dist/encoders/index.d.ts +8 -0
- package/dist/encoders/index.d.ts.map +1 -0
- package/dist/encoders/index.js +8 -0
- package/dist/encoders/index.js.map +1 -0
- package/dist/ffmpeg/FFmpegProcess.d.ts +111 -0
- package/dist/ffmpeg/FFmpegProcess.d.ts.map +1 -0
- package/dist/ffmpeg/FFmpegProcess.js +543 -0
- package/dist/ffmpeg/FFmpegProcess.js.map +1 -0
- package/dist/ffmpeg/audio-codecs.d.ts +59 -0
- package/dist/ffmpeg/audio-codecs.d.ts.map +1 -0
- package/dist/ffmpeg/audio-codecs.js +99 -0
- package/dist/ffmpeg/audio-codecs.js.map +1 -0
- package/dist/ffmpeg/formats.d.ts +42 -0
- package/dist/ffmpeg/formats.d.ts.map +1 -0
- package/dist/ffmpeg/formats.js +147 -0
- package/dist/ffmpeg/formats.js.map +1 -0
- package/dist/ffmpeg/index.d.ts +9 -0
- package/dist/ffmpeg/index.d.ts.map +1 -0
- package/dist/ffmpeg/index.js +13 -0
- package/dist/ffmpeg/index.js.map +1 -0
- package/dist/ffmpeg/parsers/annexb.d.ts +88 -0
- package/dist/ffmpeg/parsers/annexb.d.ts.map +1 -0
- package/dist/ffmpeg/parsers/annexb.js +201 -0
- package/dist/ffmpeg/parsers/annexb.js.map +1 -0
- package/dist/ffmpeg/parsers/index.d.ts +6 -0
- package/dist/ffmpeg/parsers/index.d.ts.map +1 -0
- package/dist/ffmpeg/parsers/index.js +8 -0
- package/dist/ffmpeg/parsers/index.js.map +1 -0
- package/dist/ffmpeg/parsers/ivf.d.ts +54 -0
- package/dist/ffmpeg/parsers/ivf.d.ts.map +1 -0
- package/dist/ffmpeg/parsers/ivf.js +109 -0
- package/dist/ffmpeg/parsers/ivf.js.map +1 -0
- package/dist/ffmpeg/types.d.ts +85 -0
- package/dist/ffmpeg/types.d.ts.map +1 -0
- package/dist/ffmpeg/types.js +8 -0
- package/dist/ffmpeg/types.js.map +1 -0
- package/dist/formats/audio-formats.d.ts +61 -0
- package/dist/formats/audio-formats.d.ts.map +1 -0
- package/dist/formats/audio-formats.js +113 -0
- package/dist/formats/audio-formats.js.map +1 -0
- package/dist/formats/color-space.d.ts +35 -0
- package/dist/formats/color-space.d.ts.map +1 -0
- package/dist/formats/color-space.js +62 -0
- package/dist/formats/color-space.js.map +1 -0
- package/dist/formats/conversions/frame-converter.d.ts +42 -0
- package/dist/formats/conversions/frame-converter.d.ts.map +1 -0
- package/dist/formats/conversions/frame-converter.js +244 -0
- package/dist/formats/conversions/frame-converter.js.map +1 -0
- package/dist/formats/conversions/index.d.ts +8 -0
- package/dist/formats/conversions/index.d.ts.map +1 -0
- package/dist/formats/conversions/index.js +10 -0
- package/dist/formats/conversions/index.js.map +1 -0
- package/dist/formats/index.d.ts +9 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +14 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/parsers/index.d.ts +5 -0
- package/dist/formats/parsers/index.d.ts.map +1 -0
- package/dist/formats/parsers/index.js +5 -0
- package/dist/formats/parsers/index.js.map +1 -0
- package/dist/formats/parsers/webp.d.ts +16 -0
- package/dist/formats/parsers/webp.d.ts.map +1 -0
- package/dist/formats/parsers/webp.js +116 -0
- package/dist/formats/parsers/webp.js.map +1 -0
- package/dist/formats/pixel-formats.d.ts +41 -0
- package/dist/formats/pixel-formats.d.ts.map +1 -0
- package/dist/formats/pixel-formats.js +113 -0
- package/dist/formats/pixel-formats.js.map +1 -0
- package/dist/hardware/HardwareAcceleration.d.ts +6 -0
- package/dist/hardware/HardwareAcceleration.d.ts.map +1 -0
- package/dist/hardware/HardwareAcceleration.js +6 -0
- package/dist/hardware/HardwareAcceleration.js.map +1 -0
- package/dist/hardware/decoder-args.d.ts +25 -0
- package/dist/hardware/decoder-args.d.ts.map +1 -0
- package/dist/hardware/decoder-args.js +84 -0
- package/dist/hardware/decoder-args.js.map +1 -0
- package/dist/hardware/detection.d.ts +39 -0
- package/dist/hardware/detection.d.ts.map +1 -0
- package/dist/hardware/detection.js +178 -0
- package/dist/hardware/detection.js.map +1 -0
- package/dist/hardware/encoder-args.d.ts +38 -0
- package/dist/hardware/encoder-args.d.ts.map +1 -0
- package/dist/hardware/encoder-args.js +177 -0
- package/dist/hardware/encoder-args.js.map +1 -0
- package/dist/hardware/index.d.ts +12 -0
- package/dist/hardware/index.d.ts.map +1 -0
- package/dist/hardware/index.js +14 -0
- package/dist/hardware/index.js.map +1 -0
- package/dist/hardware/types.d.ts +29 -0
- package/dist/hardware/types.d.ts.map +1 -0
- package/dist/hardware/types.js +58 -0
- package/dist/hardware/types.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts +37 -0
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts.map +1 -0
- package/dist/mediabunny/FFmpegAudioDecoder.js +254 -0
- package/dist/mediabunny/FFmpegAudioDecoder.js.map +1 -0
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts +77 -0
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts.map +1 -0
- package/dist/mediabunny/FFmpegAudioEncoder.js +484 -0
- package/dist/mediabunny/FFmpegAudioEncoder.js.map +1 -0
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts +58 -0
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts.map +1 -0
- package/dist/mediabunny/FFmpegVideoDecoder.js +366 -0
- package/dist/mediabunny/FFmpegVideoDecoder.js.map +1 -0
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts +77 -0
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts.map +1 -0
- package/dist/mediabunny/FFmpegVideoEncoder.js +551 -0
- package/dist/mediabunny/FFmpegVideoEncoder.js.map +1 -0
- package/dist/mediabunny/index.d.ts +21 -0
- package/dist/mediabunny/index.d.ts.map +1 -0
- package/dist/mediabunny/index.js +33 -0
- package/dist/mediabunny/index.js.map +1 -0
- package/dist/polyfill.d.ts +27 -0
- package/dist/polyfill.d.ts.map +1 -0
- package/dist/polyfill.js +78 -0
- package/dist/polyfill.js.map +1 -0
- package/dist/polyfills/CanvasRenderingContext2DPolyfill.d.ts +72 -0
- package/dist/polyfills/CanvasRenderingContext2DPolyfill.d.ts.map +1 -0
- package/dist/polyfills/CanvasRenderingContext2DPolyfill.js +293 -0
- package/dist/polyfills/CanvasRenderingContext2DPolyfill.js.map +1 -0
- package/dist/polyfills/ImageDataPolyfill.d.ts +12 -0
- package/dist/polyfills/ImageDataPolyfill.d.ts.map +1 -0
- package/dist/polyfills/ImageDataPolyfill.js +22 -0
- package/dist/polyfills/ImageDataPolyfill.js.map +1 -0
- package/dist/polyfills/OffscreenCanvas.d.ts +15 -0
- package/dist/polyfills/OffscreenCanvas.d.ts.map +1 -0
- package/dist/polyfills/OffscreenCanvas.js +35 -0
- package/dist/polyfills/OffscreenCanvas.js.map +1 -0
- package/dist/polyfills/OffscreenCanvasPolyfill.d.ts +16 -0
- package/dist/polyfills/OffscreenCanvasPolyfill.d.ts.map +1 -0
- package/dist/polyfills/OffscreenCanvasPolyfill.js +46 -0
- package/dist/polyfills/OffscreenCanvasPolyfill.js.map +1 -0
- package/dist/polyfills/VideoFramePolyfill.d.ts +44 -0
- package/dist/polyfills/VideoFramePolyfill.d.ts.map +1 -0
- package/dist/polyfills/VideoFramePolyfill.js +98 -0
- package/dist/polyfills/VideoFramePolyfill.js.map +1 -0
- package/dist/tools/generate-capabilities-profile.d.ts +2 -0
- package/dist/tools/generate-capabilities-profile.d.ts.map +1 -0
- package/dist/tools/generate-capabilities-profile.js +63 -0
- package/dist/tools/generate-capabilities-profile.js.map +1 -0
- package/dist/types/audio.d.ts +26 -0
- package/dist/types/audio.d.ts.map +1 -0
- package/dist/types/audio.js +5 -0
- package/dist/types/audio.js.map +1 -0
- package/dist/types/common.d.ts +68 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +70 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/geometry.d.ts +35 -0
- package/dist/types/geometry.d.ts.map +1 -0
- package/dist/types/geometry.js +34 -0
- package/dist/types/geometry.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/video.d.ts +43 -0
- package/dist/types/video.d.ts.map +1 -0
- package/dist/types/video.js +5 -0
- package/dist/types/video.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/aac.d.ts +26 -0
- package/dist/utils/aac.d.ts.map +1 -0
- package/dist/utils/aac.js +129 -0
- package/dist/utils/aac.js.map +1 -0
- package/dist/utils/avc.d.ts +39 -0
- package/dist/utils/avc.d.ts.map +1 -0
- package/dist/utils/avc.js +225 -0
- package/dist/utils/avc.js.map +1 -0
- package/dist/utils/buffer.d.ts +25 -0
- package/dist/utils/buffer.d.ts.map +1 -0
- package/dist/utils/buffer.js +73 -0
- package/dist/utils/buffer.js.map +1 -0
- package/dist/utils/hevc.d.ts +27 -0
- package/dist/utils/hevc.d.ts.map +1 -0
- package/dist/utils/hevc.js +239 -0
- package/dist/utils/hevc.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +55 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +110 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/type-guards.d.ts +50 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +49 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/dist/utils/validation.d.ts +32 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +66 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/api.md +506 -0
- package/docs/codecs.md +382 -0
- package/docs/configuration.md +442 -0
- package/examples/README.md +100 -0
- package/examples/audio-encoding.ts +85 -0
- package/examples/hardware-decoding.ts +245 -0
- package/examples/hardware-encoding.ts +231 -0
- package/examples/image-decoding.ts +145 -0
- package/examples/streaming.ts +151 -0
- package/examples/transparent-video.ts +162 -0
- package/examples/video-decoding.ts +107 -0
- package/examples/video-encoding.ts +93 -0
- package/package.json +105 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
This guide covers all configuration options for video and audio encoding in webcodecs-node.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Bitrate Mode](#bitrate-mode)
|
|
8
|
+
- [Alpha Channel Handling](#alpha-channel-handling)
|
|
9
|
+
- [Latency Mode](#latency-mode)
|
|
10
|
+
- [Hardware Acceleration](#hardware-acceleration)
|
|
11
|
+
- [Pixel Formats](#pixel-formats)
|
|
12
|
+
- [Audio Sample Formats](#audio-sample-formats)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Bitrate Mode
|
|
17
|
+
|
|
18
|
+
The `bitrateMode` option controls how the encoder manages bitrate during encoding.
|
|
19
|
+
|
|
20
|
+
### Available Modes
|
|
21
|
+
|
|
22
|
+
| Mode | Description | Use Case |
|
|
23
|
+
|------|-------------|----------|
|
|
24
|
+
| `'variable'` | Variable bitrate (VBR) - default | General purpose, best quality/size ratio |
|
|
25
|
+
| `'constant'` | Constant bitrate (CBR) | Streaming, predictable file size |
|
|
26
|
+
| `'quantizer'` | Fixed quality (CRF/CQ) | Archival, consistent quality |
|
|
27
|
+
|
|
28
|
+
### Variable Bitrate (VBR)
|
|
29
|
+
|
|
30
|
+
Default mode. Allocates more bits to complex scenes and fewer to simple ones.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
encoder.configure({
|
|
34
|
+
codec: 'avc1.42001E',
|
|
35
|
+
width: 1920,
|
|
36
|
+
height: 1080,
|
|
37
|
+
bitrate: 5_000_000, // Target average bitrate
|
|
38
|
+
bitrateMode: 'variable',
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Pros:**
|
|
43
|
+
- Best quality for a given file size
|
|
44
|
+
- Efficient encoding
|
|
45
|
+
|
|
46
|
+
**Cons:**
|
|
47
|
+
- Unpredictable file size
|
|
48
|
+
- May cause buffering issues in streaming
|
|
49
|
+
|
|
50
|
+
### Constant Bitrate (CBR)
|
|
51
|
+
|
|
52
|
+
Maintains a steady bitrate throughout the video.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
encoder.configure({
|
|
56
|
+
codec: 'avc1.42001E',
|
|
57
|
+
width: 1920,
|
|
58
|
+
height: 1080,
|
|
59
|
+
bitrate: 5_000_000, // Fixed bitrate
|
|
60
|
+
bitrateMode: 'constant',
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Pros:**
|
|
65
|
+
- Predictable file size
|
|
66
|
+
- Smooth streaming
|
|
67
|
+
- Required for some broadcast standards
|
|
68
|
+
|
|
69
|
+
**Cons:**
|
|
70
|
+
- May waste bits on simple scenes
|
|
71
|
+
- May degrade quality on complex scenes
|
|
72
|
+
|
|
73
|
+
### Quantizer Mode (CRF/CQ)
|
|
74
|
+
|
|
75
|
+
Uses a fixed quality level. The encoder adjusts bitrate to maintain consistent visual quality.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
encoder.configure({
|
|
79
|
+
codec: 'avc1.42001E',
|
|
80
|
+
width: 1920,
|
|
81
|
+
height: 1080,
|
|
82
|
+
bitrateMode: 'quantizer',
|
|
83
|
+
// bitrate is optional/ignored in this mode
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Pros:**
|
|
88
|
+
- Consistent visual quality
|
|
89
|
+
- Optimal for archival
|
|
90
|
+
- No need to guess bitrate
|
|
91
|
+
|
|
92
|
+
**Cons:**
|
|
93
|
+
- Unpredictable file size
|
|
94
|
+
- Not suitable for streaming
|
|
95
|
+
|
|
96
|
+
### Codec-Specific Implementation
|
|
97
|
+
|
|
98
|
+
Different codecs use different parameters for each bitrate mode:
|
|
99
|
+
|
|
100
|
+
| Codec | CBR | VBR | Quantizer |
|
|
101
|
+
|-------|-----|-----|-----------|
|
|
102
|
+
| H.264 | `-b:v` + `maxrate`/`bufsize`, CBR mode | `-b:v` only | `-crf 23` |
|
|
103
|
+
| H.265 | `-b:v` + `maxrate`/`bufsize`, CBR mode | `-b:v` only | `-crf 28` |
|
|
104
|
+
| VP8/VP9 | `-b:v` + `minrate`/`maxrate` | `-b:v` only | `-crf 31` + `-b:v 0` |
|
|
105
|
+
| AV1 | `-b:v` + `maxrate`/`bufsize` | `-b:v` only | `-crf 30` |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Alpha Channel Handling
|
|
110
|
+
|
|
111
|
+
The `alpha` option controls how transparent pixels are handled during encoding.
|
|
112
|
+
|
|
113
|
+
### Available Options
|
|
114
|
+
|
|
115
|
+
| Option | Description |
|
|
116
|
+
|--------|-------------|
|
|
117
|
+
| `'discard'` | Drop alpha channel (default) |
|
|
118
|
+
| `'keep'` | Preserve transparency |
|
|
119
|
+
|
|
120
|
+
### Codec Support for Alpha
|
|
121
|
+
|
|
122
|
+
| Codec | Alpha Support |
|
|
123
|
+
|-------|---------------|
|
|
124
|
+
| H.264 | No |
|
|
125
|
+
| H.265 | No |
|
|
126
|
+
| VP8 | No |
|
|
127
|
+
| VP9 | **Yes** |
|
|
128
|
+
| AV1 | **Yes** |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Output Bitstream Format
|
|
133
|
+
|
|
134
|
+
By default the encoders emit Annex B (video) and ADTS/OGG (audio) streams directly from FFmpeg. If you need MP4-style payloads (length-prefixed NAL units, raw AAC frames) you can opt-in via the `format` config field.
|
|
135
|
+
|
|
136
|
+
### VideoEncoder `format`
|
|
137
|
+
|
|
138
|
+
| Value | Description |
|
|
139
|
+
|-------|-------------|
|
|
140
|
+
| `'annexb'` (default) | Emit Annex B/IVF bitstreams (same as before). |
|
|
141
|
+
| `'mp4'` | Convert Annex B output into length-prefixed avcC/hvcc samples and include `decoderConfig.description`. |
|
|
142
|
+
|
|
143
|
+
When `format: 'mp4'` is set the encoder automatically extracts SPS/PPS/VPS from keyframes and exposes them in metadata so an MP4 muxer can use them.
|
|
144
|
+
|
|
145
|
+
### AudioEncoder `format`
|
|
146
|
+
|
|
147
|
+
| Value | Description |
|
|
148
|
+
|-------|-------------|
|
|
149
|
+
| `'adts'` (default) | Emit AAC frames with ADTS headers (or Ogg/MP3 for other codecs). |
|
|
150
|
+
| `'aac'` | Strip ADTS headers and expose raw AAC frames with the AudioSpecificConfig in `decoderConfig.description`. |
|
|
151
|
+
|
|
152
|
+
This option currently applies to `mp4a.*`/`aac` codecs; other audio codecs continue to emit their container-specific framing.
|
|
153
|
+
|
|
154
|
+
### Discarding Alpha (Default)
|
|
155
|
+
|
|
156
|
+
Strips the alpha channel. Works with all codecs.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
encoder.configure({
|
|
160
|
+
codec: 'avc1.42001E',
|
|
161
|
+
width: 1920,
|
|
162
|
+
height: 1080,
|
|
163
|
+
alpha: 'discard', // Default behavior
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
When encoding RGBA frames with `alpha: 'discard'`:
|
|
168
|
+
- Input: RGBA → Converted to YUV420
|
|
169
|
+
- Transparent areas become opaque
|
|
170
|
+
|
|
171
|
+
### Keeping Alpha
|
|
172
|
+
|
|
173
|
+
Preserves transparency. Only works with VP9 and AV1.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
encoder.configure({
|
|
177
|
+
codec: 'vp9',
|
|
178
|
+
width: 1920,
|
|
179
|
+
height: 1080,
|
|
180
|
+
alpha: 'keep',
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
When encoding RGBA frames with `alpha: 'keep'`:
|
|
185
|
+
- Input: RGBA → Converted to YUVA420P
|
|
186
|
+
- Transparency is preserved in the encoded video
|
|
187
|
+
|
|
188
|
+
**Example with transparent overlay:**
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
const encoder = new VideoEncoder({
|
|
192
|
+
output: (chunk) => saveChunk(chunk),
|
|
193
|
+
error: console.error,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
encoder.configure({
|
|
197
|
+
codec: 'vp9',
|
|
198
|
+
width: 640,
|
|
199
|
+
height: 480,
|
|
200
|
+
alpha: 'keep',
|
|
201
|
+
framerate: 30,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Create frame with transparency
|
|
205
|
+
const rgba = new Uint8Array(640 * 480 * 4);
|
|
206
|
+
for (let i = 0; i < rgba.length; i += 4) {
|
|
207
|
+
rgba[i] = 255; // R
|
|
208
|
+
rgba[i + 1] = 0; // G
|
|
209
|
+
rgba[i + 2] = 0; // B
|
|
210
|
+
rgba[i + 3] = 128; // A - 50% transparent
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const frame = new VideoFrame(rgba, {
|
|
214
|
+
format: 'RGBA',
|
|
215
|
+
codedWidth: 640,
|
|
216
|
+
codedHeight: 480,
|
|
217
|
+
timestamp: 0,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
encoder.encode(frame);
|
|
221
|
+
frame.close();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Latency Mode
|
|
227
|
+
|
|
228
|
+
The `latencyMode` option trades off compression efficiency for encoding latency.
|
|
229
|
+
|
|
230
|
+
### Available Modes
|
|
231
|
+
|
|
232
|
+
| Mode | Description | Use Case |
|
|
233
|
+
|------|-------------|----------|
|
|
234
|
+
| `'quality'` | Best compression (default) | File encoding, VOD |
|
|
235
|
+
| `'realtime'` | Minimum latency | Live streaming, video calls |
|
|
236
|
+
|
|
237
|
+
### Quality Mode (Default)
|
|
238
|
+
|
|
239
|
+
Optimizes for best compression. May use B-frames and lookahead.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
encoder.configure({
|
|
243
|
+
codec: 'avc1.42001E',
|
|
244
|
+
width: 1920,
|
|
245
|
+
height: 1080,
|
|
246
|
+
bitrate: 5_000_000,
|
|
247
|
+
latencyMode: 'quality',
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Realtime Mode
|
|
252
|
+
|
|
253
|
+
Minimizes encoding latency. Disables B-frames and lookahead.
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
encoder.configure({
|
|
257
|
+
codec: 'avc1.42001E',
|
|
258
|
+
width: 1920,
|
|
259
|
+
height: 1080,
|
|
260
|
+
bitrate: 2_000_000,
|
|
261
|
+
latencyMode: 'realtime',
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Codec-Specific Optimizations
|
|
266
|
+
|
|
267
|
+
| Codec | Quality Mode | Realtime Mode |
|
|
268
|
+
|-------|--------------|---------------|
|
|
269
|
+
| H.264 | Default (B-frames, lookahead) | `-tune zerolatency`, no B-frames |
|
|
270
|
+
| H.265 | Default settings | `-tune zerolatency`, no B-frames |
|
|
271
|
+
| VP8 | Default | `-deadline realtime`, `-cpu-used 8` |
|
|
272
|
+
| VP9 | Row multithreading, tile columns | `-deadline realtime`, `-cpu-used 8` |
|
|
273
|
+
| AV1 | Default | `-usage realtime`, `-cpu-used 8` |
|
|
274
|
+
|
|
275
|
+
**Example for live streaming:**
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
const encoder = new VideoEncoder({
|
|
279
|
+
output: (chunk) => {
|
|
280
|
+
// Send immediately over WebSocket/WebRTC
|
|
281
|
+
socket.send(chunk);
|
|
282
|
+
},
|
|
283
|
+
error: console.error,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
encoder.configure({
|
|
287
|
+
codec: 'avc1.42001E',
|
|
288
|
+
width: 1280,
|
|
289
|
+
height: 720,
|
|
290
|
+
bitrate: 2_000_000,
|
|
291
|
+
framerate: 30,
|
|
292
|
+
latencyMode: 'realtime',
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Hardware Acceleration
|
|
299
|
+
|
|
300
|
+
The `hardwareAcceleration` option controls GPU encoding/decoding.
|
|
301
|
+
|
|
302
|
+
### Available Options
|
|
303
|
+
|
|
304
|
+
| Option | Description |
|
|
305
|
+
|--------|-------------|
|
|
306
|
+
| `'no-preference'` | Let the system decide |
|
|
307
|
+
| `'prefer-hardware'` | Use GPU if available |
|
|
308
|
+
| `'prefer-software'` | Use CPU encoding |
|
|
309
|
+
|
|
310
|
+
### Using Hardware Acceleration
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
encoder.configure({
|
|
314
|
+
codec: 'avc1.42001E',
|
|
315
|
+
width: 1920,
|
|
316
|
+
height: 1080,
|
|
317
|
+
bitrate: 5_000_000,
|
|
318
|
+
hardwareAcceleration: 'prefer-hardware',
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Detecting Available Hardware
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import {
|
|
326
|
+
detectHardwareAcceleration,
|
|
327
|
+
getHardwareAccelerationSummary,
|
|
328
|
+
} from 'webcodecs-node';
|
|
329
|
+
|
|
330
|
+
// Get human-readable summary
|
|
331
|
+
const summary = await getHardwareAccelerationSummary();
|
|
332
|
+
console.log(summary);
|
|
333
|
+
|
|
334
|
+
// Get detailed capabilities
|
|
335
|
+
const caps = await detectHardwareAcceleration();
|
|
336
|
+
console.log('Methods:', caps.methods);
|
|
337
|
+
console.log('Encoders:', caps.encoders);
|
|
338
|
+
console.log('Decoders:', caps.decoders);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Supported Hardware Methods
|
|
342
|
+
|
|
343
|
+
| Method | Platform | GPUs |
|
|
344
|
+
|--------|----------|------|
|
|
345
|
+
| VAAPI | Linux | Intel, AMD |
|
|
346
|
+
| NVENC/NVDEC | Linux, Windows | NVIDIA |
|
|
347
|
+
| QSV | Linux, Windows | Intel |
|
|
348
|
+
| VideoToolbox | macOS | Apple Silicon, Intel |
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Pixel Formats
|
|
353
|
+
|
|
354
|
+
VideoFrame supports various pixel formats for input.
|
|
355
|
+
|
|
356
|
+
### Supported Formats
|
|
357
|
+
|
|
358
|
+
| Format | Description | Bytes/Pixel |
|
|
359
|
+
|--------|-------------|-------------|
|
|
360
|
+
| `'I420'` | YUV 4:2:0 planar | 1.5 |
|
|
361
|
+
| `'I420A'` | YUV 4:2:0 + alpha planar | 2 |
|
|
362
|
+
| `'I422'` | YUV 4:2:2 planar | 2 |
|
|
363
|
+
| `'I444'` | YUV 4:4:4 planar | 3 |
|
|
364
|
+
| `'NV12'` | YUV 4:2:0 semi-planar | 1.5 |
|
|
365
|
+
| `'RGBA'` | 8-bit RGBA interleaved | 4 |
|
|
366
|
+
| `'RGBX'` | 8-bit RGB (alpha ignored) | 4 |
|
|
367
|
+
| `'BGRA'` | 8-bit BGRA interleaved | 4 |
|
|
368
|
+
| `'BGRX'` | 8-bit BGR (alpha ignored) | 4 |
|
|
369
|
+
|
|
370
|
+
### Choosing a Format
|
|
371
|
+
|
|
372
|
+
**For encoding with transparency:**
|
|
373
|
+
```typescript
|
|
374
|
+
const frame = new VideoFrame(rgbaData, {
|
|
375
|
+
format: 'RGBA',
|
|
376
|
+
codedWidth: 1920,
|
|
377
|
+
codedHeight: 1080,
|
|
378
|
+
timestamp: 0,
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**For maximum efficiency (no color conversion):**
|
|
383
|
+
```typescript
|
|
384
|
+
const frame = new VideoFrame(yuvData, {
|
|
385
|
+
format: 'I420',
|
|
386
|
+
codedWidth: 1920,
|
|
387
|
+
codedHeight: 1080,
|
|
388
|
+
timestamp: 0,
|
|
389
|
+
});
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## Audio Sample Formats
|
|
395
|
+
|
|
396
|
+
AudioData supports various sample formats.
|
|
397
|
+
|
|
398
|
+
### Interleaved Formats
|
|
399
|
+
|
|
400
|
+
Samples from all channels are interleaved: L R L R L R...
|
|
401
|
+
|
|
402
|
+
| Format | Description | Bytes/Sample |
|
|
403
|
+
|--------|-------------|--------------|
|
|
404
|
+
| `'u8'` | Unsigned 8-bit | 1 |
|
|
405
|
+
| `'s16'` | Signed 16-bit | 2 |
|
|
406
|
+
| `'s32'` | Signed 32-bit | 4 |
|
|
407
|
+
| `'f32'` | 32-bit float | 4 |
|
|
408
|
+
|
|
409
|
+
### Planar Formats
|
|
410
|
+
|
|
411
|
+
Samples are grouped by channel: LLLLLL RRRRRR
|
|
412
|
+
|
|
413
|
+
| Format | Description | Bytes/Sample |
|
|
414
|
+
|--------|-------------|--------------|
|
|
415
|
+
| `'u8-planar'` | Unsigned 8-bit planar | 1 |
|
|
416
|
+
| `'s16-planar'` | Signed 16-bit planar | 2 |
|
|
417
|
+
| `'s32-planar'` | Signed 32-bit planar | 4 |
|
|
418
|
+
| `'f32-planar'` | 32-bit float planar | 4 |
|
|
419
|
+
|
|
420
|
+
### Example
|
|
421
|
+
|
|
422
|
+
```typescript
|
|
423
|
+
// Interleaved stereo float samples
|
|
424
|
+
const audioData = new AudioData({
|
|
425
|
+
format: 'f32',
|
|
426
|
+
sampleRate: 48000,
|
|
427
|
+
numberOfChannels: 2,
|
|
428
|
+
numberOfFrames: 1024,
|
|
429
|
+
timestamp: 0,
|
|
430
|
+
data: float32Samples, // L R L R L R...
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Planar stereo float samples
|
|
434
|
+
const audioDataPlanar = new AudioData({
|
|
435
|
+
format: 'f32-planar',
|
|
436
|
+
sampleRate: 48000,
|
|
437
|
+
numberOfChannels: 2,
|
|
438
|
+
numberOfFrames: 1024,
|
|
439
|
+
timestamp: 0,
|
|
440
|
+
data: float32SamplesPlanar, // LLLL... RRRR...
|
|
441
|
+
});
|
|
442
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Practical examples demonstrating webcodecs-node features.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Build the project first:
|
|
8
|
+
```bash
|
|
9
|
+
npm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Running Examples
|
|
13
|
+
|
|
14
|
+
Use `npx tsx` to run TypeScript examples directly:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx tsx examples/video-encoding.ts
|
|
18
|
+
npx tsx examples/video-decoding.ts
|
|
19
|
+
npx tsx examples/audio-encoding.ts
|
|
20
|
+
npx tsx examples/image-decoding.ts
|
|
21
|
+
npx tsx examples/transparent-video.ts
|
|
22
|
+
npx tsx examples/streaming.ts
|
|
23
|
+
npx tsx examples/hardware-encoding.ts
|
|
24
|
+
npx tsx examples/hardware-decoding.ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### video-encoding.ts
|
|
30
|
+
|
|
31
|
+
Basic video encoding with H.264. Demonstrates:
|
|
32
|
+
- Creating a VideoEncoder
|
|
33
|
+
- Configuring codec, bitrate, and framerate
|
|
34
|
+
- Encoding VideoFrames from raw RGBA data
|
|
35
|
+
- Handling keyframes
|
|
36
|
+
|
|
37
|
+
### video-decoding.ts
|
|
38
|
+
|
|
39
|
+
Video decoding back to raw frames. Demonstrates:
|
|
40
|
+
- Encoding frames to get sample chunks
|
|
41
|
+
- Creating a VideoDecoder
|
|
42
|
+
- Decoding EncodedVideoChunks back to VideoFrames
|
|
43
|
+
|
|
44
|
+
### audio-encoding.ts
|
|
45
|
+
|
|
46
|
+
Audio encoding with Opus. Demonstrates:
|
|
47
|
+
- Creating an AudioEncoder
|
|
48
|
+
- Configuring sample rate, channels, and bitrate
|
|
49
|
+
- Encoding AudioData from float32 samples
|
|
50
|
+
- Generating sine wave test audio
|
|
51
|
+
|
|
52
|
+
### image-decoding.ts
|
|
53
|
+
|
|
54
|
+
Image decoding including animated formats. Demonstrates:
|
|
55
|
+
- Checking format support with isTypeSupported
|
|
56
|
+
- Decoding PNG, JPEG, GIF, WebP images
|
|
57
|
+
- Accessing frame timing for animated images
|
|
58
|
+
- Using ImageTrackList for animation info
|
|
59
|
+
|
|
60
|
+
### transparent-video.ts
|
|
61
|
+
|
|
62
|
+
VP9 encoding with alpha channel. Demonstrates:
|
|
63
|
+
- Configuring `alpha: 'keep'` for transparency
|
|
64
|
+
- Creating frames with varying alpha values
|
|
65
|
+
- Comparing file sizes with/without alpha
|
|
66
|
+
|
|
67
|
+
### streaming.ts
|
|
68
|
+
|
|
69
|
+
Real-time vs quality encoding comparison. Demonstrates:
|
|
70
|
+
- Using `latencyMode: 'realtime'` for streaming
|
|
71
|
+
- Using `latencyMode: 'quality'` for best compression
|
|
72
|
+
- Measuring encode time and output size differences
|
|
73
|
+
|
|
74
|
+
### hardware-encoding.ts
|
|
75
|
+
|
|
76
|
+
GPU-accelerated encoding. Demonstrates:
|
|
77
|
+
- Detecting available hardware acceleration (VAAPI, NVENC, QSV)
|
|
78
|
+
- Using `hardwareAcceleration: 'prefer-hardware'`
|
|
79
|
+
- Benchmarking hardware vs software encoding
|
|
80
|
+
- Getting the best encoder for a codec
|
|
81
|
+
|
|
82
|
+
### hardware-decoding.ts
|
|
83
|
+
|
|
84
|
+
GPU-accelerated decoding. Demonstrates:
|
|
85
|
+
- Detecting available hardware decoders (VAAPI, NVDEC, QSV)
|
|
86
|
+
- Using `hardwareAcceleration: 'prefer-hardware'` for decoding
|
|
87
|
+
- Benchmarking hardware vs software decoding
|
|
88
|
+
- Real-time decoding capability analysis
|
|
89
|
+
|
|
90
|
+
## Additional Demos
|
|
91
|
+
|
|
92
|
+
The `demos/` folder contains more complete demos that can be run via npm scripts:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run demo:webcodecs # Basic WebCodecs demo
|
|
96
|
+
npm run demo:image # Image decoding demo
|
|
97
|
+
npm run demo:streaming # Streaming comparison
|
|
98
|
+
npm run demo:conversion # File conversion with Mediabunny
|
|
99
|
+
npm run demo:hwaccel # Hardware acceleration detection
|
|
100
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio Encoding Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates how to encode raw audio samples to Opus.
|
|
5
|
+
*
|
|
6
|
+
* Run: npx tsx examples/audio-encoding.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { AudioEncoder, AudioData, EncodedAudioChunk } from '../src/index.js';
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
const sampleRate = 48000;
|
|
13
|
+
const numberOfChannels = 2;
|
|
14
|
+
const duration = 2; // seconds
|
|
15
|
+
const samplesPerChunk = 960; // Opus frame size
|
|
16
|
+
|
|
17
|
+
const chunks: EncodedAudioChunk[] = [];
|
|
18
|
+
|
|
19
|
+
// Create encoder
|
|
20
|
+
const encoder = new AudioEncoder({
|
|
21
|
+
output: (chunk, metadata) => {
|
|
22
|
+
chunks.push(chunk);
|
|
23
|
+
console.log(
|
|
24
|
+
`Encoded audio: ${chunk.byteLength} bytes, timestamp: ${chunk.timestamp}`
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
error: (err) => {
|
|
28
|
+
console.error('Encoding error:', err);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Configure for Opus encoding
|
|
33
|
+
encoder.configure({
|
|
34
|
+
codec: 'opus',
|
|
35
|
+
sampleRate,
|
|
36
|
+
numberOfChannels,
|
|
37
|
+
bitrate: 128000,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(`Encoding ${duration}s of audio at ${sampleRate}Hz stereo...\n`);
|
|
41
|
+
|
|
42
|
+
// Generate and encode audio samples (sine wave)
|
|
43
|
+
const totalSamples = sampleRate * duration;
|
|
44
|
+
let timestamp = 0;
|
|
45
|
+
|
|
46
|
+
for (let offset = 0; offset < totalSamples; offset += samplesPerChunk) {
|
|
47
|
+
const samples = new Float32Array(samplesPerChunk * numberOfChannels);
|
|
48
|
+
|
|
49
|
+
// Generate stereo sine wave (440Hz left, 880Hz right)
|
|
50
|
+
for (let i = 0; i < samplesPerChunk; i++) {
|
|
51
|
+
const t = (offset + i) / sampleRate;
|
|
52
|
+
samples[i * 2] = Math.sin(2 * Math.PI * 440 * t) * 0.5; // Left
|
|
53
|
+
samples[i * 2 + 1] = Math.sin(2 * Math.PI * 880 * t) * 0.5; // Right
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const audioData = new AudioData({
|
|
57
|
+
format: 'f32', // Interleaved float32
|
|
58
|
+
sampleRate,
|
|
59
|
+
numberOfChannels,
|
|
60
|
+
numberOfFrames: samplesPerChunk,
|
|
61
|
+
timestamp,
|
|
62
|
+
data: samples,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
encoder.encode(audioData);
|
|
66
|
+
audioData.close();
|
|
67
|
+
|
|
68
|
+
timestamp += (samplesPerChunk * 1_000_000) / sampleRate;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await encoder.flush();
|
|
72
|
+
encoder.close();
|
|
73
|
+
|
|
74
|
+
// Calculate statistics
|
|
75
|
+
const totalBytes = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
76
|
+
const actualBitrate = (totalBytes * 8) / duration;
|
|
77
|
+
|
|
78
|
+
console.log(`\nEncoding complete:`);
|
|
79
|
+
console.log(` Duration: ${duration}s`);
|
|
80
|
+
console.log(` Chunks: ${chunks.length}`);
|
|
81
|
+
console.log(` Total size: ${(totalBytes / 1024).toFixed(2)} KB`);
|
|
82
|
+
console.log(` Actual bitrate: ${(actualBitrate / 1000).toFixed(0)} kbps`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main().catch(console.error);
|