All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Stream - Media Transformations binding for Workers

3mo ago

Source

CloudflareStream - Media Transformations binding for Workerscloudflare.com
Snippet from the RSS feed
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: wrangler.jsonc { " $schema " : "./node_modules/wrangler/config-schema.json" , " media " : { " binding " : "MEDIA" } } wrangler.toml [ 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 () ; }, }; TypeScript 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 .

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.