Stream - Media Transformations binding for Workers
Key Points
- Workers binding for Media Transformations
- Transforms videos from private sources (R2)
- Supports video, frame, spritesheet, audio outputs
Summary
Cloudflare Stream released a Media Transformations binding for Workers (2026-03-18). Engineers can call env.MEDIA from a Worker to transform videos stored anywhere — including private R2 buckets — to resize/crop, extract frames or audio, and output optimized assets back to storage.
Key Points
-
Add a Media binding to your Wrangler config (JSON or TOML) and reference it as the binding name in Workers.
{ "$schema": "./node_modules/wrangler/config-schema.json", "media": { "binding": "MEDIA" } }
[media] binding = "MEDIA"
-
Typical Worker flow:
- Read source video (e.g., env.R2_BUCKET.get("input.mp4")).
- Pass the body to the binding: env.MEDIA.input(video.body).transform({...}).output({...}).
- Return result.response() or write the output back to R2 for reuse.
-
Example call pattern (JS/TS): env.MEDIA.input(video.body).transform({width:480,height:270}).output({mode:"video",duration:"5s"}).response()
-
Supported output modes: video (MP4 clips), frame (single still), spritesheet (multiple frames), audio (M4A extraction).
-
Common uses: optimize videos for delivery, extract still frames for Workers AI classification, extract audio for transcription, and store transformed outputs to R2.
Next steps
- Add the binding to your Wrangler config, wire env.MEDIA in your Worker, and test transforms against an R2 or other private source.
Key docs
- See the Media Transformations binding documentation for full API options and examples.