payload-video-streaming 0.2.0-beta.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -543
- package/dist/access.d.ts +35 -0
- package/dist/access.js +53 -0
- package/dist/access.js.map +1 -0
- package/dist/bin/args.d.ts +13 -0
- package/dist/bin/args.js +61 -0
- package/dist/bin/args.js.map +1 -1
- package/dist/bin/cli.js +9 -1
- package/dist/bin/cli.js.map +1 -1
- package/dist/bin/webhooks.d.ts +15 -0
- package/dist/bin/webhooks.js +149 -0
- package/dist/bin/webhooks.js.map +1 -0
- package/dist/collection.js +148 -1
- package/dist/collection.js.map +1 -1
- package/dist/components/BulkUploader.d.ts +16 -0
- package/dist/components/BulkUploader.js +226 -0
- package/dist/components/BulkUploader.js.map +1 -0
- package/dist/components/ListUploader.js +22 -0
- package/dist/components/ListUploader.js.map +1 -1
- package/dist/components/Uploader.d.ts +5 -0
- package/dist/components/Uploader.js +13 -4
- package/dist/components/Uploader.js.map +1 -1
- package/dist/components/VideoField.js +9 -5
- package/dist/components/VideoField.js.map +1 -1
- package/dist/components/VideoRelationshipField.d.ts +16 -0
- package/dist/components/VideoRelationshipField.js +106 -0
- package/dist/components/VideoRelationshipField.js.map +1 -0
- package/dist/components/WebhookStatusPanel.d.ts +6 -0
- package/dist/components/WebhookStatusPanel.js +143 -0
- package/dist/components/WebhookStatusPanel.js.map +1 -0
- package/dist/components/api.d.ts +7 -1
- package/dist/components/api.js +2 -0
- package/dist/components/api.js.map +1 -1
- package/dist/components/uploadFile.d.ts +30 -0
- package/dist/components/uploadFile.js +140 -0
- package/dist/components/uploadFile.js.map +1 -0
- package/dist/components/usePluginApi.d.ts +5 -0
- package/dist/components/useUploadQueue.d.ts +35 -0
- package/dist/components/useUploadQueue.js +135 -0
- package/dist/components/useUploadQueue.js.map +1 -0
- package/dist/components/useVideoUpload.d.ts +3 -7
- package/dist/components/useVideoUpload.js +29 -123
- package/dist/components/useVideoUpload.js.map +1 -1
- package/dist/core/provider.d.ts +16 -0
- package/dist/core/provider.js.map +1 -1
- package/dist/endpoints/index.js +38 -2
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/client.d.ts +9 -0
- package/dist/exports/client.js +5 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/react.d.ts +12 -0
- package/dist/exports/react.js +7 -0
- package/dist/exports/react.js.map +1 -1
- package/dist/fields.d.ts +11 -2
- package/dist/fields.js +62 -2
- package/dist/fields.js.map +1 -1
- package/dist/frontend/VideoUploader.d.ts +65 -0
- package/dist/frontend/VideoUploader.js +260 -0
- package/dist/frontend/VideoUploader.js.map +1 -0
- package/dist/frontend/useVideoStatus.d.ts +26 -0
- package/dist/frontend/useVideoStatus.js +68 -0
- package/dist/frontend/useVideoStatus.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +7 -2
- package/dist/options.js +65 -2
- package/dist/options.js.map +1 -1
- package/dist/plugin.js +80 -1
- package/dist/plugin.js.map +1 -1
- package/dist/providers/bunny/provider.d.ts +2 -1
- package/dist/providers/bunny/provider.js +8 -0
- package/dist/providers/bunny/provider.js.map +1 -1
- package/dist/providers/cloudflare/provider.d.ts +2 -1
- package/dist/providers/cloudflare/provider.js +11 -0
- package/dist/providers/cloudflare/provider.js.map +1 -1
- package/dist/providers/mux/provider.d.ts +2 -1
- package/dist/providers/mux/provider.js +9 -0
- package/dist/providers/mux/provider.js.map +1 -1
- package/dist/service.d.ts +28 -1
- package/dist/service.js +114 -4
- package/dist/service.js.map +1 -1
- package/dist/types.d.ts +155 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,95 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>payload-video-streaming</h1>
|
|
3
|
+
<p><strong>Video for Payload CMS, from upload to playback.</strong></p>
|
|
4
|
+
<p>Upload straight to Cloudflare Stream, Mux or Bunny Stream, follow encoding in the admin,<br>and play videos on your site with any player. One plugin for Payload 3 and 4.</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<a href="https://www.npmjs.com/package/payload-video-streaming"><img src="https://img.shields.io/npm/v/payload-video-streaming.svg" alt="npm"></a>
|
|
7
|
+
<a href="https://github.com/BarakChamo/payload-video-streaming/actions/workflows/ci.yml"><img src="https://github.com/BarakChamo/payload-video-streaming/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
8
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
|
|
9
|
+
<img src="https://img.shields.io/badge/Payload-3%20%7C%204-black" alt="Payload 3 and 4">
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
<p>
|
|
12
|
+
<a href="#quick-start">Quick start</a> •
|
|
13
|
+
<a href="#providers">Providers</a> •
|
|
14
|
+
<a href="#features">Features</a> •
|
|
15
|
+
<a href="#documentation">Docs</a> •
|
|
16
|
+
<a href="./examples">Examples</a> •
|
|
17
|
+
<a href="./CHANGELOG.md">Changelog</a>
|
|
18
|
+
</p>
|
|
19
|
+
</div>
|
|
6
20
|
|
|
7
|
-
|
|
8
|
-
| --- | --- | --- |
|
|
9
|
-
| [Cloudflare Stream](https://developers.cloudflare.com/stream/) | `payload-video-streaming/cloudflare` | Available |
|
|
10
|
-
| [Mux](https://www.mux.com/) | `payload-video-streaming/mux` | Available ([guide](./docs/providers/mux.md)) |
|
|
11
|
-
| [Bunny Stream](https://bunny.net/stream/) | `payload-video-streaming/bunny` | Available ([guide](./docs/providers/bunny.md)) |
|
|
12
|
-
|
|
13
|
-
What each provider supports. The admin shows only what the document's provider can do, and endpoints for unsupported features answer `501`:
|
|
14
|
-
|
|
15
|
-
| | Cloudflare Stream | Mux | Bunny Stream |
|
|
16
|
-
| --- | --- | --- | --- |
|
|
17
|
-
| Browser upload | POST (≤200 MB) or tus | resumable chunked PUT | tus, signed by your server |
|
|
18
|
-
| Import by URL, server upload, adopt existing | ✓ | ✓ | ✓ |
|
|
19
|
-
| Encoding progress | ✓ | ✓ (while transcoding) | ✓ |
|
|
20
|
-
| Signed playback | per video | per video (playback ID swap) | library-wide (embed and CDN tokens) |
|
|
21
|
-
| Per-video allowed origins | ✓ | — (environment playback restrictions) | — (library referrers) |
|
|
22
|
-
| Poster time | ✓ | ✓ | at creation only |
|
|
23
|
-
| Captions | upload, AI (12 languages) | upload, AI (22 languages + auto) | upload, AI transcription |
|
|
24
|
-
| Downloads | MP4 and audio, per video | MP4 and audio, per video | MP4 fallback, library-wide |
|
|
25
|
-
| HLS / DASH | ✓ / ✓ | ✓ / — | ✓ / — |
|
|
26
|
-
| Webhooks | ✓ | ✓ | ✓ (signed with the library's Read-Only key) |
|
|
27
|
-
|
|
28
|
-
A streaming provider is not file storage. It ingests a video, encodes it, and serves it as adaptive HLS (and, on Cloudflare, DASH) with a player, thumbnails, captions and downloads, optionally behind signed tokens. This plugin connects Payload to that workflow, with the same collection, admin UI, block and frontend API for every provider:
|
|
29
|
-
|
|
30
|
-
- **A `videos` collection.** Each document is backed by a provider asset. Status, duration and dimensions are kept in sync. Each document records its provider, so several providers can be configured at once.
|
|
31
|
-
- **Direct-from-browser uploads.** Bytes never pass through your server. The provider picks the protocol: a single POST, a resumable **tus** upload or chunked PUTs, with pause and resume where the protocol allows. `tus-js-client` is only loaded when a tus upload starts.
|
|
32
|
-
- **Admin UI:**
|
|
33
|
-
- drag and drop upload with progress
|
|
34
|
-
- live processing status
|
|
35
|
-
- an embedded player
|
|
36
|
-
- "Replace video"
|
|
37
|
-
- an import-from-URL button
|
|
38
|
-
- list thumbnails
|
|
39
|
-
- caption management (upload `.vtt` or generate with AI)
|
|
40
|
-
- MP4 and audio download toggles
|
|
41
|
-
|
|
42
|
-
Panels appear only when the document's provider supports them.
|
|
43
|
-
- **Video blocks and any player.** A video block for layout builders and Lexical rich text, plus `payload-video-streaming/react` to render videos with the provider's player or any HLS player you like. See [Using videos in your content](#using-videos-in-your-content).
|
|
44
|
-
- **Playback URLs everywhere.** A virtual `playback` field adds HLS, iframe, thumbnail (and, on Cloudflare, DASH and watch) URLs to every REST, GraphQL and Local API read, including through relationships.
|
|
45
|
-
- **Signed playback and private videos.** Turn on `signedPlayback` per video. Tokens are signed locally when the provider has a signing key, and outlast the video so they never expire mid-playback. A `playback` access hook decides who receives them.
|
|
46
|
-
- **Webhooks are optional.** Signed notifications update documents the moment encoding finishes. Without them, the admin UI polls while a video is open, and a built-in **sync-pending** job (or `POST /sync-pending` from any cron) settles everything else. See [Keeping status in sync](#keeping-status-in-sync).
|
|
47
|
-
- **Adopt an existing library.** `adoptExisting()` creates documents for assets already in your provider account.
|
|
48
|
-
- **Import by URL and a server API**, for example `getVideo(payload).uploadFile(buffer)`.
|
|
49
|
-
- **Two-way sync.** Editing `signedPlayback`, `allowedOrigins`, the poster time, the title or `meta` in Payload pushes the change to the provider. Deleting a document deletes the asset.
|
|
50
|
-
- **Database-agnostic.** Works with the SQLite, Postgres and MongoDB adapters and only uses portable field types. Every nested write passes `req`, so it joins your transaction.
|
|
51
|
-
- **Easy local development.** A built-in **fake provider server** lets you develop and test without an account, containers or network access.
|
|
52
|
-
- **Small install.** Providers are called through their REST APIs with `fetch`. No provider SDK is installed in your app; the only runtime dependency is `tus-js-client`.
|
|
53
|
-
|
|
54
|
-
> **Examples:** see [`examples/`](./examples) for video blocks, frontend pages, bring-your-own players, private members-only videos, webhook-free sync, custom upload UIs, server scripts and testing with the fake server.
|
|
55
|
-
|
|
56
|
-
> **Coming from `payload-cf-stream`?** This package is its successor. See [Migrating from payload-cf-stream](./docs/migrating-from-payload-cf-stream.md).
|
|
57
|
-
|
|
58
|
-
> The plugin has been tested against Payload `4.0.0-beta.12` and `3.94.2`, on SQLite, Postgres and MongoDB. See [TESTING.md](./TESTING.md).
|
|
21
|
+
## Why payload-video-streaming
|
|
59
22
|
|
|
60
|
-
|
|
23
|
+
- **One `videos` collection, any provider.** Cloudflare Stream, Mux and Bunny Stream behind the same fields, admin and API. Configure one or several.
|
|
24
|
+
- **Uploads skip your server.** Files go from the browser straight to the provider, large ones resume after interruptions, and editors can upload many at once.
|
|
25
|
+
- **A real admin for video.** Upload, processing status, preview, replace, import from URL, captions (uploaded or AI) and downloads. Editors can also upload straight from any video field.
|
|
26
|
+
- **Play it anywhere.** React components for video fields, blocks and rich text, with the provider's player or yours (hls.js, Video.js, Vidstack, Mux Player…).
|
|
27
|
+
- **Public or private.** Visitors watch the videos your pages embed. Signed playback and access hooks decide who sees private ones.
|
|
28
|
+
- **Member uploads.** Let your site's users upload, with ownership, review before publishing, limits and a drop-in form.
|
|
29
|
+
- **Light.** Providers are called over REST with `fetch`: no SDKs at runtime. A built-in fake provider lets you build and test without an account.
|
|
61
30
|
|
|
62
|
-
|
|
31
|
+
> **Coming from `payload-cf-stream`?** This is its successor. See [Migrating from payload-cf-stream](./docs/migrating-from-payload-cf-stream.md).
|
|
63
32
|
|
|
64
|
-
##
|
|
33
|
+
## Quick start
|
|
65
34
|
|
|
66
|
-
|
|
67
|
-
| --- | --- |
|
|
68
|
-
| Payload | `^3.94.0` or `^4.0.0-beta.12` (the same package works for both) |
|
|
69
|
-
| Node | Whatever your Payload version requires (v4: `^24.22.3 \|\| >=26.13.1`) |
|
|
70
|
-
| A provider account | **Cloudflare Stream**: Stream enabled and an API token. **Mux**: an environment and an access token (Mux Video read + write). **Bunny Stream**: a video library and its API key |
|
|
35
|
+
You need Payload `^3.94.0` or `^4.0.0-beta.12` and an account with one of the providers.
|
|
71
36
|
|
|
72
|
-
|
|
37
|
+
**1. Install**
|
|
73
38
|
|
|
74
39
|
```bash
|
|
75
|
-
npm install payload-video-streaming
|
|
40
|
+
npm install payload-video-streaming
|
|
76
41
|
```
|
|
77
42
|
|
|
43
|
+
**2. Add the plugin and a provider.** This uses Cloudflare Stream; [Mux and Bunny](#providers) work the same way.
|
|
44
|
+
|
|
78
45
|
```ts
|
|
79
46
|
// payload.config.ts
|
|
80
47
|
import { buildConfig } from 'payload'
|
|
81
|
-
import { videoPlugin } from 'payload-video-streaming'
|
|
48
|
+
import { videoField, videoPlugin } from 'payload-video-streaming'
|
|
82
49
|
import { cloudflareStream } from 'payload-video-streaming/cloudflare'
|
|
83
50
|
|
|
84
51
|
export default buildConfig({
|
|
85
|
-
|
|
52
|
+
collections: [
|
|
53
|
+
{ slug: 'posts', fields: [{ name: 'title', type: 'text' }, videoField({ name: 'heroVideo' })] },
|
|
54
|
+
],
|
|
86
55
|
plugins: [
|
|
87
56
|
videoPlugin({
|
|
88
57
|
providers: [
|
|
89
58
|
cloudflareStream({
|
|
90
59
|
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
|
|
91
60
|
apiToken: process.env.CLOUDFLARE_STREAM_API_TOKEN!,
|
|
92
|
-
webhook: { secret: process.env.CLOUDFLARE_STREAM_WEBHOOK_SECRET },
|
|
93
61
|
}),
|
|
94
62
|
],
|
|
95
63
|
}),
|
|
@@ -97,563 +65,226 @@ export default buildConfig({
|
|
|
97
65
|
})
|
|
98
66
|
```
|
|
99
67
|
|
|
100
|
-
|
|
68
|
+
Prefer environment variables? `videoPlugin(videoOptionsFromEnv())` configures every provider it finds ([variables](./docs/configuration.md#environment-variables)).
|
|
69
|
+
|
|
70
|
+
**3. Regenerate the admin import map**, so Payload finds the plugin's components:
|
|
101
71
|
|
|
102
72
|
```bash
|
|
103
73
|
npx payload generate:importmap
|
|
104
74
|
```
|
|
105
75
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
import { videoOptionsFromEnv, videoPlugin } from 'payload-video-streaming'
|
|
110
|
-
|
|
111
|
-
plugins: [videoPlugin(videoOptionsFromEnv({ cloudflare: { upload: { maxDurationSeconds: 1800 } } }))]
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Cloudflare setup
|
|
115
|
-
|
|
116
|
-
1. **Account ID.** Log in to the dashboard and pick the account. The 32-character hex string in the URL (`dash.cloudflare.com/<ACCOUNT_ID>/…`) is the account ID.
|
|
117
|
-
2. **Enable Stream** and buy storage minutes: **Media → Stream**. Uploads fail with error `10011 Storage capacity exceeded` until the account has storage minutes.
|
|
118
|
-
3. **API token.** Go to **My Profile → API Tokens → Create Custom Token** and set:
|
|
119
|
-
- Permissions: **Account · Stream · Edit**
|
|
120
|
-
- Account Resources: **Include → your account**
|
|
121
|
-
4. *Optional:* **Customer code.** This is the `XXXX` in `customer-XXXX.cloudflarestream.com`. The provider discovers it from API responses automatically, so you only need to set it to avoid an extra API call.
|
|
122
|
-
5. *Optional:* **Signing key** for signed URLs at scale. Run this once:
|
|
123
|
-
```bash
|
|
124
|
-
curl -X POST -H "Authorization: Bearer $TOKEN" \
|
|
125
|
-
https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/stream/keys
|
|
126
|
-
```
|
|
127
|
-
Store `result.id` and `result.pem` as `CLOUDFLARE_STREAM_SIGNING_KEY_ID` and `CLOUDFLARE_STREAM_SIGNING_KEY_PEM`. The base64 PEM can be used as returned. Cloudflare only shows the PEM once.
|
|
128
|
-
6. *Optional:* **Webhook.** Each account has **one** webhook URL. Register yours and keep the secret it returns:
|
|
129
|
-
```bash
|
|
130
|
-
curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
|
131
|
-
-d '{"notificationUrl":"https://your-site.com/api/videos/webhook/cloudflare"}' \
|
|
132
|
-
https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/stream/webhook
|
|
133
|
-
```
|
|
134
|
-
Set `result.secret` as `CLOUDFLARE_STREAM_WEBHOOK_SECRET`. Cloudflare can't call localhost. That's fine, because the admin UI polls for status during development.
|
|
135
|
-
|
|
136
|
-
## Mux setup
|
|
137
|
-
|
|
138
|
-
1. In the Mux dashboard, create an **access token** for your environment with **Mux Video: Read and Write** (add **System: Write** if you want the plugin's setup script to create a signing key).
|
|
139
|
-
2. *Optional, for signed playback:* create a **signing key** (Settings → Signing keys, or `examples/server-scripts/setup-mux.ts`) and keep its id and base64 private key. Without one, signed videos have no playback URLs, because Mux has no API that mints tokens.
|
|
140
|
-
3. *Optional:* add a **webhook** pointing at `https://your-site.com/api/videos/webhook/mux` and keep its signing secret.
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
import { muxVideo } from 'payload-video-streaming/mux'
|
|
144
|
-
|
|
145
|
-
videoPlugin({ providers: [muxVideo({ tokenId: process.env.MUX_TOKEN_ID!, tokenSecret: process.env.MUX_TOKEN_SECRET! })] })
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Details, limits and how signed playback works: [docs/providers/mux.md](./docs/providers/mux.md).
|
|
149
|
-
|
|
150
|
-
## Bunny Stream setup
|
|
151
|
-
|
|
152
|
-
1. Create a **video library** (Stream → Add video library). From its **API** page, note the **library ID**, the **API key** and the **CDN hostname** (`vz-….b-cdn.net`).
|
|
153
|
-
2. *Optional, for private videos:* turn on **embed view token authentication** (Security) and/or **CDN token authentication** on the library's pull zone, and pass the keys as `embedTokenKey` / `cdnTokenKey`. On Bunny this applies to the whole library, not per video.
|
|
154
|
-
3. *Optional:* set the library's **webhook URL** to `https://your-site.com/api/videos/webhook/bunny` and pass the library's **Read-Only API key** as `webhook.secret` (Bunny signs webhooks with it).
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
import { bunnyStream } from 'payload-video-streaming/bunny'
|
|
158
|
-
|
|
159
|
-
videoPlugin({
|
|
160
|
-
providers: [
|
|
161
|
-
bunnyStream({
|
|
162
|
-
libraryId: process.env.BUNNY_STREAM_LIBRARY_ID!,
|
|
163
|
-
apiKey: process.env.BUNNY_STREAM_API_KEY!,
|
|
164
|
-
cdnHostname: process.env.BUNNY_STREAM_CDN_HOSTNAME!,
|
|
165
|
-
}),
|
|
166
|
-
],
|
|
167
|
-
})
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Details, limits and library-wide settings: [docs/providers/bunny.md](./docs/providers/bunny.md).
|
|
171
|
-
|
|
172
|
-
## Environment variables
|
|
173
|
-
|
|
174
|
-
`videoOptionsFromEnv(overrides?, env?)` reads these and sets up every provider whose required variables are present. Anything passed in `overrides` wins; `overrides.cloudflare`, `overrides.mux` and `overrides.bunny` are merged into each provider's options, and `overrides.providers` replaces the detected providers.
|
|
175
|
-
|
|
176
|
-
**Core:**
|
|
177
|
-
|
|
178
|
-
| Variable | Option |
|
|
179
|
-
| --- | --- |
|
|
180
|
-
| `VIDEO_DEFAULT_PROVIDER` | `defaultProvider` |
|
|
181
|
-
| `VIDEO_SIGNED_PLAYBACK` (or `CLOUDFLARE_STREAM_REQUIRE_SIGNED_URLS`) | `upload.signedPlayback` |
|
|
182
|
-
| `VIDEO_TOKEN_TTL_SECONDS` (or `CLOUDFLARE_STREAM_TOKEN_TTL_SECONDS`) | `playback.expiresIn` |
|
|
183
|
-
| `VIDEO_SYNC_CRON` (or `CLOUDFLARE_STREAM_SYNC_CRON`) | `syncPendingTask.cron` (e.g. `*/5 * * * *`) |
|
|
184
|
-
|
|
185
|
-
**Cloudflare Stream** (configured when `CLOUDFLARE_ACCOUNT_ID` is set; `cloudflareOptionsFromEnv()` from `payload-video-streaming/cloudflare` reads the same variables):
|
|
186
|
-
|
|
187
|
-
| Variable | `cloudflareStream()` option |
|
|
188
|
-
| --- | --- |
|
|
189
|
-
| `CLOUDFLARE_ACCOUNT_ID` | `accountId` (required) |
|
|
190
|
-
| `CLOUDFLARE_STREAM_API_TOKEN` (or `CLOUDFLARE_API_TOKEN`) | `apiToken` (required) |
|
|
191
|
-
| `CLOUDFLARE_STREAM_CUSTOMER_CODE` | `customerCode` |
|
|
192
|
-
| `CLOUDFLARE_STREAM_DELIVERY_BASE_URL` | `deliveryBaseUrl` |
|
|
193
|
-
| `CLOUDFLARE_STREAM_API_BASE_URL` | `apiBaseUrl` |
|
|
194
|
-
| `CLOUDFLARE_STREAM_WEBHOOK_SECRET` | `webhook.secret` |
|
|
195
|
-
| `CLOUDFLARE_STREAM_SIGNING_KEY_ID` + `CLOUDFLARE_STREAM_SIGNING_KEY_PEM` (or `_JWK`) | `signingKey` |
|
|
196
|
-
| `CLOUDFLARE_STREAM_MAX_DURATION_SECONDS` | `upload.maxDurationSeconds` |
|
|
197
|
-
| `CLOUDFLARE_STREAM_DIRECT_UPLOAD_MAX_BYTES` | `upload.directUploadMaxBytes` |
|
|
198
|
-
| `CLOUDFLARE_STREAM_ALLOWED_ORIGINS` (comma-separated) | `upload.allowedOrigins` |
|
|
199
|
-
| `CLOUDFLARE_STREAM_WATERMARK_UID` | `upload.watermarkUID` |
|
|
200
|
-
|
|
201
|
-
**Mux** (configured when `MUX_TOKEN_ID` and `MUX_TOKEN_SECRET` are set; Mux's own variable names; `muxOptionsFromEnv()` from `payload-video-streaming/mux`):
|
|
202
|
-
|
|
203
|
-
| Variable | `muxVideo()` option |
|
|
204
|
-
| --- | --- |
|
|
205
|
-
| `MUX_TOKEN_ID` | `tokenId` (required) |
|
|
206
|
-
| `MUX_TOKEN_SECRET` | `tokenSecret` (required) |
|
|
207
|
-
| `MUX_SIGNING_KEY_ID` + `MUX_SIGNING_KEY_PRIVATE` | `signingKey` |
|
|
208
|
-
| `MUX_WEBHOOK_SECRET` | `webhook.secret` |
|
|
209
|
-
| `MUX_API_BASE_URL` | `apiBaseUrl` |
|
|
210
|
-
| `MUX_UPLOAD_CORS_ORIGIN` | `upload.corsOrigin` |
|
|
211
|
-
| `MUX_VIDEO_QUALITY` (`basic`, `plus`, `premium`) | `upload.videoQuality` |
|
|
212
|
-
| `MUX_UPLOAD_TIMEOUT_SECONDS` | `upload.timeoutSeconds` |
|
|
213
|
-
| `MUX_TEST_ASSETS` (`1`/`true`) | `upload.test` |
|
|
214
|
-
| `MUX_PLAYBACK_RESTRICTION_ID` | `playback.playbackRestrictionId` |
|
|
215
|
-
|
|
216
|
-
**Bunny Stream** (configured when `BUNNY_STREAM_LIBRARY_ID`, `BUNNY_STREAM_API_KEY` and `BUNNY_STREAM_CDN_HOSTNAME` are set; `bunnyOptionsFromEnv()` from `payload-video-streaming/bunny`):
|
|
217
|
-
|
|
218
|
-
| Variable | `bunnyStream()` option |
|
|
219
|
-
| --- | --- |
|
|
220
|
-
| `BUNNY_STREAM_LIBRARY_ID` | `libraryId` (required) |
|
|
221
|
-
| `BUNNY_STREAM_API_KEY` | `apiKey` (required) |
|
|
222
|
-
| `BUNNY_STREAM_CDN_HOSTNAME` | `cdnHostname` (required) |
|
|
223
|
-
| `BUNNY_STREAM_TOKEN_KEY` | `embedTokenKey` |
|
|
224
|
-
| `BUNNY_CDN_TOKEN_KEY` | `cdnTokenKey` |
|
|
225
|
-
| `BUNNY_STREAM_WEBHOOK_SECRET` (the library's Read-Only API key) | `webhook.secret` |
|
|
226
|
-
| `BUNNY_STREAM_COLLECTION_ID` | `collectionId` |
|
|
227
|
-
| `BUNNY_STREAM_API_BASE_URL` | `apiBaseUrl` |
|
|
228
|
-
|
|
229
|
-
## Options
|
|
76
|
+
Upload a video under **Videos** in the admin. It updates on its own while the provider processes it.
|
|
230
77
|
|
|
231
|
-
|
|
78
|
+
**4. Render it on your site:**
|
|
232
79
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
| `providers` | (required unless `disabled`) | The providers, e.g. `[cloudflareStream({ … })]`. Each needs a unique `id` |
|
|
236
|
-
| `defaultProvider` | the first provider | Provider for new uploads when several are configured |
|
|
237
|
-
| `collection.slug` | `videos` | Collection slug |
|
|
238
|
-
| `collection.adminGroup` | (none) | Admin sidebar group |
|
|
239
|
-
| `collection.access` | Payload defaults (logged-in users) | Access functions for the videos collection, e.g. `{ read: () => true }` for public sites. See [Who can see videos](#who-can-see-videos) |
|
|
240
|
-
| `collection.override` | (none) | `(collection) => collection`: last chance to change the generated collection (access, fields, hooks…) |
|
|
241
|
-
| `access.upload` | collection `create` (or `update` when replacing) | Extra check for creating uploads and imports |
|
|
242
|
-
| `access.playback` | collection `read` | Extra check before handing out signed playback tokens |
|
|
243
|
-
| `access.manage` | collection `update` | Extra check for captions, downloads and sync |
|
|
244
|
-
| `upload.signedPlayback` | `false` | Default for new videos |
|
|
245
|
-
| `upload.thumbnailTime` | (none) | Default poster frame, in seconds |
|
|
246
|
-
| `upload.creator` | uploading user's ID | `(req) => string` stored as the asset's `creator` |
|
|
247
|
-
| `playback.expiresIn` | `3600` | Signed token lifetime in seconds (at most the providers' maximum; Cloudflare's is 86400) |
|
|
248
|
-
| `playback.coverDuration` | `{ factor: 2, marginSeconds: 600 }` | Extends tokens to `duration × factor + marginSeconds` so they outlast the video (still capped). `false` always uses `expiresIn` |
|
|
249
|
-
| `playback.populateOnRead` | `true` | Adds the virtual `playback` field on reads |
|
|
250
|
-
| `videoBlock` | `false` | `true` (or `{ slug, defaults, fields, … }`) registers the video block in `config.blocks`, so fields and Lexical can reference it by slug |
|
|
251
|
-
| `syncPendingTask` | `false` | `true` registers the `videoSyncPending` Payload jobs task (queue or run it yourself) |
|
|
252
|
-
| `syncPendingTask.cron` | (none) | How often to sync pending videos, e.g. `'*/5 * * * *'` (5 fields, or 6 with seconds). Adds the schedule and a `jobs.autoRun` entry, so nothing else is needed |
|
|
253
|
-
| `syncPendingTask.queue` | `videos` | Jobs queue for the schedule and autoRun entry |
|
|
254
|
-
| `syncPendingTask.autoRun` | `true` with `cron` | Set `false` if you run jobs yourself (a worker or `/api/payload-jobs/run`) |
|
|
255
|
-
| `syncPendingTask.schedule` | (none) | Full Payload jobs `schedule` array; overrides `cron`/`queue` |
|
|
256
|
-
| `syncPendingTask.batchSize` / `.slug` | `50` / `videoSyncPending` | Documents per run / task slug |
|
|
257
|
-
| `deleteFromProvider` | `true` | Delete the provider asset when its document is deleted |
|
|
258
|
-
| `disabled` | `false` | Keeps the schema but turns off endpoints, hooks and UI. `providers` may be empty |
|
|
259
|
-
|
|
260
|
-
### `cloudflareStream()`
|
|
261
|
-
|
|
262
|
-
| Option | Default | Description |
|
|
263
|
-
| --- | --- | --- |
|
|
264
|
-
| `accountId` | (required) | Cloudflare account ID |
|
|
265
|
-
| `apiToken` | (required) | API token with Stream:Edit |
|
|
266
|
-
| `id` / `label` | `cloudflare` / `Cloudflare Stream` | Provider id stored on documents, and its admin label. Set `id` to configure two accounts |
|
|
267
|
-
| `customerCode` | auto | `customer-<code>.cloudflarestream.com` |
|
|
268
|
-
| `deliveryBaseUrl` | (none) | Base URL for playback URLs, e.g. a custom or regional hostname. Overrides `customerCode` |
|
|
269
|
-
| `apiBaseUrl` | `https://api.cloudflare.com/client/v4` | Override for API gateways or proxies (or the fake server) |
|
|
270
|
-
| `signingKey` | (none) | `{ keyId, pem \| jwk }` for local token signing. Without it, tokens come from Cloudflare's rate-limited `/token` API |
|
|
271
|
-
| `webhook.secret` | (none) | Turns on `POST /api/videos/webhook/cloudflare` |
|
|
272
|
-
| `webhook.toleranceSeconds` | `300` | Maximum signature age |
|
|
273
|
-
| `upload.maxDurationSeconds` | `3600` | Cloudflare rejects longer videos (max 36000). Storage is reserved for this duration until the upload completes |
|
|
274
|
-
| `upload.directUploadMaxBytes` | 200 MB | Files above this use resumable tus uploads |
|
|
275
|
-
| `upload.tusChunkSize` | 50 MiB | Normalised to Cloudflare's rules (5–200 MiB, multiple of 256 KiB) |
|
|
276
|
-
| `upload.allowedOrigins` | `[]` | Hostnames allowed to embed new videos |
|
|
277
|
-
| `upload.expiryMinutes` | `360` | How long an upload URL stays valid |
|
|
278
|
-
| `upload.watermarkUID` | (none) | Watermark profile applied to new uploads |
|
|
279
|
-
| `upload.scheduledDeletionDays` | (none) | Auto-delete new videos after N days |
|
|
280
|
-
| `playback.accessRules` | (none) | Default [access rules](https://developers.cloudflare.com/stream/viewing-videos/securing-your-stream/) embedded in tokens (at most 5) |
|
|
281
|
-
| `playback.iframe` / `playback.thumbnail` | (none) | Default iframe player and thumbnail options |
|
|
282
|
-
| `fetch` | global `fetch` | Custom fetch (tests) |
|
|
283
|
-
|
|
284
|
-
Cloudflare stores the poster position as a fraction of the duration. The plugin's `thumbnailTime` is in seconds, so a poster time chosen before the duration is known is applied as soon as the video is ready.
|
|
285
|
-
|
|
286
|
-
### `muxVideo()`
|
|
287
|
-
|
|
288
|
-
| Option | Default | Description |
|
|
289
|
-
| --- | --- | --- |
|
|
290
|
-
| `tokenId` / `tokenSecret` | (required) | Access token with Mux Video read + write |
|
|
291
|
-
| `id` / `label` | `mux` / `Mux` | Provider id stored on documents, and its admin label. Set `id` to configure two environments |
|
|
292
|
-
| `signingKey` | (none) | `{ keyId, privateKey }` (base64 PEM as Mux returns it) for signed playback. Tokens are signed per audience (video, poster, animated, storyboard) |
|
|
293
|
-
| `webhook.secret` / `.toleranceSeconds` | (none) / `300` | Turns on `POST /api/videos/webhook/mux` |
|
|
294
|
-
| `upload.chunkSize` | 16 MiB | Browser upload chunk size (rounded to a multiple of 256 KiB) |
|
|
295
|
-
| `upload.corsOrigin` | the uploading browser's origin | `cors_origin` of direct uploads |
|
|
296
|
-
| `upload.videoQuality` / `upload.maxResolutionTier` | Mux's defaults | `basic` / `plus` / `premium`; `1080p` / `1440p` / `2160p` |
|
|
297
|
-
| `upload.timeoutSeconds` | `3600` | How long an unused upload URL stays valid |
|
|
298
|
-
| `upload.test` | `false` | Create free, watermarked test assets that Mux deletes after 24 h |
|
|
299
|
-
| `playback.thumbnail` / `.animated` | (none) | Poster and animated preview options (inside the token for signed videos) |
|
|
300
|
-
| `playback.playbackRestrictionId` | (none) | Referrer / user-agent restriction added to every signed token |
|
|
301
|
-
| `delivery` | Mux's hosts | `{ stream, image, player }` base URLs, e.g. for a custom domain |
|
|
302
|
-
| `apiBaseUrl`, `fetch` | Mux's API, global `fetch` | Overrides for proxies and tests |
|
|
303
|
-
|
|
304
|
-
### `bunnyStream()`
|
|
305
|
-
|
|
306
|
-
| Option | Default | Description |
|
|
307
|
-
| --- | --- | --- |
|
|
308
|
-
| `libraryId` / `apiKey` / `cdnHostname` | (required) | The video library, its API key and its CDN hostname (or a full base URL for a custom hostname) |
|
|
309
|
-
| `id` / `label` | `bunny` / `Bunny Stream` | Provider id stored on documents, and its admin label. Set `id` to configure two libraries |
|
|
310
|
-
| `embedTokenKey` | (none) | Set when the library uses embed view token authentication: iframe URLs are signed |
|
|
311
|
-
| `cdnTokenKey` | (none) | Set when the pull zone uses CDN token authentication: HLS, images and MP4 URLs are signed (directory tokens, so segments inherit them) |
|
|
312
|
-
| `webhook.secret` / `.toleranceSeconds` | (none) / `21600` | The library's Read-Only API key; turns on `POST /api/videos/webhook/bunny`. Events older than the tolerance are ignored |
|
|
313
|
-
| `collectionId` | (none) | Put new videos in this Bunny collection |
|
|
314
|
-
| `upload.tusChunkSize` / `.tusSignatureTtlSeconds` | none / `86400` | tus chunk size; how long the browser's upload signature stays valid (min 3600) |
|
|
315
|
-
| `playback.iframe` | (none) | Default iframe options. `autoplay` is always sent, because Bunny's player autoplays otherwise |
|
|
316
|
-
| `playback.tokenCountries` | (none) | Lock signed CDN URLs to these countries |
|
|
317
|
-
| `apiBaseUrl`, `embedBaseUrl`, `fetch` | Bunny's hosts, global `fetch` | Overrides for proxies and tests |
|
|
318
|
-
|
|
319
|
-
On Bunny, signed playback and MP4 downloads are library settings, so the admin shows them read-only, and the poster time can only be set when the video is created.
|
|
80
|
+
```tsx
|
|
81
|
+
import { Video } from 'payload-video-streaming/react'
|
|
320
82
|
|
|
321
|
-
|
|
83
|
+
const post = await payload.findByID({ collection: 'posts', id, depth: 1 })
|
|
322
84
|
|
|
323
|
-
|
|
324
|
-
videoPlugin({
|
|
325
|
-
providers: [cloudflareStream({ … }), muxVideo({ … }), bunnyStream({ … })],
|
|
326
|
-
defaultProvider: 'mux',
|
|
327
|
-
})
|
|
85
|
+
<Video video={post.heroVideo} /> // the provider's player, or pass player={YourPlayer}
|
|
328
86
|
```
|
|
329
87
|
|
|
330
|
-
|
|
88
|
+
Anyone who can read the post can watch its video, even though the videos collection itself is only readable by logged-in users by default ([who can watch](./docs/rendering.md#who-can-watch)).
|
|
331
89
|
|
|
332
|
-
|
|
90
|
+
## Providers
|
|
333
91
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
| Mechanism | When it runs | Setup |
|
|
92
|
+
| Provider | Setup | Import |
|
|
337
93
|
| --- | --- | --- |
|
|
338
|
-
|
|
|
339
|
-
|
|
|
340
|
-
|
|
|
341
|
-
| `POST /api/videos/sync-pending` | Whenever you call it | Any external cron, authenticated as a user with `update` access (e.g. an API key). `?limit=` up to 500 |
|
|
342
|
-
| `getVideo(payload).syncPending()` | From your own code | None |
|
|
343
|
-
|
|
344
|
-
Sync-pending only fetches documents that aren't `ready` or `error` yet, oldest update first, for every provider. If an asset has disappeared at its provider (for example, an upload URL that expired unused), its document is marked `error` with code `notFound`.
|
|
94
|
+
| **Cloudflare Stream** | Account ID and an API token with **Stream · Edit** ([guide](./docs/providers/cloudflare.md)) | `cloudflareStream()` from `payload-video-streaming/cloudflare` |
|
|
95
|
+
| **Mux** | An access token with **Mux Video: Read and Write** ([guide](./docs/providers/mux.md)) | `muxVideo()` from `payload-video-streaming/mux` |
|
|
96
|
+
| **Bunny Stream** | Library ID, API key and CDN hostname ([guide](./docs/providers/bunny.md)) | `bunnyStream()` from `payload-video-streaming/bunny` |
|
|
345
97
|
|
|
346
98
|
```ts
|
|
347
|
-
|
|
348
|
-
videoPlugin({ providers, syncPendingTask: { cron: '* * * * *' } })
|
|
99
|
+
muxVideo({ tokenId: process.env.MUX_TOKEN_ID!, tokenSecret: process.env.MUX_TOKEN_SECRET! })
|
|
349
100
|
|
|
350
|
-
|
|
351
|
-
|
|
101
|
+
bunnyStream({
|
|
102
|
+
libraryId: process.env.BUNNY_STREAM_LIBRARY_ID!,
|
|
103
|
+
apiKey: process.env.BUNNY_STREAM_API_KEY!,
|
|
104
|
+
cdnHostname: process.env.BUNNY_STREAM_CDN_HOSTNAME!,
|
|
105
|
+
})
|
|
352
106
|
```
|
|
353
107
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
### Statuses
|
|
357
|
-
|
|
358
|
-
Every provider's states map to five neutral statuses:
|
|
108
|
+
Each guide covers signing keys, webhooks, limits and what was verified against a real account.
|
|
359
109
|
|
|
360
|
-
|
|
361
|
-
| --- | --- | --- | --- | --- |
|
|
362
|
-
| `waiting` | Waiting for the upload | `pendingupload` | upload `waiting` | 0 Created |
|
|
363
|
-
| `queued` | Received or being fetched, waiting to be processed | `queued`, `downloading` | asset `preparing` before transcoding | 1 Uploaded |
|
|
364
|
-
| `processing` | Encoding; `progress` holds a percentage when the provider reports one | `inprogress`, `live-inprogress` | asset `preparing` (transcoding) | 2 Processing, 3 Transcoding, 7/8 JIT |
|
|
365
|
-
| `ready` | Playable | `ready` | asset `ready` | 4 Finished |
|
|
366
|
-
| `error` | Processing failed (see the document's `error`) | `error` | asset `errored`; upload `errored`, `timed_out` or `cancelled` | 5 Error, 6 Upload failed |
|
|
110
|
+
### What each provider supports
|
|
367
111
|
|
|
368
|
-
|
|
112
|
+
The admin shows only what a video's provider can do, and endpoints for anything else answer `501`.
|
|
369
113
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
The videos collection uses Payload's default access unless you set your own. By default, only logged-in users can read, create, update or delete videos. For a public site, let visitors read them:
|
|
384
|
-
|
|
385
|
-
```ts
|
|
386
|
-
videoPlugin({
|
|
387
|
-
// ...
|
|
388
|
-
collection: { access: { read: () => true } }, // any Payload access functions; unset operations keep the defaults
|
|
389
|
-
})
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
Readable doesn't mean watchable for private videos. Videos with `signedPlayback` only play with a signed token, and visitors only get one when `access.playback` allows it (see [Signed (private) videos](#signed-private-videos)).
|
|
114
|
+
| | Cloudflare Stream | Mux | Bunny Stream |
|
|
115
|
+
| --- | --- | --- | --- |
|
|
116
|
+
| Browser upload | POST (≤200 MB) or tus | resumable chunked PUT | tus, signed by your server |
|
|
117
|
+
| Import by URL, server upload, adopt existing | ✓ | ✓ | ✓ |
|
|
118
|
+
| Encoding progress | ✓ | ✓ (while transcoding) | ✓ |
|
|
119
|
+
| Signed playback | per video | per video | library-wide |
|
|
120
|
+
| Per-video allowed origins | ✓ | — | — |
|
|
121
|
+
| Poster time | ✓ | ✓ | at creation only |
|
|
122
|
+
| Captions | upload, AI (12 languages) | upload, AI (22 languages + auto) | upload, AI transcription |
|
|
123
|
+
| Downloads | MP4 and audio, per video | MP4 and audio, per video | MP4, library-wide |
|
|
124
|
+
| HLS / DASH | ✓ / ✓ | ✓ / — | ✓ / — |
|
|
125
|
+
| Webhooks | ✓ | ✓ | ✓ |
|
|
393
126
|
|
|
394
|
-
|
|
127
|
+
All three are tested against real accounts, on Payload `4.0.0-beta.12` and `3.94.2`, with SQLite, Postgres and MongoDB ([TESTING.md](./TESTING.md)).
|
|
395
128
|
|
|
396
|
-
|
|
129
|
+
> [!IMPORTANT]
|
|
130
|
+
> **Bunny's standard encoding queue can be slow.** On a new library, videos waited at 0% for over 15 minutes; with Premium encoding they were ready in under a minute. [More](./docs/providers/bunny.md#limits-and-behaviour-to-know).
|
|
397
131
|
|
|
398
|
-
|
|
399
|
-
import { videoField } from 'payload-video-streaming'
|
|
132
|
+
## Features
|
|
400
133
|
|
|
401
|
-
|
|
402
|
-
slug: 'posts',
|
|
403
|
-
fields: [{ name: 'title', type: 'text' }, videoField({ name: 'heroVideo' })],
|
|
404
|
-
}
|
|
405
|
-
```
|
|
134
|
+
### Uploading
|
|
406
135
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
```jsonc
|
|
410
|
-
{
|
|
411
|
-
"heroVideo": {
|
|
412
|
-
"id": 1,
|
|
413
|
-
"title": "Launch trailer",
|
|
414
|
-
"provider": "cloudflare",
|
|
415
|
-
"assetId": "ea95132c15732412d22c1476fa83f27a",
|
|
416
|
-
"status": "ready",
|
|
417
|
-
"duration": 42.5,
|
|
418
|
-
"signedPlayback": false,
|
|
419
|
-
"playback": {
|
|
420
|
-
"provider": "cloudflare",
|
|
421
|
-
"assetId": "ea95132c15732412d22c1476fa83f27a",
|
|
422
|
-
"status": "ready",
|
|
423
|
-
"readyToStream": true,
|
|
424
|
-
"signedPlayback": false,
|
|
425
|
-
"signed": false,
|
|
426
|
-
"urls": {
|
|
427
|
-
"hls": "https://customer-xxxx.cloudflarestream.com/ea95…/manifest/video.m3u8",
|
|
428
|
-
"dash": "https://customer-xxxx.cloudflarestream.com/ea95…/manifest/video.mpd",
|
|
429
|
-
"iframe": "https://customer-xxxx.cloudflarestream.com/ea95…/iframe",
|
|
430
|
-
"watch": "https://customer-xxxx.cloudflarestream.com/ea95…/watch",
|
|
431
|
-
"thumbnail": "https://customer-xxxx.cloudflarestream.com/ea95…/thumbnails/thumbnail.jpg"
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
```
|
|
136
|
+
Every upload goes straight from the browser to the provider.
|
|
437
137
|
|
|
438
|
-
|
|
138
|
+
- **Videos list:** drop one file to upload it and open it. Drop several and they upload as separate videos, 3 at a time, each with progress, pause, cancel and retry.
|
|
139
|
+
- **Any video field:** "Upload new video" next to the picker uploads and selects the new video without leaving the page.
|
|
140
|
+
- **Import from a URL:** the provider fetches the file.
|
|
141
|
+
- **Replace:** the original keeps playing until the replacement is ready.
|
|
439
142
|
|
|
440
|
-
|
|
143
|
+
Building your own upload UI? `useVideoUpload`, `useUploadQueue` and `uploadVideoFile` handle every provider's protocol ([API reference](./docs/api.md#uploading-from-your-own-frontend)).
|
|
441
144
|
|
|
442
|
-
###
|
|
145
|
+
### Videos in your content
|
|
443
146
|
|
|
444
|
-
`
|
|
147
|
+
`videoField()` adds a video to any collection, group or block. `videoBlock()` is a ready-made block for layout builders and Lexical rich text, with player settings editors can change.
|
|
445
148
|
|
|
446
149
|
```ts
|
|
447
|
-
import { BlocksFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
448
|
-
import { videoBlock, videoBlockReferences } from 'payload-video-streaming'
|
|
449
|
-
|
|
450
150
|
fields: [
|
|
451
|
-
|
|
151
|
+
videoField({ name: 'heroVideo' }),
|
|
452
152
|
{ name: 'layout', type: 'blocks', blocks: [videoBlock(), /* your blocks */] },
|
|
453
|
-
|
|
454
|
-
// Or register it once with `videoPlugin({ videoBlock: true })` and reference it by slug.
|
|
455
|
-
// `videoBlockReferences` returns the right shape for Payload 3 (`blockReferences`) and 4 (`blocks`).
|
|
456
|
-
{ name: 'sections', type: 'blocks', ...videoBlockReferences('video') },
|
|
457
|
-
|
|
458
|
-
// Lexical takes slugs on both versions (with `videoBlock: true`) or the block itself:
|
|
459
|
-
{
|
|
460
|
-
name: 'content',
|
|
461
|
-
type: 'richText',
|
|
462
|
-
editor: lexicalEditor({
|
|
463
|
-
features: ({ defaultFeatures }) => [...defaultFeatures, BlocksFeature({ blocks: ['video'] })],
|
|
464
|
-
}),
|
|
465
|
-
},
|
|
466
153
|
]
|
|
467
154
|
```
|
|
468
155
|
|
|
469
|
-
|
|
156
|
+
Populated videos carry a virtual `playback` field with their URLs in every REST, GraphQL and Local API read. → [Video fields and blocks](./docs/fields-and-blocks.md)
|
|
470
157
|
|
|
471
|
-
### Rendering
|
|
158
|
+
### Rendering and players
|
|
472
159
|
|
|
473
|
-
`payload-video-streaming/react`
|
|
160
|
+
`payload-video-streaming/react` works in Server and Client Components, without importing Payload or Next.js.
|
|
474
161
|
|
|
475
162
|
```tsx
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
<Video video={post.heroVideo} />
|
|
480
|
-
<VideoBlock block={block} /> // a block from a blocks field
|
|
481
|
-
<RichText data={page.content} converters={({ defaultConverters }) => ({
|
|
482
|
-
...defaultConverters,
|
|
483
|
-
blocks: { ...defaultConverters.blocks, ...videoJSXConverters().blocks }, // blocks in rich text
|
|
484
|
-
})} />
|
|
163
|
+
<Video video={post.heroVideo} /> // a video field
|
|
164
|
+
<VideoBlock block={block} /> // a video block
|
|
165
|
+
videoJSXConverters() // video blocks in rich text
|
|
166
|
+
<Video video={post.heroVideo} player={HlsJsPlayer} /> // any player
|
|
485
167
|
```
|
|
486
168
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
**Any other player** works too. The plugin doesn't wrap players. A player is just a component that receives `{ source, options, title }`, and `source` has plain URLs:
|
|
490
|
-
|
|
491
|
-
```tsx
|
|
492
|
-
import type { VideoPlayerProps } from 'payload-video-streaming/react'
|
|
493
|
-
|
|
494
|
-
const MyPlayer = ({ source, options, title }: VideoPlayerProps) => (
|
|
495
|
-
<MediaPlayer src={source.hls} poster={source.poster} autoPlay={options.autoplay} title={title} />
|
|
496
|
-
)
|
|
169
|
+
- **Default player:** the provider's iframe player, which adds no JavaScript to the page.
|
|
170
|
+
- **Your own player:** any component that receives `{ source, options, title }`. `source.hls` works with hls.js, Video.js, Vidstack, native Safari and iOS, ExoPlayer and AVPlayer.
|
|
497
171
|
|
|
498
|
-
|
|
499
|
-
<VideoBlock block={block} player={MyPlayer} />
|
|
500
|
-
videoJSXConverters({ player: MyPlayer })
|
|
501
|
-
```
|
|
172
|
+
→ [Rendering videos](./docs/rendering.md), covering your own blocks, a page per video, client-only apps and caching. Ready-made players are in [examples/players](./examples/players).
|
|
502
173
|
|
|
503
|
-
|
|
174
|
+
### Who can watch
|
|
504
175
|
|
|
505
|
-
**
|
|
176
|
+
- **Video documents** follow your collection access. By default, only logged-in users can read them.
|
|
177
|
+
- **Embedded videos** play for anyone who can read the page they're on. Signed videos, unapproved member uploads and anything `access.playback` denies are excluded.
|
|
178
|
+
- **Signed playback:** turn on `signedPlayback` per video (or for every upload). Readers who pass `access.playback` get tokens that outlast the video.
|
|
506
179
|
|
|
507
|
-
|
|
180
|
+
→ [Who can watch](./docs/rendering.md#who-can-watch) and [signed videos](./docs/rendering.md#signed-private-videos)
|
|
508
181
|
|
|
509
|
-
###
|
|
182
|
+
### Member uploads
|
|
510
183
|
|
|
511
|
-
|
|
184
|
+
Let your site's users upload their own videos:
|
|
185
|
+
- **`ownership`** records each video's uploader.
|
|
186
|
+
- **`moderation`** holds new uploads for review.
|
|
187
|
+
- **Upload rules** limit size and file type, and run your own checks (quotas, for example).
|
|
188
|
+
- **`<VideoUploader />`** is a drop-in upload form for your site.
|
|
512
189
|
|
|
513
|
-
|
|
514
|
-
|
|
190
|
+
```ts
|
|
191
|
+
import { ownerOr, videoPlugin } from 'payload-video-streaming'
|
|
515
192
|
|
|
516
|
-
|
|
193
|
+
const isAdmin = ({ req }) => req.user?.collection === 'users'
|
|
517
194
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
195
|
+
videoPlugin({
|
|
196
|
+
providers,
|
|
197
|
+
ownership: true,
|
|
198
|
+
moderation: true,
|
|
199
|
+
upload: { maxFileSize: 2 * 1024 ** 3, allowedTypes: ['video/*'] },
|
|
200
|
+
collection: { access: { create: ({ req }) => Boolean(req.user), update: ownerOr(isAdmin), delete: ownerOr(isAdmin) } },
|
|
201
|
+
})
|
|
521
202
|
```
|
|
522
203
|
|
|
523
|
-
|
|
204
|
+
→ [Member uploads](./docs/member-uploads.md)
|
|
524
205
|
|
|
525
|
-
|
|
206
|
+
### Status updates and webhooks
|
|
526
207
|
|
|
527
|
-
|
|
208
|
+
Providers encode in the background. The plugin hears back in any of these ways:
|
|
528
209
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
| Method | Path | Description |
|
|
532
|
-
| --- | --- | --- |
|
|
533
|
-
| `POST` | `/upload` | `{ size, filename?, title?, id?, signedPlayback?, provider? }` → `{ id, provider, assetId?, upload }`. Creates or replaces the document; `upload` says where and how the browser sends the file (see below) |
|
|
534
|
-
| `POST` | `/import` | `{ url, title?, signedPlayback?, provider? }`: the provider fetches the video from the URL |
|
|
535
|
-
| `POST` | `/webhook/:provider` | Webhook receiver for that provider (signature-verified, no session needed). 404 when the provider has no webhook secret configured |
|
|
536
|
-
| `GET` | `/:id/playback` | Playback URLs, with a signed token when needed. Query: `expiresIn`, `downloadable` |
|
|
537
|
-
| `POST` | `/:id/sync` | Re-fetch status from the provider |
|
|
538
|
-
| `POST` | `/sync-pending` | Refresh every document that's still processing (needs collection `update` access). Query: `limit` |
|
|
539
|
-
| `GET` | `/:id/captions` | List captions |
|
|
540
|
-
| `PUT` | `/:id/captions/:language` | Upload a WebVTT file (multipart `file`, or a raw `text/vtt` body) |
|
|
541
|
-
| `POST` | `/:id/captions/:language/generate` | Generate captions with AI |
|
|
542
|
-
| `DELETE` | `/:id/captions/:language` | Delete a caption track |
|
|
543
|
-
| `GET`/`POST` | `/:id/downloads` | Read or create downloads (`{ type: 'default' \| 'audio' }`) |
|
|
544
|
-
| `DELETE` | `/:id/downloads/:type` | Remove a download |
|
|
545
|
-
| any | `/providers/:provider/…` | Extra endpoints a provider contributes, if any |
|
|
546
|
-
|
|
547
|
-
Provider API failures return `502` (or the provider's `404`/`429`) with `{ errors, provider, providerErrors }`.
|
|
548
|
-
|
|
549
|
-
### Uploading from your own frontend
|
|
550
|
-
|
|
551
|
-
`upload` is one of three protocols, chosen by the provider:
|
|
552
|
-
|
|
553
|
-
| `upload.protocol` | Fields | What to do |
|
|
210
|
+
| Mechanism | When | Setup |
|
|
554
211
|
| --- | --- | --- |
|
|
555
|
-
|
|
|
556
|
-
|
|
|
557
|
-
|
|
|
558
|
-
|
|
559
|
-
In React, `useVideoUpload(api)` handles all three, with pause, resume and cancel:
|
|
212
|
+
| Admin polling | While an editor has the video open | None |
|
|
213
|
+
| Webhook | The moment the provider finishes | `npx payload-video-streaming webhooks --url https://your-site.com` |
|
|
214
|
+
| Sync-pending job | On your schedule | `syncPendingTask: { cron: '*/5 * * * *' }` |
|
|
215
|
+
| `POST /api/videos/sync-pending` | From any external cron | An authenticated request |
|
|
560
216
|
|
|
561
|
-
|
|
562
|
-
import { createPluginApi, useVideoUpload } from 'payload-video-streaming/client'
|
|
217
|
+
The `webhooks` command prints each provider's URL and setup steps. It can also register Cloudflare's webhook for you (`--register cloudflare`) and test deployed endpoints (`--check`). The videos list shows whether each provider's webhook is working. → [Webhooks](./docs/webhooks.md)
|
|
563
218
|
|
|
564
|
-
|
|
565
|
-
const { start, pause, resume, cancel, state } = useVideoUpload(api)
|
|
566
|
-
await start(file, { title: 'My video' })
|
|
567
|
-
```
|
|
219
|
+
### Lifecycle hooks
|
|
568
220
|
|
|
569
|
-
|
|
221
|
+
React when a video becomes ready or fails, whatever triggered the change:
|
|
570
222
|
|
|
571
|
-
|
|
223
|
+
```ts
|
|
224
|
+
videoPlugin({
|
|
225
|
+
providers,
|
|
226
|
+
hooks: {
|
|
227
|
+
onReady: async ({ doc, req }) => { /* notify the uploader, publish the post… */ },
|
|
228
|
+
onError: async ({ doc }) => { /* doc.error.code, doc.error.message */ },
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
```
|
|
572
232
|
|
|
573
|
-
|
|
233
|
+
### Server API
|
|
574
234
|
|
|
575
235
|
```ts
|
|
576
236
|
import { getVideo } from 'payload-video-streaming'
|
|
577
237
|
|
|
578
238
|
const videos = getVideo(payload)
|
|
579
|
-
|
|
580
|
-
await videos.uploadFile({ file: buffer, filename: 'intro.mp4', data: { title: 'Intro' } })
|
|
239
|
+
await videos.uploadFile({ file: buffer, filename: 'intro.mp4' })
|
|
581
240
|
await videos.importFromUrl({ url: 'https://example.com/video.mp4' })
|
|
582
|
-
await videos.createUpload({ size, filename, provider: 'cloudflare' }) // a browser upload + document
|
|
583
|
-
await videos.sync(id) // refresh from the provider
|
|
584
|
-
await videos.syncPending({ limit: 50 }) // refresh everything still processing → { checked, missing, failed }
|
|
585
|
-
await videos.adoptExisting({ creator }) // create documents for untracked assets → { created, skipped }
|
|
586
241
|
await videos.getPlayback(doc, { expiresIn: 600 })
|
|
587
|
-
await videos.getPlayback(doc, { providerOptions: { accessRules: [{ type: 'ip.geoip.country', action: 'allow', country: ['US'] }] } })
|
|
588
|
-
videos.provider() // the default provider; videos.provider('cloudflare') by id
|
|
589
|
-
videos.providers.all // every configured provider
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
Inside hooks and endpoints, pass `req` (for example `videos.sync(id, req)`) so writes join the current transaction.
|
|
593
|
-
|
|
594
|
-
The Cloudflare provider has its own helpers: `videos.provider<CloudflareStreamProvider>('cloudflare').client` is the typed Stream REST client, and `.signToken(uid, opts)` signs a token. Framework-agnostic helpers with no Payload dependency, such as `StreamClient`, URL builders, `signStreamToken` and `verifyWebhookSignature`, are exported from `payload-video-streaming/cloudflare`.
|
|
595
|
-
|
|
596
|
-
### Writing a provider
|
|
597
|
-
|
|
598
|
-
Providers implement the `VideoProvider` interface exported from the package root: uploads, asset reads and updates, playback URLs, and optional captions, downloads and webhooks, with a `capabilities` object that the core reads to gate the admin and endpoints. Cloudflare's implementation (`src/providers/cloudflare/provider.ts`) is the reference.
|
|
599
|
-
|
|
600
|
-
## Local development (no containers, no provider account)
|
|
601
|
-
|
|
602
|
-
```bash
|
|
603
|
-
bun install # installs only; everything else runs on Node
|
|
604
|
-
npm run dev # http://payload-video-streaming.localhost/admin (auto-login dev@payloadcms.com / test)
|
|
605
|
-
npm run dev:direct # same, without portless: http://localhost:3000/admin
|
|
606
242
|
```
|
|
607
243
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
- The first run starts the portless proxy. By default it serves HTTPS on port 443, which asks for `sudo` once to trust a local certificate authority. For plain HTTP without `sudo`, start it yourself first: `npx portless proxy start --unprivileged`.
|
|
611
|
-
- `PORTLESS=0 npm run dev` (or `npm run dev:direct`) skips portless.
|
|
612
|
-
- The E2E suite doesn't use portless. It picks free ports and its own Next.js build directory, so it can run while `npm run dev` is up.
|
|
244
|
+
→ [API reference](./docs/api.md): REST endpoints, the server API, frontend exports and writing a provider.
|
|
613
245
|
|
|
614
|
-
|
|
246
|
+
## Documentation
|
|
615
247
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
248
|
+
| Guide | What's in it |
|
|
249
|
+
| --- | --- |
|
|
250
|
+
| [Configuration](./docs/configuration.md) | Every option and environment variable |
|
|
251
|
+
| [Video fields and blocks](./docs/fields-and-blocks.md) | `videoField()`, `videoBlock()` and the video document |
|
|
252
|
+
| [Rendering videos](./docs/rendering.md) | Components, players, your own blocks, who can watch, signed videos, caching |
|
|
253
|
+
| [Member uploads](./docs/member-uploads.md) | Ownership, moderation, upload rules, `VideoUploader` |
|
|
254
|
+
| [Webhooks](./docs/webhooks.md) | Setup per provider, the CLI, local tunnels, troubleshooting |
|
|
255
|
+
| [API reference](./docs/api.md) | Statuses, REST endpoints, server API, frontend exports, writing a provider |
|
|
256
|
+
| Providers | [Cloudflare Stream](./docs/providers/cloudflare.md), [Mux](./docs/providers/mux.md), [Bunny Stream](./docs/providers/bunny.md) |
|
|
257
|
+
| [Examples](./examples) | Type-checked configs, Next.js pages, players, upload UIs, server scripts and tests |
|
|
258
|
+
| [Migrating from payload-cf-stream](./docs/migrating-from-payload-cf-stream.md) | Moving existing documents over |
|
|
259
|
+
|
|
260
|
+
### Entry points
|
|
261
|
+
|
|
262
|
+
| Import | For |
|
|
263
|
+
| --- | --- |
|
|
264
|
+
| `payload-video-streaming` | The plugin, `videoField()`, `videoBlock()`, access helpers, `getVideo()` |
|
|
265
|
+
| `payload-video-streaming/cloudflare`, `/mux`, `/bunny` | Provider factories, plus standalone REST clients, signing and webhook helpers |
|
|
266
|
+
| `payload-video-streaming/react` | `Video`, `VideoBlock`, `videoJSXConverters`, `VideoUploader`, upload and source hooks |
|
|
267
|
+
| `payload-video-streaming/client` | The admin components, if you build your own admin views |
|
|
268
|
+
| `payload-video-streaming/testing` | Fake providers for your own tests |
|
|
269
|
+
| `npx payload-video-streaming` | `webhooks`, `fake` and `migrate-cf-stream` commands |
|
|
621
270
|
|
|
622
|
-
|
|
623
|
-
videoPlugin({ providers: [cloudflareStream(fake.providerOptions)] })
|
|
624
|
-
// fake.setStatus(assetId, 'ready'), fake.buildWebhook(assetId, secret), fake.requests, await fake.stop()
|
|
625
|
-
```
|
|
271
|
+
## Good to know
|
|
626
272
|
|
|
627
|
-
|
|
273
|
+
- **Playback starts once the provider is done:** `readyToStream` turns `true`. That usually takes seconds to a few minutes.
|
|
274
|
+
- **Edits sync to the provider.** Changing signed playback, allowed origins, the poster time, the title or `meta` updates the provider. Deleting a document deletes its video there too (`deleteFromProvider`).
|
|
275
|
+
- **Databases:** SQLite, Postgres and MongoDB work, and the plugin's writes join your transaction when you pass `req`.
|
|
276
|
+
- **One provider per video.** Replacements stay on the same provider; moving videos between providers isn't supported.
|
|
277
|
+
- **Provider quirks**, such as Cloudflare's single webhook URL, Mux's caption fetching and Bunny's replace behaviour, are listed in each [provider guide](#providers).
|
|
628
278
|
|
|
629
|
-
##
|
|
279
|
+
## Development
|
|
630
280
|
|
|
631
281
|
```bash
|
|
632
|
-
|
|
633
|
-
npm run
|
|
634
|
-
npm run test:e2e # Playwright admin UI and frontend against the fake; VIDEO_PROVIDER=cloudflare|mux|bunny
|
|
635
|
-
npm run test:live # real provider APIs, each only when its credentials are in .env; cleans up after itself
|
|
636
|
-
npm run test:payload3 # the whole suite against Payload 3 (honours TEST_PROVIDER / VIDEO_PROVIDER)
|
|
637
|
-
npm run cleanup:live # delete leftover live-test videos (cleanup:live:mux, cleanup:live:bunny for the others)
|
|
282
|
+
bun install # installs only; everything else runs on Node
|
|
283
|
+
npm run dev # the admin against a fake provider; no account, containers or database server needed
|
|
638
284
|
```
|
|
639
285
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
## Notes
|
|
643
|
-
|
|
644
|
-
- A video is playable only when `readyToStream` is `true`. Encoding usually takes seconds to a few minutes.
|
|
645
|
-
- Cloudflare: `maxDurationSeconds` reserves storage minutes until an upload completes or its URL expires.
|
|
646
|
-
- Cloudflare allows **one webhook URL per account**. If several environments share an account, use separate accounts or rely on the sync-pending job.
|
|
647
|
-
- Cloudflare's `/token` API is rate-limited. Configure a `signingKey` for production traffic.
|
|
648
|
-
- Mux fetches uploaded caption files from a URL, so the plugin serves them at a signed, one-hour URL (`GET /api/videos/caption-source/…`). Mux must be able to reach your server, so this doesn't work from localhost.
|
|
649
|
-
- Mux: an asset only exists once the upload finishes, so a video's `assetId` is empty until then (the document links to the upload by `uploadId`).
|
|
650
|
-
- Bunny: there's no file-replace API, so "Replace video" creates a new Bunny video and deletes the old one once the new one is ready (as on the other providers).
|
|
651
|
-
- Replacing a video keeps the original until the replacement is ready, so a cancelled upload never loses the original.
|
|
652
|
-
|
|
653
|
-
## Contributing
|
|
654
|
-
|
|
655
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup and guidelines, and [ROADMAP.md](./ROADMAP.md) for planned features. Report security problems privately as described in [SECURITY.md](./SECURITY.md).
|
|
286
|
+
[CONTRIBUTING.md](./CONTRIBUTING.md) covers the dev app, the fake providers and the test suites. [ROADMAP.md](./ROADMAP.md) lists what's planned. Report security problems privately, as described in [SECURITY.md](./SECURITY.md).
|
|
656
287
|
|
|
657
288
|
## License
|
|
658
289
|
|
|
659
|
-
MIT
|
|
290
|
+
[MIT](./LICENSE)
|