A high-performance, GPU-accelerated video processing library for web applications. Built with WebGPU and WebGL2 fallback support.
WebGPU Video Processor is an open-source library that enables efficient video processing directly in the browser using modern GPU acceleration. It provides a simple API for common video processing tasks while leveraging the power of WebGPU (with WebGL2 fallback) for optimal performance.
- π GPU-accelerated video processing
- π¨ Easy-to-use API for common video effects
- π Automatic WebGL2 fallback for broader browser support
- π― High-performance frame processing
- π οΈ Extensible architecture for custom effects
- π¦ Zero dependencies
- Core GPU operations implemented
- WebGL2 fallback support
- Comprehensive test coverage
- Cross-browser compatibility
- GPU testing utilities
- Logo overlay on videos
- Caption burning
- Background image compositing
- Layout transformations
- Color space conversions
- Frame rate handling
- Real-time video effects
The library is built with a layered architecture:
- Core Layer: Handles GPU initialization and resource management
- Processing Layer: Implements video processing algorithms
- Effects Layer: Provides pre-built effects and transformations
- API Layer: Exposes a simple, developer-friendly interface
- Primary: WebGPU (Modern GPU API)
- Fallback: WebGL2
- Language: TypeScript
- Build Tool: Vite
- Minimizes CPU/GPU memory copies
- Leverages GPU parallelization
- Efficient resource management
- Automatic format conversion optimization
interface VideoProcessorOptions {
width: number;
height: number;
debug?: boolean;
}
class VideoProcessor {
constructor(options: VideoProcessorOptions);
async checkGPUSupport(): Promise<boolean>;
async destroy(): Promise<void>;
}
webgpu-video-processor/
βββ src/
β βββ core/ # Core GPU operations
β βββ utils/ # Utility functions
β βββ types/ # TypeScript definitions
βββ tests/
β βββ unit/ # Jest tests
β βββ e2e/ # Playwright tests
βββ .github/ # GitHub Actions
βββ docs/ # Documentation
- π GPU-accelerated video processing using WebGPU
- π Automatic WebGL2 fallback for broader browser support
- π¨ Real-time video effects and filters
- π¦ Zero dependencies
- π Comprehensive test coverage
- π± Cross-browser compatibility
npm install webgpu-video-processor
import { VideoProcessor } from 'webgpu-video-processor';
// Initialize the video processor
const processor = new VideoProcessor({
width: 1920,
height: 1080,
useWebGPU: true // Automatically falls back to WebGL2 if WebGPU is not available
});
// Process a video frame
const outputTexture = await processor.processFrame(inputTexture);
// Apply effects
await processor.applyEffect('blur', { radius: 5 });
await processor.applyEffect('colorAdjust', { brightness: 1.2 });
- Chrome/Chromium 113+: WebGPU support (primary)
- Edge 113+: WebGPU support
- Firefox: WebGL2 fallback
- Safari 16.4+: WebGL2 fallback
- Node.js 20 or higher
- npm 9 or higher
- Modern web browser with WebGPU support
- Clone the repository:
git clone https://github.com/yourusername/webgpu-video-processor.git
cd webgpu-video-processor
- Install dependencies:
npm install
- Start development server:
npm run dev
npm test # Run all unit tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run test:e2e # Run all E2E tests
npm run test:e2e:ui # Run E2E tests with UI
npm run test:e2e:debug # Run E2E tests in debug mode
npm run build
The build output will be available in the dist
directory.
The main class for video processing operations.
interface VideoProcessorOptions {
width: number;
height: number;
useWebGPU?: boolean; // Default: true
fallbackToWebGL2?: boolean; // Default: true
}
processFrame(inputTexture: GPUTexture): Promise<GPUTexture>
applyEffect(effectName: string, options: EffectOptions): Promise<void>
destroy(): void
blur
: Gaussian blur effectcolorAdjust
: Color adjustment (brightness, contrast, saturation)edgeDetection
: Edge detection filtersharpen
: Image sharpeningdenoise
: Noise reduction
import { VideoProcessor } from 'webgpu-video-processor';
const video = document.querySelector('video');
const canvas = document.querySelector('canvas');
const processor = new VideoProcessor({
width: video.videoWidth,
height: video.videoHeight
});
// Process video frames
video.addEventListener('play', async () => {
while (!video.paused) {
const frame = await processor.processFrame(video);
processor.renderToCanvas(frame, canvas);
await new Promise(resolve => requestAnimationFrame(resolve));
}
});
// Apply multiple effects
await processor.applyEffect('blur', { radius: 3 });
await processor.applyEffect('colorAdjust', {
brightness: 1.1,
contrast: 1.2,
saturation: 1.1
});
await processor.applyEffect('sharpen', { amount: 0.5 });
// Create a custom effect
processor.registerEffect('customEffect', {
shader: `
@vertex
fn vertexMain(@location(0) position: vec2f) -> @builtin(position) vec4f {
return vec4f(position, 0.0, 1.0);
}
@fragment
fn fragmentMain(@location(0) uv: vec2f) -> @location(0) vec4f {
return vec4f(uv.x, uv.y, 0.0, 1.0);
}
`,
uniforms: {
intensity: { type: 'float', default: 1.0 }
}
});
- Project setup
- Basic GPU operations
- Testing infrastructure
- CI/CD pipeline
- Video frame processing
- Basic effects pipeline
- Performance optimization
- WebGL2 fallback improvements
- Custom shader support
- Advanced video effects
- Real-time processing
- Performance monitoring
-
WebGPU Not Available
- Ensure you're using a supported browser
- Check if hardware acceleration is enabled
- Try using WebGL2 fallback
-
Performance Issues
- Monitor GPU memory usage
- Check for unnecessary texture copies
- Optimize shader complexity
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
- WebGPU Working Group
- WebGL Working Group
- Contributors and maintainers
For support, please open an issue in the GitHub repository.