Skip to content
Cloudflare Docs

Changelog

New updates and improvements at Cloudflare.

hero image

Media Transformations binding for Workers

You can now use a Workers binding to transform videos with Media Transformations. This allows you to resize, crop, extract frames, and extract audio from videos stored anywhere, even in private locations like R2 buckets.

The Media Transformations binding is useful when you want to:

  • Transform videos stored in private or protected sources
  • Optimize videos and store the output directly back to R2 for re-use
  • Extract still frames for classification or description with Workers AI
  • Extract audio tracks for transcription using Workers AI

To get started, add the Media binding to your Wrangler configuration:

{
"$schema": "./node_modules/wrangler/config-schema.json",
"media": {
"binding": "MEDIA"
}
}

Then use the binding in your Worker to transform videos:

JavaScript
export default {
async fetch(request, env) {
const video = await env.R2_BUCKET.get("input.mp4");
const result = env.MEDIA.input(video.body)
.transform({ width: 480, height: 270 })
.output({ mode: "video", duration: "5s" });
return await result.response();
},
};

Output modes include video for optimized MP4 clips, frame for still images, spritesheet for multiple frames, and audio for M4A extraction.

For more information, refer to the Media Transformations binding documentation.