Cloudflare Workers adds Media Transformations binding for video processing
Media Transformations Binding for Workers
Cloudflare has introduced a new Media Transformations binding for Workers, allowing developers to perform video operations within their serverless applications. This binding provides a simple API to transform videos stored in any location, including private sources like R2 buckets.
Key Capabilities
The binding supports multiple transformation operations:
- Video Processing: Resize and crop videos with configurable dimensions
- Frame Extraction: Extract still frames for classification or analysis
- Audio Extraction: Pull audio tracks from videos (M4A format)
- Spritesheet Generation: Create multiple frames in a single output
Getting Started
To use the Media Transformations binding, add it to your wrangler.toml or wrangler.jsonc:
[media]
binding = "MEDIA"
Then access it in your Worker code:
const result = env.MEDIA.input(video.body)
.transform({ width: 480, height: 270 })
.output({ mode: "video", duration: "5s" });
Use Cases
Developers can leverage this binding for:
- Protected Content Processing: Transform videos stored in private locations without exposing them
- Video Optimization: Resize and compress videos before storing them back to R2 for reuse
- AI Integration: Extract frames for Workers AI vision models or audio for transcription services
Output Formats
The binding supports multiple output modes: video for optimized MP4 clips, frame for single still images, spritesheet for batched frame output, and audio for M4A audio extraction.