OpenAICloudflare Developer PlatformMar 18, 2026, 12:00 AM

Stream - Media Transformations binding for Workers

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

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:

    1. Read source video (e.g., env.R2_BUCKET.get("input.mp4")).
    2. Pass the body to the binding: env.MEDIA.input(video.body).transform({...}).output({...}).
    3. 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.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

Stream - Workers の Media Transformations バインディング

Stream - Workers の Media Transformations バインディング

公開日: 2026-03-18 カテゴリ: Stream

Cloudflare の Media Transformations バインディングを Workers で使用できるようになりました。これにより、R2 バケットなどのプライベートな場所に保存された動画でも、リサイズ、クロップ、フレーム抽出、オーディオ抽出といった変換が可能になります。

主な利用シーン

  • プライベートまたは保護されたソースに保存された動画の変換
  • 動画を最適化して、出力を R2 に直接保存して再利用
  • Workers AI と組み合わせて、分類や説明のために静止フレームを抽出
  • Workers AI を使った文字起こしのためにオーディオトラックを抽出

始め方

まず、Wrangler の設定に Media バインディングを追加します。

wrangler.jsonc の例:

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

wrangler.toml の例:

[media]
binding = "MEDIA"

その後、Worker 内でバインディングを使って動画を変換します。

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();
  },
};

出力モード

  • video — 最適化された MP4 クリップ
  • frame — 静止画像
  • spritesheet — 複数フレームのスプライトシート
  • audio — M4A の抽出

詳細は Media Transformations binding documentation を参照してください。