Media Cloud Upload
Context: $ARGUMENTS
Quick start
- Cloudflare Stream (fast, HLS+DASH auto): → Step 3a
- Mux Video (signed URL, pro API): → Step 3b
- Bunny Stream (cheap CDN): → Step 3c
- AWS S3 + CloudFront (DIY): → Step 3d
- YouTube (OAuth required): → Step 3e
- Vimeo (tus via PyVimeo): → Step 3f
- rclone to any cloud (Drive/OneDrive/B2/...): → Step 3g
When to use
- Finished ffmpeg encode needs adaptive-bitrate delivery (Cloudflare Stream / Mux).
- Raw MP4 needs to sit on a CDN with a URL (S3 + CloudFront, Bunny).
- Publishing to a consumer video platform (YouTube, Vimeo).
- Backup, archive, or sync media to arbitrary cloud storage (rclone).
Step 1 — Pick a service and gather credentials
| Service | Env vars | Notes |
|--------------------|----------------------------------------------|-------------------------------------|
| Cloudflare Stream | CF_TOKEN, CF_ACCOUNT_ID | API token with Stream:Edit |
| Mux | MUX_TOKEN, MUX_SECRET | Access-token pair (Basic Auth) |
| Bunny Stream | BUNNY_KEY, BUNNY_LIB_ID | Library-level AccessKey |
| AWS S3 | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY | Or ~/.aws/credentials |
| YouTube Data API | OAuth 2.0 client JSON + stored refresh token | Upload costs 1600 quota units |
| Vimeo | VIMEO_TOKEN | Personal access token, upload scope |
| rclone | rclone config remote | Token stored in ~/.config/rclone |
Never commit tokens. Read from env only. Rotate leaked tokens immediately.
Step 2 — Install SDK / CLI
# Universal: curl (present), rclone, aws CLI
brew install curl rclone awscli # macOS
# YouTube + Vimeo
pip install google-api-python-client google-auth-oauthlib PyVimeo
# Resumable uploads (Cloudflare Stream / Vimeo TUS)
pip install tuspy
Check everything with:
uv run ${CLAUDE_SKILL_DIR}/scripts/cloud.py check
Step 3 — Upload
3a. Cloudflare Stream
Direct upload (≤ 200 MB):
curl -X POST -H "Authorization: Bearer $CF_TOKEN" \
-F "file=@video.mp4" \
"https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/stream"
TUS resumable (any size, required > 200 MB):
# 1. Create upload URL
curl -X POST -H "Authorization: Bearer $CF_TOKEN" \
-H "Tus-Resumable: 1.0.0" \
-H "Upload-Length: $(stat -f%z video.mp4)" \
-H "Upload-Metadata: name $(echo -n video.mp4 | base64)" \
"https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/stream?direct_user=true" -D -
# 2. Then PATCH the returned Location with tus-js-client or `tuspy`
Response includes uid; playback URLs:
https://customer-<code>.cloudflarestream.com/<uid>/manifest/video.m3u8 # HLS
https://customer-<code>.cloudflarestream.com/<uid>/manifest/video.mpd # DASH
https://customer-<code>.cloudflarestream.com/<uid>/downloads/default.mp4 # MP4
https://customer-<code>.cloudflarestream.com/<uid>/thumbnails/thumbnail.jpg
3b. Mux Video
# 1. Create direct upload slot
curl -X POST -u $MUX_TOKEN:$MUX_SECRET \
-H "Content-Type: application/json" \
-d '{"new_asset_settings":{"playback_policy":["public"]},"cors_origin":"*"}' \
https://api.mux.com/video/v1/uploads
# Response → .data.url
# 2. PUT the file to that signed URL
curl -X PUT --data-binary @video.mp4 "$SIGNED_URL"
# 3. Poll upload → asset_id → playback_ids[0].id
Playback: https://stream.mux.com/<playback_id>.m3u8, thumbnail https://image.mux.com/<playback_id>/thumbnail.jpg.
3c. Bunny Stream
# 1. Create video shell
curl -X POST -H "AccessKey: $BUNNY_KEY" -H "Content-Type: application/json" \
-d '{"title":"My Clip"}' \
"https://video.bunnycdn.com/library/$BUNNY_LIB_ID/videos"
# Response → .guid (VIDEO_ID)
# 2. Upload bytes
curl -X PUT -H "AccessKey: $BUNNY_KEY" --upload-file video.mp4 \
"https://video.bunnycdn.com/library/$BUNNY_LIB_ID/videos/$VIDEO_ID"
Playback: https://iframe.mediadelivery.net/embed/$BUNNY_LIB_ID/$VIDEO_ID or HLS at https://vz-<hash>.b-cdn.net/$VIDEO_ID/playlist.m3u8.
3d. AWS S3 + CloudFront
aws s3 cp video.mp4 s3://my-bucket/videos/clip.mp4 \
--content-type video/mp4 --acl public-read --cache-control "max-age=31536000"
Pre-signed URL for private buckets:
aws s3 presign s3://my-bucket/videos/clip.mp4 --expires-in 3600
CloudFront: create a distribution with the bucket as origin, enable CORS, use the CloudFront URL (https://d12345.cloudfront.net/videos/clip.mp4).
3e. YouTube Data API v3
Requires OAuth 2.0 (installed-app flow). Run once with the user present to get a refresh token; subsequent runs are silent:
uv run ${CLAUDE_SKILL_DIR}/scripts/cloud.py youtube \
--file video.mp4 --title "My Title" --description "desc" \
--tags demo,ffmpeg --privacy unlisted
Uses googleapiclient.http.MediaFileUpload with resumable chunked upload.
3f. Vimeo
import vimeo, os
v = vimeo.VimeoClient(token=os.environ["VIMEO_TOKEN"])
uri = v.upload("video.mp4", data={"name": "Clip", "description": "..."})
print(v.get(uri + "?fields=link,player_embed_url").json())
PyVimeo uses TUS under the hood and resumes automatically.
3g. rclone (any cloud)
rclone config # one-time setup
rclone copy --progress video.mp4 gdrive:videos/ # upload
rclone link gdrive:videos/video.mp4 # get public URL (providers that support it)
rclone mount gdrive: /mnt/gdrive # stream-mount for ffmpeg to read directly
Supports Google Drive, OneDrive, Dropbox, Backblaze B2, S3, R2, Azure Blob, FTP, SFTP, WebDAV, and many more behind one CLI.
Step 4 — Verify and get playback URL
curl -I <playback_url>— expect200and a video content-type (orapplication/vnd.apple.mpegurlfor HLS).- Drop the URL into
ffplayormpvto smoke-test playback. - For HLS manifests, check that both master + variant playlists load:
```bash
curl -s "$PLAYBACK_URL" | head -40
```
- For Mux / Cloudflare Stream, poll the API until
status: readybefore sharing the link — the upload returns before the transcode finishes. - Register a webhook (Mux → Settings → Webhooks; Cloudflare → Stream webhooks) to avoid polling in production.
Available scripts
scripts/cloud.py— unified CLI:check,cloudflare-stream,mux,bunny,s3,rclone,youtube,vimeo. Stdlib + systemcurl/rclone/aws.--dry-runprints the command,--verbosedumps full JSON.