payload-video-streaming 0.0.0-stage → 0.2.0-beta.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/LICENSE +21 -0
- package/README.md +658 -2
- package/dist/bin/args.d.ts +24 -0
- package/dist/bin/args.js +96 -0
- package/dist/bin/args.js.map +1 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +17 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/fake.d.ts +2 -0
- package/dist/bin/fake.js +14 -0
- package/dist/bin/fake.js.map +1 -0
- package/dist/bin/migrate.d.ts +5 -0
- package/dist/bin/migrate.js +47 -0
- package/dist/bin/migrate.js.map +1 -0
- package/dist/bin/runFake.d.ts +2 -0
- package/dist/bin/runFake.js +24 -0
- package/dist/bin/runFake.js.map +1 -0
- package/dist/blocks.d.ts +42 -0
- package/dist/blocks.js +150 -0
- package/dist/blocks.js.map +1 -0
- package/dist/collection.d.ts +10 -0
- package/dist/collection.js +550 -0
- package/dist/collection.js.map +1 -0
- package/dist/components/CaptionsManager.d.ts +9 -0
- package/dist/components/CaptionsManager.js +174 -0
- package/dist/components/CaptionsManager.js.map +1 -0
- package/dist/components/DownloadsPanel.d.ts +9 -0
- package/dist/components/DownloadsPanel.js +147 -0
- package/dist/components/DownloadsPanel.js.map +1 -0
- package/dist/components/ListUploader.d.ts +11 -0
- package/dist/components/ListUploader.js +116 -0
- package/dist/components/ListUploader.js.map +1 -0
- package/dist/components/ThumbnailCell.d.ts +5 -0
- package/dist/components/ThumbnailCell.js +28 -0
- package/dist/components/ThumbnailCell.js.map +1 -0
- package/dist/components/Uploader.d.ts +17 -0
- package/dist/components/Uploader.js +162 -0
- package/dist/components/Uploader.js.map +1 -0
- package/dist/components/VideoBlockLabel.d.ts +11 -0
- package/dist/components/VideoBlockLabel.js +86 -0
- package/dist/components/VideoBlockLabel.js.map +1 -0
- package/dist/components/VideoField.d.ts +17 -0
- package/dist/components/VideoField.js +418 -0
- package/dist/components/VideoField.js.map +1 -0
- package/dist/components/api.d.ts +46 -0
- package/dist/components/api.js +74 -0
- package/dist/components/api.js.map +1 -0
- package/dist/components/chunkedUpload.d.ts +28 -0
- package/dist/components/chunkedUpload.js +49 -0
- package/dist/components/chunkedUpload.js.map +1 -0
- package/dist/components/styles.d.ts +95 -0
- package/dist/components/styles.js +148 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/components/usePluginApi.d.ts +41 -0
- package/dist/components/usePluginApi.js +21 -0
- package/dist/components/usePluginApi.js.map +1 -0
- package/dist/components/useVideoUpload.d.ts +37 -0
- package/dist/components/useVideoUpload.js +181 -0
- package/dist/components/useVideoUpload.js.map +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +29 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/provider.d.ts +331 -0
- package/dist/core/provider.js +13 -0
- package/dist/core/provider.js.map +1 -0
- package/dist/core/registry.d.ts +17 -0
- package/dist/core/registry.js +110 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/status.d.ts +15 -0
- package/dist/core/status.js +29 -0
- package/dist/core/status.js.map +1 -0
- package/dist/endpoints/index.d.ts +3 -0
- package/dist/endpoints/index.js +464 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/env.d.ts +40 -0
- package/dist/env.js +105 -0
- package/dist/env.js.map +1 -0
- package/dist/exports/bunny.d.ts +16 -0
- package/dist/exports/bunny.js +13 -0
- package/dist/exports/bunny.js.map +1 -0
- package/dist/exports/client.d.ts +13 -0
- package/dist/exports/client.js +13 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/cloudflare.d.ts +18 -0
- package/dist/exports/cloudflare.js +15 -0
- package/dist/exports/cloudflare.js.map +1 -0
- package/dist/exports/mux.d.ts +18 -0
- package/dist/exports/mux.js +15 -0
- package/dist/exports/mux.js.map +1 -0
- package/dist/exports/react.d.ts +13 -0
- package/dist/exports/react.js +11 -0
- package/dist/exports/react.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/testing.d.ts +13 -0
- package/dist/exports/testing.js +9 -0
- package/dist/exports/testing.js.map +1 -0
- package/dist/fields.d.ts +13 -0
- package/dist/fields.js +13 -0
- package/dist/fields.js.map +1 -0
- package/dist/frontend/ClientVideo.d.ts +14 -0
- package/dist/frontend/ClientVideo.js +43 -0
- package/dist/frontend/ClientVideo.js.map +1 -0
- package/dist/frontend/Video.d.ts +32 -0
- package/dist/frontend/Video.js +73 -0
- package/dist/frontend/Video.js.map +1 -0
- package/dist/frontend/VideoIframe.d.ts +35 -0
- package/dist/frontend/VideoIframe.js +60 -0
- package/dist/frontend/VideoIframe.js.map +1 -0
- package/dist/frontend/constants.d.ts +10 -0
- package/dist/frontend/constants.js +10 -0
- package/dist/frontend/constants.js.map +1 -0
- package/dist/frontend/converters.d.ts +25 -0
- package/dist/frontend/converters.js +24 -0
- package/dist/frontend/converters.js.map +1 -0
- package/dist/frontend/source.d.ts +80 -0
- package/dist/frontend/source.js +159 -0
- package/dist/frontend/source.js.map +1 -0
- package/dist/frontend/useVideoSource.d.ts +27 -0
- package/dist/frontend/useVideoSource.js +108 -0
- package/dist/frontend/useVideoSource.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate/cfStream.d.ts +108 -0
- package/dist/migrate/cfStream.js +418 -0
- package/dist/migrate/cfStream.js.map +1 -0
- package/dist/options.d.ts +4 -0
- package/dist/options.js +90 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +98 -0
- package/dist/plugin.js.map +1 -0
- package/dist/providers/bunny/client.d.ts +78 -0
- package/dist/providers/bunny/client.js +231 -0
- package/dist/providers/bunny/client.js.map +1 -0
- package/dist/providers/bunny/env.d.ts +18 -0
- package/dist/providers/bunny/env.js +31 -0
- package/dist/providers/bunny/env.js.map +1 -0
- package/dist/providers/bunny/mapping.d.ts +39 -0
- package/dist/providers/bunny/mapping.js +123 -0
- package/dist/providers/bunny/mapping.js.map +1 -0
- package/dist/providers/bunny/options.d.ts +92 -0
- package/dist/providers/bunny/options.js +85 -0
- package/dist/providers/bunny/options.js.map +1 -0
- package/dist/providers/bunny/provider.d.ts +69 -0
- package/dist/providers/bunny/provider.js +472 -0
- package/dist/providers/bunny/provider.js.map +1 -0
- package/dist/providers/bunny/signing.d.ts +61 -0
- package/dist/providers/bunny/signing.js +144 -0
- package/dist/providers/bunny/signing.js.map +1 -0
- package/dist/providers/bunny/types.d.ts +153 -0
- package/dist/providers/bunny/types.js +64 -0
- package/dist/providers/bunny/types.js.map +1 -0
- package/dist/providers/bunny/urls.d.ts +49 -0
- package/dist/providers/bunny/urls.js +70 -0
- package/dist/providers/bunny/urls.js.map +1 -0
- package/dist/providers/bunny/webhook.d.ts +32 -0
- package/dist/providers/bunny/webhook.js +75 -0
- package/dist/providers/bunny/webhook.js.map +1 -0
- package/dist/providers/cloudflare/client.d.ts +93 -0
- package/dist/providers/cloudflare/client.js +436 -0
- package/dist/providers/cloudflare/client.js.map +1 -0
- package/dist/providers/cloudflare/env.d.ts +22 -0
- package/dist/providers/cloudflare/env.js +57 -0
- package/dist/providers/cloudflare/env.js.map +1 -0
- package/dist/providers/cloudflare/mapping.d.ts +15 -0
- package/dist/providers/cloudflare/mapping.js +95 -0
- package/dist/providers/cloudflare/mapping.js.map +1 -0
- package/dist/providers/cloudflare/options.d.ts +104 -0
- package/dist/providers/cloudflare/options.js +91 -0
- package/dist/providers/cloudflare/options.js.map +1 -0
- package/dist/providers/cloudflare/provider.d.ts +62 -0
- package/dist/providers/cloudflare/provider.js +434 -0
- package/dist/providers/cloudflare/provider.js.map +1 -0
- package/dist/providers/cloudflare/signing.d.ts +41 -0
- package/dist/providers/cloudflare/signing.js +97 -0
- package/dist/providers/cloudflare/signing.js.map +1 -0
- package/dist/providers/cloudflare/tus.d.ts +24 -0
- package/dist/providers/cloudflare/tus.js +55 -0
- package/dist/providers/cloudflare/tus.js.map +1 -0
- package/dist/providers/cloudflare/types.d.ts +156 -0
- package/dist/providers/cloudflare/types.js +14 -0
- package/dist/providers/cloudflare/types.js.map +1 -0
- package/dist/providers/cloudflare/urls.d.ts +55 -0
- package/dist/providers/cloudflare/urls.js +87 -0
- package/dist/providers/cloudflare/urls.js.map +1 -0
- package/dist/providers/cloudflare/webhook.d.ts +36 -0
- package/dist/providers/cloudflare/webhook.js +83 -0
- package/dist/providers/cloudflare/webhook.js.map +1 -0
- package/dist/providers/mux/client.d.ts +82 -0
- package/dist/providers/mux/client.js +283 -0
- package/dist/providers/mux/client.js.map +1 -0
- package/dist/providers/mux/env.d.ts +21 -0
- package/dist/providers/mux/env.js +61 -0
- package/dist/providers/mux/env.js.map +1 -0
- package/dist/providers/mux/mapping.d.ts +38 -0
- package/dist/providers/mux/mapping.js +111 -0
- package/dist/providers/mux/mapping.js.map +1 -0
- package/dist/providers/mux/options.d.ts +96 -0
- package/dist/providers/mux/options.js +83 -0
- package/dist/providers/mux/options.js.map +1 -0
- package/dist/providers/mux/provider.d.ts +62 -0
- package/dist/providers/mux/provider.js +546 -0
- package/dist/providers/mux/provider.js.map +1 -0
- package/dist/providers/mux/signing.d.ts +45 -0
- package/dist/providers/mux/signing.js +84 -0
- package/dist/providers/mux/signing.js.map +1 -0
- package/dist/providers/mux/types.d.ts +173 -0
- package/dist/providers/mux/types.js +42 -0
- package/dist/providers/mux/types.js.map +1 -0
- package/dist/providers/mux/urls.d.ts +58 -0
- package/dist/providers/mux/urls.js +59 -0
- package/dist/providers/mux/urls.js.map +1 -0
- package/dist/providers/mux/webhook.d.ts +38 -0
- package/dist/providers/mux/webhook.js +115 -0
- package/dist/providers/mux/webhook.js.map +1 -0
- package/dist/service.d.ts +166 -0
- package/dist/service.js +857 -0
- package/dist/service.js.map +1 -0
- package/dist/testing/bunny.d.ts +113 -0
- package/dist/testing/bunny.js +776 -0
- package/dist/testing/bunny.js.map +1 -0
- package/dist/testing/cloudflare.d.ts +101 -0
- package/dist/testing/cloudflare.js +913 -0
- package/dist/testing/cloudflare.js.map +1 -0
- package/dist/testing/index.d.ts +45 -0
- package/dist/testing/index.js +42 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mux.d.ts +139 -0
- package/dist/testing/mux.js +1053 -0
- package/dist/testing/mux.js.map +1 -0
- package/dist/testing/types.d.ts +90 -0
- package/dist/testing/types.js +9 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/access.d.ts +22 -0
- package/dist/utils/access.js +66 -0
- package/dist/utils/access.js.map +1 -0
- package/dist/utils/localReq.d.ts +11 -0
- package/dist/utils/localReq.js +23 -0
- package/dist/utils/localReq.js.map +1 -0
- package/dist/utils/request.d.ts +12 -0
- package/dist/utils/request.js +55 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/version.d.ts +5 -0
- package/dist/utils/version.js +7 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +174 -4
package/README.md
CHANGED
|
@@ -1,3 +1,659 @@
|
|
|
1
|
-
#
|
|
1
|
+
# payload-video-streaming
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/payload-video-streaming) [](https://github.com/BarakChamo/payload-video-streaming/actions/workflows/ci.yml) [](./LICENSE)
|
|
4
|
+
|
|
5
|
+
Video uploads, playback URLs and access control for **Payload CMS 3 and 4 (beta)**, backed by a video streaming provider.
|
|
6
|
+
|
|
7
|
+
| Provider | Entry point | Status |
|
|
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).
|
|
59
|
+
|
|
60
|
+
### How this differs from `payload-video-stream`
|
|
61
|
+
|
|
62
|
+
[`payload-video-stream`](https://www.npmjs.com/package/payload-video-stream) is a separate, Cloudflare-only plugin that works through Payload upload collections. This plugin supports Payload 4 as well as 3, is built for several providers, uploads directly from the browser to the provider, and ships a video block, frontend components and bring-your-own-player support.
|
|
63
|
+
|
|
64
|
+
## Requirements
|
|
65
|
+
|
|
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 |
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install payload-video-streaming # or pnpm add / bun add / yarn add
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// payload.config.ts
|
|
80
|
+
import { buildConfig } from 'payload'
|
|
81
|
+
import { videoPlugin } from 'payload-video-streaming'
|
|
82
|
+
import { cloudflareStream } from 'payload-video-streaming/cloudflare'
|
|
83
|
+
|
|
84
|
+
export default buildConfig({
|
|
85
|
+
// ...
|
|
86
|
+
plugins: [
|
|
87
|
+
videoPlugin({
|
|
88
|
+
providers: [
|
|
89
|
+
cloudflareStream({
|
|
90
|
+
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
|
|
91
|
+
apiToken: process.env.CLOUDFLARE_STREAM_API_TOKEN!,
|
|
92
|
+
webhook: { secret: process.env.CLOUDFLARE_STREAM_WEBHOOK_SECRET },
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then regenerate the admin import map so Payload can find the plugin's admin components:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx payload generate:importmap
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Or configure everything from environment variables. `videoOptionsFromEnv()` sets up every provider whose variables are present:
|
|
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
|
|
230
|
+
|
|
231
|
+
### `videoPlugin()`
|
|
232
|
+
|
|
233
|
+
| Option | Default | Description |
|
|
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.
|
|
320
|
+
|
|
321
|
+
### Several providers
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
videoPlugin({
|
|
325
|
+
providers: [cloudflareStream({ … }), muxVideo({ … }), bunnyStream({ … })],
|
|
326
|
+
defaultProvider: 'mux',
|
|
327
|
+
})
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
New uploads go to `defaultProvider`; with more than one provider the admin uploader shows a select. Existing documents keep playing from the provider that stores them, and a replacement upload stays on the same provider. Moving videos between providers isn't supported.
|
|
331
|
+
|
|
332
|
+
### Keeping status in sync
|
|
333
|
+
|
|
334
|
+
Providers encode videos asynchronously, so each document needs to hear when its video becomes `ready` (or fails). Pick whatever fits your deployment; **none of these are required for uploads or playback to work**:
|
|
335
|
+
|
|
336
|
+
| Mechanism | When it runs | Setup |
|
|
337
|
+
| --- | --- | --- |
|
|
338
|
+
| Admin polling | While an editor has the video open | None |
|
|
339
|
+
| Webhook | The moment the provider finishes | Register `/api/videos/webhook/<provider id>` with the provider and give the provider its secret ([Cloudflare setup](#cloudflare-setup)) |
|
|
340
|
+
| Sync-pending job | On your cron | `syncPendingTask: { cron: '*/5 * * * *' }` (or `VIDEO_SYNC_CRON`) |
|
|
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`.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
// Webhook-free: settle processing videos every minute
|
|
348
|
+
videoPlugin({ providers, syncPendingTask: { cron: '* * * * *' } })
|
|
349
|
+
|
|
350
|
+
// You already run Payload jobs elsewhere (worker, /api/payload-jobs/run): only schedule it
|
|
351
|
+
videoPlugin({ providers, syncPendingTask: { autoRun: false, cron: '*/5 * * * *', queue: 'default' } })
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
`cron` adds the task's schedule and a `jobs.autoRun` entry for its queue, alongside any `autoRun` you already have. That suits long-running servers. Payload starts its crons with the first admin or API request; standalone scripts need `getPayload({ config, cron: true })`. On serverless hosts, call the endpoint from a scheduled function instead.
|
|
355
|
+
|
|
356
|
+
### Statuses
|
|
357
|
+
|
|
358
|
+
Every provider's states map to five neutral statuses:
|
|
359
|
+
|
|
360
|
+
| Status | Meaning | Cloudflare | Mux | Bunny (API status) |
|
|
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 |
|
|
367
|
+
|
|
368
|
+
Bunny's webhooks use different numbers for the same states; the plugin treats every Bunny webhook as "fetch the current state", so retries and out-of-order deliveries can't move a document backwards.
|
|
369
|
+
|
|
370
|
+
### Regions and data localization (Cloudflare)
|
|
371
|
+
|
|
372
|
+
Cloudflare Stream has **no per-video region or jurisdiction setting** in its API. Videos are stored and delivered from Cloudflare's global network. The provider exposes every endpoint it talks to, so it works with any regional or proxied setup:
|
|
373
|
+
|
|
374
|
+
- `apiBaseUrl`: route API calls through a gateway or proxy.
|
|
375
|
+
- `deliveryBaseUrl`: serve playback from a custom or regional hostname.
|
|
376
|
+
|
|
377
|
+
Account-level data localization (Cloudflare's [Customer Metadata Boundary](https://developers.cloudflare.com/data-localization/metadata-boundary/get-started/), EU/US) is configured in the Cloudflare dashboard, not through Stream. Cloudflare's [GraphQL datasets reference](https://developers.cloudflare.com/data-localization/metadata-boundary/graphql-datasets/) lists the Stream analytics datasets as **US only**. Check Cloudflare's current documentation for your compliance needs.
|
|
378
|
+
|
|
379
|
+
## Using videos in your content
|
|
380
|
+
|
|
381
|
+
### Who can see videos
|
|
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)).
|
|
393
|
+
|
|
394
|
+
### Video fields
|
|
395
|
+
|
|
396
|
+
Point a field at the videos collection:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
import { videoField } from 'payload-video-streaming'
|
|
400
|
+
|
|
401
|
+
export const Posts: CollectionConfig = {
|
|
402
|
+
slug: 'posts',
|
|
403
|
+
fields: [{ name: 'title', type: 'text' }, videoField({ name: 'heroVideo' })],
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Read it with `depth >= 1`. Every video carries `playback`:
|
|
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
|
+
```
|
|
437
|
+
|
|
438
|
+
`urls.dash` and `urls.watch` are only present for providers that have them (Cloudflare). `urls.downloadMp4` appears once an MP4 download is ready.
|
|
439
|
+
|
|
440
|
+
The document's fields: `title`, `provider`, `assetId`, `playbackId`, `uploadId`, `status`, `progress`, `readyToStream`, `duration`, `width`, `height`, `size`, `signedPlayback`, `allowedOrigins`, `thumbnailTime` (seconds), `captions`, `downloads`, `error { code, message }`, `meta`, `creator`, `uploadedAt`, `readyAt`, `lastSyncedAt`, `replacedAssetId`, `providerData` (hidden raw payload) and the virtual `playback`. `provider` + `assetId` is unique.
|
|
441
|
+
|
|
442
|
+
### Video blocks
|
|
443
|
+
|
|
444
|
+
`videoBlock()` is an ordinary Payload block for layout builders and rich text. It holds a video, an optional caption and the player settings editors choose: autoplay, muted, loop, controls, start time, aspect ratio and default captions. In the admin, each block row shows the video's thumbnail and title. The default slug is `video` and its TypeScript interface is `VideoBlock`.
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
import { BlocksFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
448
|
+
import { videoBlock, videoBlockReferences } from 'payload-video-streaming'
|
|
449
|
+
|
|
450
|
+
fields: [
|
|
451
|
+
// Inline, in any blocks field:
|
|
452
|
+
{ 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
|
+
]
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
`videoBlock({ slug, defaults, fields, interfaceName, collectionSlug })` changes the slug, the default settings and the fields. See [`examples/video-blocks`](./examples/video-blocks/payload.config.ts).
|
|
470
|
+
|
|
471
|
+
### Rendering on your site
|
|
472
|
+
|
|
473
|
+
`payload-video-streaming/react` renders videos in any React app. It has no Payload or Next.js imports, and works in Server and Client Components.
|
|
474
|
+
|
|
475
|
+
```tsx
|
|
476
|
+
import { RichText } from '@payloadcms/richtext-lexical/react'
|
|
477
|
+
import { Video, VideoBlock, videoJSXConverters } from 'payload-video-streaming/react'
|
|
478
|
+
|
|
479
|
+
<Video video={post.heroVideo} /> // a video field
|
|
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
|
+
})} />
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
By default these render the provider's iframe player, which adds no JavaScript to your page. They apply the block's settings and show a placeholder while a video is still processing. Each provider's iframe takes the player options differently; the mapping is a plain table, `IFRAME_PARAMS`, keyed by provider id.
|
|
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
|
+
)
|
|
497
|
+
|
|
498
|
+
<Video video={post.heroVideo} player={MyPlayer} />
|
|
499
|
+
<VideoBlock block={block} player={MyPlayer} />
|
|
500
|
+
videoJSXConverters({ player: MyPlayer })
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
`source.hls` works with hls.js, Video.js, Vidstack, native Safari/iOS, ExoPlayer and AVPlayer. `source.dash` (Cloudflare only) works with Shaka Player and dash.js. `source.provider` and `source.assetId` say where the video lives. Ready-made snippets for each player are in [`examples/players`](./examples/players). On any page, `getVideoSource(video)` returns the same source object, so you can build your own markup.
|
|
504
|
+
|
|
505
|
+
**Videos resolved in the browser.** Two cases are fetched by the browser from the REST API with the visitor's session: an unpopulated relationship (an ID at `depth: 0`), and a private video the server couldn't sign. `Video` does this automatically, and so does the `useVideoSource(video)` hook for your own components. If you render from a Server Component and this can happen, make your player a Client Component.
|
|
506
|
+
|
|
507
|
+
Other exports: `ClientVideo`, `VideoIframe`, `VideoFrame`, `VideoPlaceholder`, `isVideoSourceExpired`, `videoIframeSrc`, `videoAspectRatio`, `videoDocId`, `blockPlayerOptions`, and the `VideoSource`, `VideoPlayerOptions` and `VideoPlayerComponent` types.
|
|
508
|
+
|
|
509
|
+
### Signed (private) videos
|
|
510
|
+
|
|
511
|
+
When `signedPlayback` is on:
|
|
512
|
+
|
|
513
|
+
- With **local signing**, `playback` contains freshly signed URLs on every read, as long as the reader passes `access.playback`. Local signing means a `signingKey` on Cloudflare and Mux (Mux signs one token per audience: video, poster, animated preview, storyboard), and the token keys on Bunny.
|
|
514
|
+
- Without it, reads return `urls: null`. `Video` and `useVideoSource` then call the playback endpoint, which can use the provider's signing API (Cloudflare's rate-limited `/token`; Mux and Bunny have none, so configure their keys). You can also call it yourself:
|
|
515
|
+
|
|
516
|
+
On **Bunny**, signing is a library setting: when the library uses token authentication every video is signed, and the document's `signedPlayback` shows that read-only. On **Mux**, switching a video between public and signed replaces its playback ID, so old public URLs stop working.
|
|
517
|
+
|
|
518
|
+
```ts
|
|
519
|
+
const res = await fetch(`/api/videos/${id}/playback?expiresIn=600`, { credentials: 'include' })
|
|
520
|
+
const { urls, expiresAt } = await res.json()
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Tokens outlast the video, so they never expire mid-playback. By default a video gets `max(playback.expiresIn, duration × 2 + 10 minutes)`, capped at the provider's maximum (`playback.coverDuration`). Pages that embed signed URLs shouldn't be cached for longer than `playback.expiresIn`.
|
|
524
|
+
|
|
525
|
+
Downloads of signed videos need a token that allows them. Pass `?downloadable=true`; it's set automatically once an MP4 download is ready.
|
|
526
|
+
|
|
527
|
+
## REST endpoints
|
|
528
|
+
|
|
529
|
+
All paths are under `/api/<collectionSlug>` (default `/api/videos`). Collection access control always applies, plus the plugin's `access.*` hooks. A feature the document's provider doesn't support answers **501** with a clear message.
|
|
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 |
|
|
554
|
+
| --- | --- | --- |
|
|
555
|
+
| `post` | `url`, `fieldName?` | One multipart POST of the file (field `fieldName`, default `file`). Cloudflare, files ≤ `directUploadMaxBytes` |
|
|
556
|
+
| `tus` | `uploadUrl?` or `endpoint?`, `headers?`, `metadata?`, `chunkSize?` | Resumable tus upload. Cloudflare, larger files (an existing upload at `uploadUrl`); Bunny, every upload (`endpoint` plus the signed `headers` and `metadata`) |
|
|
557
|
+
| `put-chunked` | `url`, `chunkSize`, `headers?` | Sequential PUTs with `Content-Range` headers (`ChunkedUpload` does this). Mux |
|
|
558
|
+
|
|
559
|
+
In React, `useVideoUpload(api)` handles all three, with pause, resume and cancel:
|
|
560
|
+
|
|
561
|
+
```tsx
|
|
562
|
+
import { createPluginApi, useVideoUpload } from 'payload-video-streaming/client'
|
|
563
|
+
|
|
564
|
+
const api = createPluginApi('/api', 'videos')
|
|
565
|
+
const { start, pause, resume, cancel, state } = useVideoUpload(api)
|
|
566
|
+
await start(file, { title: 'My video' })
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
[`examples/custom-upload/vanilla-upload.ts`](./examples/custom-upload/vanilla-upload.ts) does the same without React. A webhook, the sync-pending job or `POST /:id/sync` then moves the document to `ready`.
|
|
570
|
+
|
|
571
|
+
The admin components are exported too: `Uploader`, `ListUploader`, `VideoField`, `CaptionsManager`, `DownloadsPanel`, `ThumbnailCell`, `VideoBlockLabel`, `ChunkedUpload` and the `VideoApiError` class.
|
|
572
|
+
|
|
573
|
+
## Server API
|
|
574
|
+
|
|
575
|
+
```ts
|
|
576
|
+
import { getVideo } from 'payload-video-streaming'
|
|
577
|
+
|
|
578
|
+
const videos = getVideo(payload)
|
|
579
|
+
|
|
580
|
+
await videos.uploadFile({ file: buffer, filename: 'intro.mp4', data: { title: 'Intro' } })
|
|
581
|
+
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
|
+
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
|
+
```
|
|
607
|
+
|
|
608
|
+
`npm run dev` runs through [portless](https://github.com/vercel-labs/portless), so the app has a stable named URL instead of a port and never collides with other dev servers. The fake provider gets its own route, `fake.payload-video-streaming.localhost`. Git worktrees get their own subdomain automatically.
|
|
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.
|
|
613
|
+
|
|
614
|
+
`npm run dev` starts the Next.js dev app on a **SQLite file**. `VIDEO_PROVIDER` picks the provider: `cloudflare` (default), `mux` or `bunny`. If `.env` has no credentials for it, or you set `VIDEO_FAKE=1`, it also starts the **fake provider**, an in-memory emulator of the provider's API, upload endpoints and delivery. Put real credentials in `.env` (see `.env.example`) to develop against the real service.
|
|
615
|
+
|
|
616
|
+
Use the fake in your own app or tests:
|
|
617
|
+
|
|
618
|
+
```ts
|
|
619
|
+
import { cloudflareStream } from 'payload-video-streaming/cloudflare'
|
|
620
|
+
import { startFakeCloudflareStream } from 'payload-video-streaming/testing'
|
|
621
|
+
|
|
622
|
+
const fake = await startFakeCloudflareStream()
|
|
623
|
+
videoPlugin({ providers: [cloudflareStream(fake.providerOptions)] })
|
|
624
|
+
// fake.setStatus(assetId, 'ready'), fake.buildWebhook(assetId, secret), fake.requests, await fake.stop()
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
Every fake has the same `FakeProviderServer` shape (`providerOptions`, `addAsset`, `setStatus`, `simulateUpload`, `buildWebhook`, `localSigningOptions`, `requests`, `stop`…), and `startFake('cloudflare' | 'mux' | 'bunny')` picks one by id. All three can serve real HLS media (`hlsFixtureDir`) so custom players can be tested against them. You can also run one standalone: `npx payload-video-streaming-fake --provider mux --port 4870` (or `npx payload-video-streaming fake …`). It prints the options to pass to the provider factory. Behind a proxy, pass the public URL it should hand out with `--public-url`.
|
|
628
|
+
|
|
629
|
+
## Testing
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
npm run test:unit # pure modules (client, signing, webhooks, URLs, options, registry)
|
|
633
|
+
npm run test:int # real Payload + fake provider; TEST_DB=sqlite|mongodb|postgres, TEST_PROVIDER=cloudflare|mux|bunny
|
|
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)
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
MongoDB (`mongodb-memory-server`) and Postgres (`embedded-postgres`) run as local processes, so no Docker is needed. See [TESTING.md](./TESTING.md).
|
|
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).
|
|
656
|
+
|
|
657
|
+
## License
|
|
658
|
+
|
|
659
|
+
MIT
|