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,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Accelerated Video Decoding Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates GPU-accelerated decoding with VAAPI, NVDEC, or QSV.
|
|
5
|
+
*
|
|
6
|
+
* Run: npx tsx examples/hardware-decoding.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
VideoEncoder,
|
|
11
|
+
VideoDecoder,
|
|
12
|
+
VideoFrame,
|
|
13
|
+
EncodedVideoChunk,
|
|
14
|
+
} from '../src/index.js';
|
|
15
|
+
import {
|
|
16
|
+
detectHardwareAcceleration,
|
|
17
|
+
getHardwareAccelerationSummary,
|
|
18
|
+
} from '../src/index.js';
|
|
19
|
+
|
|
20
|
+
interface BenchmarkResult {
|
|
21
|
+
mode: string;
|
|
22
|
+
decodeTime: number;
|
|
23
|
+
framesDecoded: number;
|
|
24
|
+
fps: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function createTestChunks(
|
|
28
|
+
width: number,
|
|
29
|
+
height: number,
|
|
30
|
+
frameCount: number,
|
|
31
|
+
framerate: number
|
|
32
|
+
): Promise<EncodedVideoChunk[]> {
|
|
33
|
+
const chunks: EncodedVideoChunk[] = [];
|
|
34
|
+
|
|
35
|
+
const encoder = new VideoEncoder({
|
|
36
|
+
output: (chunk) => chunks.push(chunk),
|
|
37
|
+
error: console.error,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
encoder.configure({
|
|
41
|
+
codec: 'avc1.42001E',
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
bitrate: 5_000_000,
|
|
45
|
+
framerate,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Generate complex frames for realistic decoding load
|
|
49
|
+
for (let i = 0; i < frameCount; i++) {
|
|
50
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
51
|
+
for (let y = 0; y < height; y++) {
|
|
52
|
+
for (let x = 0; x < width; x++) {
|
|
53
|
+
const idx = (y * width + x) * 4;
|
|
54
|
+
rgba[idx] = (x * y + i * 17) % 256;
|
|
55
|
+
rgba[idx + 1] = (x + y * 2 + i * 23) % 256;
|
|
56
|
+
rgba[idx + 2] = ((x - y) * 3 + i * 31) % 256;
|
|
57
|
+
rgba[idx + 3] = 255;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const frame = new VideoFrame(rgba, {
|
|
62
|
+
format: 'RGBA',
|
|
63
|
+
codedWidth: width,
|
|
64
|
+
codedHeight: height,
|
|
65
|
+
timestamp: (i * 1_000_000) / framerate,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
encoder.encode(frame, { keyFrame: i % framerate === 0 });
|
|
69
|
+
frame.close();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await encoder.flush();
|
|
73
|
+
encoder.close();
|
|
74
|
+
|
|
75
|
+
return chunks;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function benchmarkDecode(
|
|
79
|
+
chunks: EncodedVideoChunk[],
|
|
80
|
+
width: number,
|
|
81
|
+
height: number,
|
|
82
|
+
hardwareAcceleration: 'no-preference' | 'prefer-hardware' | 'prefer-software'
|
|
83
|
+
): Promise<BenchmarkResult> {
|
|
84
|
+
let framesDecoded = 0;
|
|
85
|
+
|
|
86
|
+
const decoder = new VideoDecoder({
|
|
87
|
+
output: (frame) => {
|
|
88
|
+
framesDecoded++;
|
|
89
|
+
frame.close();
|
|
90
|
+
},
|
|
91
|
+
error: console.error,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
decoder.configure({
|
|
95
|
+
codec: 'avc1.42001E',
|
|
96
|
+
codedWidth: width,
|
|
97
|
+
codedHeight: height,
|
|
98
|
+
hardwareAcceleration,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const startTime = Date.now();
|
|
102
|
+
|
|
103
|
+
for (const chunk of chunks) {
|
|
104
|
+
decoder.decode(chunk);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await decoder.flush();
|
|
108
|
+
decoder.close();
|
|
109
|
+
|
|
110
|
+
const decodeTime = Date.now() - startTime;
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
mode: hardwareAcceleration,
|
|
114
|
+
decodeTime,
|
|
115
|
+
framesDecoded,
|
|
116
|
+
fps: (framesDecoded * 1000) / decodeTime,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function main() {
|
|
121
|
+
console.log('=== Hardware Accelerated Video Decoding ===\n');
|
|
122
|
+
|
|
123
|
+
// Detect available hardware acceleration
|
|
124
|
+
console.log('Detecting hardware acceleration...\n');
|
|
125
|
+
|
|
126
|
+
const summary = await getHardwareAccelerationSummary();
|
|
127
|
+
console.log(summary);
|
|
128
|
+
console.log('');
|
|
129
|
+
|
|
130
|
+
// Get detailed capabilities
|
|
131
|
+
const capabilities = await detectHardwareAcceleration();
|
|
132
|
+
|
|
133
|
+
if (capabilities.decoders.length > 0) {
|
|
134
|
+
console.log('Hardware decoders:');
|
|
135
|
+
for (const dec of capabilities.decoders) {
|
|
136
|
+
console.log(` - ${dec}`);
|
|
137
|
+
}
|
|
138
|
+
console.log('');
|
|
139
|
+
} else {
|
|
140
|
+
console.log('No hardware decoders detected.\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Benchmark parameters
|
|
144
|
+
const width = 1280;
|
|
145
|
+
const height = 720;
|
|
146
|
+
const frameCount = 120;
|
|
147
|
+
const framerate = 30;
|
|
148
|
+
|
|
149
|
+
console.log(`Creating ${frameCount} test frames at ${width}x${height}...`);
|
|
150
|
+
const chunks = await createTestChunks(width, height, frameCount, framerate);
|
|
151
|
+
console.log(`Created ${chunks.length} encoded chunks\n`);
|
|
152
|
+
|
|
153
|
+
const totalBytes = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
154
|
+
console.log(`Total encoded size: ${(totalBytes / 1024).toFixed(2)} KB`);
|
|
155
|
+
console.log(`Average chunk size: ${(totalBytes / chunks.length).toFixed(0)} bytes\n`);
|
|
156
|
+
|
|
157
|
+
// Benchmark software decoding
|
|
158
|
+
console.log('Testing software decoding...');
|
|
159
|
+
const softwareResult = await benchmarkDecode(chunks, width, height, 'prefer-software');
|
|
160
|
+
|
|
161
|
+
// Benchmark hardware decoding
|
|
162
|
+
console.log('Testing hardware decoding...');
|
|
163
|
+
const hardwareResult = await benchmarkDecode(chunks, width, height, 'prefer-hardware');
|
|
164
|
+
|
|
165
|
+
// Display results
|
|
166
|
+
console.log('\n=== Benchmark Results ===\n');
|
|
167
|
+
|
|
168
|
+
console.log('Software Decoding (CPU):');
|
|
169
|
+
console.log(` Decode time: ${softwareResult.decodeTime}ms`);
|
|
170
|
+
console.log(` Frames decoded: ${softwareResult.framesDecoded}`);
|
|
171
|
+
console.log(` Throughput: ${softwareResult.fps.toFixed(1)} fps`);
|
|
172
|
+
console.log(` Real-time capable: ${softwareResult.fps >= framerate ? 'Yes' : 'No'}`);
|
|
173
|
+
|
|
174
|
+
console.log('\nHardware Decoding (GPU):');
|
|
175
|
+
console.log(` Decode time: ${hardwareResult.decodeTime}ms`);
|
|
176
|
+
console.log(` Frames decoded: ${hardwareResult.framesDecoded}`);
|
|
177
|
+
console.log(` Throughput: ${hardwareResult.fps.toFixed(1)} fps`);
|
|
178
|
+
console.log(` Real-time capable: ${hardwareResult.fps >= framerate ? 'Yes' : 'No'}`);
|
|
179
|
+
|
|
180
|
+
// Comparison
|
|
181
|
+
console.log('\n=== Comparison ===\n');
|
|
182
|
+
|
|
183
|
+
const speedup = softwareResult.decodeTime / hardwareResult.decodeTime;
|
|
184
|
+
|
|
185
|
+
if (speedup > 1.1) {
|
|
186
|
+
console.log(`Hardware decoding is ${speedup.toFixed(2)}x faster`);
|
|
187
|
+
} else if (speedup < 0.9) {
|
|
188
|
+
console.log(`Software decoding is ${(1 / speedup).toFixed(2)}x faster`);
|
|
189
|
+
console.log('(Hardware acceleration may not be available or configured)');
|
|
190
|
+
} else {
|
|
191
|
+
console.log('Performance is similar (hardware may not be available)');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Calculate how many streams could be decoded in real-time
|
|
195
|
+
const softwareStreams = Math.floor(softwareResult.fps / framerate);
|
|
196
|
+
const hardwareStreams = Math.floor(hardwareResult.fps / framerate);
|
|
197
|
+
|
|
198
|
+
console.log(`\nConcurrent streams (real-time @ ${framerate}fps):`);
|
|
199
|
+
console.log(` Software: ${softwareStreams} stream${softwareStreams !== 1 ? 's' : ''}`);
|
|
200
|
+
console.log(` Hardware: ${hardwareStreams} stream${hardwareStreams !== 1 ? 's' : ''}`);
|
|
201
|
+
|
|
202
|
+
// Usage recommendations
|
|
203
|
+
console.log('\n=== When to Use Hardware Decoding ===\n');
|
|
204
|
+
|
|
205
|
+
console.log('Use prefer-hardware when:');
|
|
206
|
+
console.log(' - Decoding HD/4K video');
|
|
207
|
+
console.log(' - Multiple simultaneous streams');
|
|
208
|
+
console.log(' - Real-time playback');
|
|
209
|
+
console.log(' - Transcoding pipelines');
|
|
210
|
+
console.log(' - CPU resources are constrained');
|
|
211
|
+
|
|
212
|
+
console.log('\nUse prefer-software when:');
|
|
213
|
+
console.log(' - Maximum compatibility needed');
|
|
214
|
+
console.log(' - No compatible GPU available');
|
|
215
|
+
console.log(' - Decoding unusual/rare codecs');
|
|
216
|
+
console.log(' - Frame-accurate seeking required');
|
|
217
|
+
|
|
218
|
+
// Example configuration
|
|
219
|
+
console.log('\n=== Example Configuration ===\n');
|
|
220
|
+
console.log(`const decoder = new VideoDecoder({
|
|
221
|
+
output: (frame) => {
|
|
222
|
+
// Process decoded frame
|
|
223
|
+
processFrame(frame);
|
|
224
|
+
frame.close();
|
|
225
|
+
},
|
|
226
|
+
error: handleError,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
decoder.configure({
|
|
230
|
+
codec: 'avc1.42001E',
|
|
231
|
+
codedWidth: 1920,
|
|
232
|
+
codedHeight: 1080,
|
|
233
|
+
hardwareAcceleration: 'prefer-hardware',
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Decode chunks
|
|
237
|
+
for (const chunk of encodedChunks) {
|
|
238
|
+
decoder.decode(chunk);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
await decoder.flush();
|
|
242
|
+
decoder.close();`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Accelerated Video Encoding Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates GPU-accelerated encoding with VAAPI, NVENC, or QSV.
|
|
5
|
+
*
|
|
6
|
+
* Run: npx tsx examples/hardware-encoding.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { VideoEncoder, VideoFrame, EncodedVideoChunk } from '../src/index.js';
|
|
10
|
+
import {
|
|
11
|
+
detectHardwareAcceleration,
|
|
12
|
+
getHardwareAccelerationSummary,
|
|
13
|
+
getBestEncoder,
|
|
14
|
+
} from '../src/index.js';
|
|
15
|
+
|
|
16
|
+
interface BenchmarkResult {
|
|
17
|
+
mode: string;
|
|
18
|
+
encoder: string;
|
|
19
|
+
encodeTime: number;
|
|
20
|
+
totalBytes: number;
|
|
21
|
+
fps: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function benchmark(
|
|
25
|
+
width: number,
|
|
26
|
+
height: number,
|
|
27
|
+
frameCount: number,
|
|
28
|
+
framerate: number,
|
|
29
|
+
hardwareAcceleration: 'no-preference' | 'prefer-hardware' | 'prefer-software'
|
|
30
|
+
): Promise<BenchmarkResult> {
|
|
31
|
+
const chunks: EncodedVideoChunk[] = [];
|
|
32
|
+
|
|
33
|
+
const encoder = new VideoEncoder({
|
|
34
|
+
output: (chunk) => chunks.push(chunk),
|
|
35
|
+
error: console.error,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
encoder.configure({
|
|
39
|
+
codec: 'avc1.42001E',
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
bitrate: 5_000_000,
|
|
43
|
+
framerate,
|
|
44
|
+
hardwareAcceleration,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Pre-generate all frame data to exclude from timing
|
|
48
|
+
const frames: Uint8Array[] = [];
|
|
49
|
+
for (let i = 0; i < frameCount; i++) {
|
|
50
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
51
|
+
// Create complex pattern for realistic encoding load
|
|
52
|
+
for (let y = 0; y < height; y++) {
|
|
53
|
+
for (let x = 0; x < width; x++) {
|
|
54
|
+
const idx = (y * width + x) * 4;
|
|
55
|
+
// Animated noise pattern
|
|
56
|
+
rgba[idx] = (x * y + i * 17) % 256;
|
|
57
|
+
rgba[idx + 1] = (x + y * 2 + i * 23) % 256;
|
|
58
|
+
rgba[idx + 2] = ((x - y) * 3 + i * 31) % 256;
|
|
59
|
+
rgba[idx + 3] = 255;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
frames.push(rgba);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Time the encoding
|
|
66
|
+
const startTime = Date.now();
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < frameCount; i++) {
|
|
69
|
+
const frame = new VideoFrame(frames[i], {
|
|
70
|
+
format: 'RGBA',
|
|
71
|
+
codedWidth: width,
|
|
72
|
+
codedHeight: height,
|
|
73
|
+
timestamp: (i * 1_000_000) / framerate,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
encoder.encode(frame, { keyFrame: i % framerate === 0 });
|
|
77
|
+
frame.close();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await encoder.flush();
|
|
81
|
+
encoder.close();
|
|
82
|
+
|
|
83
|
+
const encodeTime = Date.now() - startTime;
|
|
84
|
+
const totalBytes = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
mode: hardwareAcceleration,
|
|
88
|
+
encoder: hardwareAcceleration === 'prefer-hardware' ? 'GPU (if available)' : 'CPU',
|
|
89
|
+
encodeTime,
|
|
90
|
+
totalBytes,
|
|
91
|
+
fps: (frameCount * 1000) / encodeTime,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main() {
|
|
96
|
+
console.log('=== Hardware Accelerated Video Encoding ===\n');
|
|
97
|
+
|
|
98
|
+
// Detect available hardware acceleration
|
|
99
|
+
console.log('Detecting hardware acceleration...\n');
|
|
100
|
+
|
|
101
|
+
const summary = await getHardwareAccelerationSummary();
|
|
102
|
+
console.log(summary);
|
|
103
|
+
console.log('');
|
|
104
|
+
|
|
105
|
+
// Get detailed capabilities
|
|
106
|
+
const capabilities = await detectHardwareAcceleration();
|
|
107
|
+
|
|
108
|
+
if (capabilities.methods.length > 0) {
|
|
109
|
+
console.log('Available acceleration methods:');
|
|
110
|
+
for (const method of capabilities.methods) {
|
|
111
|
+
console.log(` - ${method}`);
|
|
112
|
+
}
|
|
113
|
+
console.log('');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (capabilities.encoders.length > 0) {
|
|
117
|
+
console.log('Hardware encoders:');
|
|
118
|
+
for (const enc of capabilities.encoders) {
|
|
119
|
+
console.log(` - ${enc}`);
|
|
120
|
+
}
|
|
121
|
+
console.log('');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Get best encoder for H.264
|
|
125
|
+
console.log('Finding best H.264 encoder...');
|
|
126
|
+
const bestH264 = await getBestEncoder('h264', 'prefer-hardware');
|
|
127
|
+
console.log(` Best encoder: ${bestH264.encoder}`);
|
|
128
|
+
console.log(` Hardware: ${bestH264.isHardware}`);
|
|
129
|
+
console.log('');
|
|
130
|
+
|
|
131
|
+
// Benchmark parameters
|
|
132
|
+
const width = 1280;
|
|
133
|
+
const height = 720;
|
|
134
|
+
const frameCount = 60;
|
|
135
|
+
const framerate = 30;
|
|
136
|
+
|
|
137
|
+
console.log(`\nBenchmarking ${width}x${height} @ ${framerate}fps (${frameCount} frames)...\n`);
|
|
138
|
+
|
|
139
|
+
// Benchmark software encoding
|
|
140
|
+
console.log('Testing software encoding...');
|
|
141
|
+
const softwareResult = await benchmark(
|
|
142
|
+
width,
|
|
143
|
+
height,
|
|
144
|
+
frameCount,
|
|
145
|
+
framerate,
|
|
146
|
+
'prefer-software'
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// Benchmark hardware encoding
|
|
150
|
+
console.log('Testing hardware encoding...');
|
|
151
|
+
const hardwareResult = await benchmark(
|
|
152
|
+
width,
|
|
153
|
+
height,
|
|
154
|
+
frameCount,
|
|
155
|
+
framerate,
|
|
156
|
+
'prefer-hardware'
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Display results
|
|
160
|
+
console.log('\n=== Benchmark Results ===\n');
|
|
161
|
+
|
|
162
|
+
console.log('Software Encoding (CPU):');
|
|
163
|
+
console.log(` Encode time: ${softwareResult.encodeTime}ms`);
|
|
164
|
+
console.log(` Throughput: ${softwareResult.fps.toFixed(1)} fps`);
|
|
165
|
+
console.log(` Output size: ${(softwareResult.totalBytes / 1024).toFixed(2)} KB`);
|
|
166
|
+
console.log(
|
|
167
|
+
` Bitrate: ${((softwareResult.totalBytes * 8 * framerate) / frameCount / 1000).toFixed(0)} kbps`
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
console.log('\nHardware Encoding (GPU):');
|
|
171
|
+
console.log(` Encode time: ${hardwareResult.encodeTime}ms`);
|
|
172
|
+
console.log(` Throughput: ${hardwareResult.fps.toFixed(1)} fps`);
|
|
173
|
+
console.log(` Output size: ${(hardwareResult.totalBytes / 1024).toFixed(2)} KB`);
|
|
174
|
+
console.log(
|
|
175
|
+
` Bitrate: ${((hardwareResult.totalBytes * 8 * framerate) / frameCount / 1000).toFixed(0)} kbps`
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Comparison
|
|
179
|
+
console.log('\n=== Comparison ===\n');
|
|
180
|
+
|
|
181
|
+
const speedup = softwareResult.encodeTime / hardwareResult.encodeTime;
|
|
182
|
+
const sizeRatio = hardwareResult.totalBytes / softwareResult.totalBytes;
|
|
183
|
+
|
|
184
|
+
if (speedup > 1.1) {
|
|
185
|
+
console.log(`Hardware encoding is ${speedup.toFixed(2)}x faster`);
|
|
186
|
+
} else if (speedup < 0.9) {
|
|
187
|
+
console.log(`Software encoding is ${(1 / speedup).toFixed(2)}x faster`);
|
|
188
|
+
console.log('(Hardware acceleration may not be available or configured)');
|
|
189
|
+
} else {
|
|
190
|
+
console.log('Performance is similar (hardware may not be available)');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.log(
|
|
194
|
+
`File size difference: ${((sizeRatio - 1) * 100).toFixed(1)}% ` +
|
|
195
|
+
`(${sizeRatio > 1 ? 'larger' : 'smaller'} with hardware)`
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
// Usage recommendations
|
|
199
|
+
console.log('\n=== When to Use Hardware Acceleration ===\n');
|
|
200
|
+
|
|
201
|
+
console.log('Use prefer-hardware when:');
|
|
202
|
+
console.log(' - Encoding HD/4K video');
|
|
203
|
+
console.log(' - Real-time streaming');
|
|
204
|
+
console.log(' - Batch processing many videos');
|
|
205
|
+
console.log(' - CPU resources are constrained');
|
|
206
|
+
|
|
207
|
+
console.log('\nUse prefer-software when:');
|
|
208
|
+
console.log(' - Maximum compression quality needed');
|
|
209
|
+
console.log(' - Archival purposes');
|
|
210
|
+
console.log(' - No compatible GPU available');
|
|
211
|
+
console.log(' - Encoding small/low-res content');
|
|
212
|
+
|
|
213
|
+
// Example configuration
|
|
214
|
+
console.log('\n=== Example Configuration ===\n');
|
|
215
|
+
console.log(`const encoder = new VideoEncoder({
|
|
216
|
+
output: handleChunk,
|
|
217
|
+
error: handleError,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
encoder.configure({
|
|
221
|
+
codec: 'avc1.42001E',
|
|
222
|
+
width: 1920,
|
|
223
|
+
height: 1080,
|
|
224
|
+
bitrate: 5_000_000,
|
|
225
|
+
framerate: 30,
|
|
226
|
+
hardwareAcceleration: 'prefer-hardware',
|
|
227
|
+
latencyMode: 'realtime', // Combine with low-latency for streaming
|
|
228
|
+
});`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Decoding Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates how to decode images including animated GIFs.
|
|
5
|
+
*
|
|
6
|
+
* Run: npx tsx examples/image-decoding.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ImageDecoder } from '../src/index.js';
|
|
10
|
+
import { readFileSync, existsSync } from 'fs';
|
|
11
|
+
import { join, dirname } from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
|
|
14
|
+
async function decodeImage(imagePath: string) {
|
|
15
|
+
if (!existsSync(imagePath)) {
|
|
16
|
+
console.log(`File not found: ${imagePath}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const data = readFileSync(imagePath);
|
|
21
|
+
const ext = imagePath.split('.').pop()?.toLowerCase();
|
|
22
|
+
|
|
23
|
+
// Map extension to MIME type
|
|
24
|
+
const mimeTypes: Record<string, string> = {
|
|
25
|
+
png: 'image/png',
|
|
26
|
+
jpg: 'image/jpeg',
|
|
27
|
+
jpeg: 'image/jpeg',
|
|
28
|
+
gif: 'image/gif',
|
|
29
|
+
webp: 'image/webp',
|
|
30
|
+
avif: 'image/avif',
|
|
31
|
+
bmp: 'image/bmp',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const type = mimeTypes[ext || ''] || 'image/png';
|
|
35
|
+
|
|
36
|
+
console.log(`\nDecoding: ${imagePath}`);
|
|
37
|
+
console.log(`MIME type: ${type}`);
|
|
38
|
+
console.log(`File size: ${(data.length / 1024).toFixed(2)} KB`);
|
|
39
|
+
|
|
40
|
+
const decoder = new ImageDecoder({
|
|
41
|
+
type,
|
|
42
|
+
data,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Wait for parsing to complete
|
|
46
|
+
await decoder.completed;
|
|
47
|
+
|
|
48
|
+
const track = decoder.tracks.selectedTrack;
|
|
49
|
+
if (!track) {
|
|
50
|
+
console.log('No image track found');
|
|
51
|
+
decoder.close();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(`\nImage properties:`);
|
|
56
|
+
console.log(` Frames: ${track.frameCount}`);
|
|
57
|
+
console.log(` Animated: ${track.animated}`);
|
|
58
|
+
if (track.animated) {
|
|
59
|
+
console.log(
|
|
60
|
+
` Loop count: ${track.repetitionCount === Infinity ? 'infinite' : track.repetitionCount}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Decode each frame
|
|
65
|
+
console.log(`\nFrames:`);
|
|
66
|
+
for (let i = 0; i < track.frameCount; i++) {
|
|
67
|
+
const { image, complete } = await decoder.decode({ frameIndex: i });
|
|
68
|
+
|
|
69
|
+
console.log(
|
|
70
|
+
` Frame ${i}: ${image.codedWidth}x${image.codedHeight}, ` +
|
|
71
|
+
`format: ${image.format}, ` +
|
|
72
|
+
`duration: ${(image.duration || 0) / 1000}ms`
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
image.close();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
decoder.close();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main() {
|
|
82
|
+
console.log('=== Image Decoding Example ===');
|
|
83
|
+
|
|
84
|
+
// Check if ImageDecoder supports various formats
|
|
85
|
+
const formats = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif'];
|
|
86
|
+
|
|
87
|
+
console.log('\nSupported formats:');
|
|
88
|
+
for (const format of formats) {
|
|
89
|
+
const supported = await ImageDecoder.isTypeSupported(format);
|
|
90
|
+
console.log(` ${format}: ${supported ? 'yes' : 'no'}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Try to decode sample images if they exist
|
|
94
|
+
const samplePaths = [
|
|
95
|
+
'/tmp/webcodecs-test-images/test.png',
|
|
96
|
+
'/tmp/webcodecs-test-images/test.gif',
|
|
97
|
+
'/tmp/webcodecs-test-images/test.webp',
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
for (const path of samplePaths) {
|
|
101
|
+
if (existsSync(path)) {
|
|
102
|
+
await decodeImage(path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If no sample images, create a simple PNG in memory
|
|
107
|
+
if (!samplePaths.some(existsSync)) {
|
|
108
|
+
console.log('\nNo sample images found. Creating a test image in memory...');
|
|
109
|
+
|
|
110
|
+
// Minimal valid PNG (1x1 red pixel)
|
|
111
|
+
const minimalPng = Buffer.from([
|
|
112
|
+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, // PNG signature
|
|
113
|
+
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, // IHDR chunk
|
|
114
|
+
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
|
115
|
+
0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
|
|
116
|
+
0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, // IDAT chunk
|
|
117
|
+
0x54, 0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0x00,
|
|
118
|
+
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x18, 0xdd,
|
|
119
|
+
0x8d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, // IEND chunk
|
|
120
|
+
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
const decoder = new ImageDecoder({
|
|
124
|
+
type: 'image/png',
|
|
125
|
+
data: minimalPng,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await decoder.completed;
|
|
129
|
+
|
|
130
|
+
const track = decoder.tracks.selectedTrack;
|
|
131
|
+
console.log(`\nDecoded in-memory PNG:`);
|
|
132
|
+
console.log(` Frames: ${track?.frameCount}`);
|
|
133
|
+
|
|
134
|
+
if (track && track.frameCount > 0) {
|
|
135
|
+
const { image } = await decoder.decode({ frameIndex: 0 });
|
|
136
|
+
console.log(` Size: ${image.codedWidth}x${image.codedHeight}`);
|
|
137
|
+
console.log(` Format: ${image.format}`);
|
|
138
|
+
image.close();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
decoder.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
main().catch(console.error);
|