A Payload CMS plugin that enables seamless video uploads directly to streaming providers from Payload upload collections. This plugin automatically handles video file uploads to streaming platforms, providing optimized video delivery for your Payload CMS applications.
- 🎥 Direct video uploads to streaming providers from Payload upload collections
- ☁️ Cloudflare Stream support (currently available)
- 🔌 Extensible adapter architecture for adding more streaming providers
- 🔄 Automatic video processing and optimization
- 📊 Stream metadata integration with Payload documents
- 🎯 Type-safe configuration with TypeScript support
Currently supported:
- Cloudflare Stream - Complete integration with Cloudflare's video streaming platform
Planned support:
- Mux
- AWS MediaConvert
- Azure Media Services
- Other streaming API providers
npm install payload-video-stream
# or
yarn add payload-video-stream
# or
pnpm add payload-video-streamAdd the plugin to your payload.config.ts:
import { buildConfig } from 'payload/config'
import { videoStream } from 'payload-video-stream'
import { cloudflareStreamAdapter } from 'payload-video-stream/adapters'
export default buildConfig({
plugins: [
// configure your s3 storage configuration
s3Storage({
bucket: process.env.S3_BUCKET ?? 'romonoa',
clientUploads: true, // enable client-side uploads
collections: {
video: true,
},
config: {
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID ?? '',
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY ?? '',
},
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION,
// ... Other S3 configuration
},
signedDownloads: {
// expires in 24 hours
expiresIn: 60 * 60 * 24,
}, // enable signed download URLs
}),
// configure video stream plugin
videoStream({
collections: {
media: true,
},
// configure default adapter, currently only support cloudflare stream adapter
defaultAdapter: cloudflareStreamAdapter({
accountId: process.env.CLOUDFLARE_STREAM_ACCOUNT_ID || '',
apiToken: process.env.CLOUDFLARE_STREAM_API_TOKEN || '',
customerSubdomain: process.env.NEXT_PUBLIC_CLOUDFLARE_STREAM_CUSTOMER_SUBDOMAIN || '',
requireSignedURLs: true // OPTIONAL: enable this if you enabled the signed downloads on your storage so the plugin will use the signed s3 url to the cloudflare stream copy video url function
}),
}),
],
// ... rest of your config
})Create a .env file with your streaming provider credentials:
CLOUDFLARE_STREAM_API_TOKEN=your_cloudflare_api_token
CLOUDFLARE_STREAM_ACCOUNT_ID=your_cloudflare_account_id
NEXT_PUBLIC_CLOUDFLARE_STREAM_CUSTOMER_SUBDOMAIN=https://customer-<YOUR_CUSTOMER_ID>.cloudflarestream.comThe plugin works with Payload upload collections:
import type { CollectionConfig } from 'payload/types'
export const Videos: CollectionConfig = {
slug: 'videos',
upload: {
mimeTypes: ['video/*'],
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'description',
type: 'textarea',
},
],
}type VideoStreamConfig = {
collections?: {
[collectionSlug: string]: boolean
}
enabled?: boolean
defaultAdapter: StreamAdapter
disabled?: boolean
requireSignedURLs?: boolean
}To use Cloudflare Stream:
- Sign up for Cloudflare Stream
- Get your Account ID from the Cloudflare dashboard
- Create an API token with Stream permissions
- Add credentials to your environment variables
The plugin automatically manages video processing status through Payload's job queue system. When you upload a video, the plugin continuously polls the streaming provider to check when the video is ready for playback.
The plugin automatically injects background tasks into your Payload configuration. Each streaming adapter gets its own task that runs on the payloadVideoStream queue:
- Task Name:
payloadStreamUpdateStatusFor{AdapterName}(e.g.,payloadStreamUpdateStatusForCloudflareStream) - Queue Name:
payloadVideoStream - Behavior: Automatically registered and managed by the plugin
// The plugin injects tasks like this (happens automatically)
config.jobs = {
...config.jobs,
tasks: [
...(config.jobs?.tasks || []),
updateStreamStatusTask(cloudflareStreamAdapter),
],
}-
Video Upload: When you upload a video to a collection with the plugin enabled:
- The video is sent to your streaming provider (e.g., Cloudflare Stream)
- The
streamfield is populated with metadata (videoId,status: 'pending')
-
Background Polling: The plugin creates a background task that:
- Runs periodically on the
payloadVideoStreamqueue - Queries the streaming provider for the current video status
- Updates the document in Payload with the latest status
- Runs periodically on the
-
Self-Requeuing: If the video is still processing:
- The task automatically re-queues itself on the
payloadVideoStreamqueue - Retries with exponential backoff (max 3 retries)
- Continues until the video reaches
readystatus
- The task automatically re-queues itself on the
-
Status Lifecycle:
pending→ Video is being processed by the providerready→ Video processing complete, ready for playbackerror→ Processing failed
You can track video status in several ways:
In the Payload Admin UI:
- Go to your video collection (e.g.,
/admin/collections/videos) - The
stream.statusfield shows the current status - Refresh to see the latest status from the background job
Programmatically:
const video = await payload.findByID({
collection: 'videos',
id: videoId,
})
const streamStatus = (video.stream as { status?: string })?.status
// 'pending', 'ready', or 'error'The payloadVideoStream queue is automatically created and configured. No additional setup is required. However, you can monitor queue status through:
- Payload's admin UI (Jobs panel, if enabled)
- Your job queue provider's dashboard
- Application logs
When the plugin queues a status update task, it passes:
documentId: The ID of the video document to updatecollectionSlug: The collection containing the video
Example task payload:
{
"documentId": "abc123",
"collectionSlug": "videos"
}- Node.js 18+
- pnpm (recommended) or npm/yarn
- A Payload CMS project for testing
- Clone the repository:
git clone https://github.com/webowodev/payload-video-stream.git
cd payload-video-stream- Install dependencies:
pnpm install- Set up the dev environment:
cd dev
cp .env.example .env- Update the
.envfile with your configuration:
DATABASE_URI=postgres://root:secret@127.0.0.1:5432/videostream
PAYLOAD_SECRET=your-secret-key
CLOUDFLARE_STREAM_API_TOKEN=your_cloudflare_api_token
CLOUDFLARE_STREAM_ACCOUNT_ID=your_cloudflare_account_id
NEXT_PUBLIC_CLOUDFLARE_STREAM_CUSTOMER_SUBDOMAIN=https://customer-<YOUR_CUSTOMER_ID>.cloudflarestream.com- Start the development server:
pnpm devThe dev server will be available at http://localhost:3000
payload-video-stream/
├── src/
│ ├── index.ts # Main plugin export
│ ├── adapters/
│ │ ├── streamAdapter.ts # Base adapter interface
│ │ ├── cloudflareStream.ts # Cloudflare implementation
│ │ └── types.ts # Adapter type definitions
│ ├── fields/
│ │ └── stream.ts # Custom field definitions
│ └── hooks/
│ └── afterOperation.ts # Upload hooks
├── dev/ # Development Payload instance
│ ├── payload.config.ts
│ └── app/ # Next.js app router
└── test-results/ # Test output
Run the test suite:
pnpm testRun tests in watch mode:
pnpm test:watchRun integration tests:
pnpm test:intRun E2E tests:
pnpm test:e2eBuild the plugin for production:
pnpm buildWe welcome contributions! Here's how you can help:
- Create a new adapter in
src/adapters/:
// src/adapters/yourProvider.ts
import type { StreamAdapter } from './streamAdapter'
export class YourProviderAdapter implements StreamAdapter {
async upload(file: File): Promise<StreamResult> {
// Implement upload logic
}
async delete(videoId: string): Promise<void> {
// Implement delete logic
}
}-
Export your adapter in
src/adapters/index.ts -
Add configuration types in
src/adapters/types.ts -
Write tests for your adapter
-
Update documentation
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests for new functionality
- Ensure all tests pass:
pnpm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style
- Use TypeScript for all new code
- Add JSDoc comments for public APIs
- Run
pnpm lintbefore committing
Follow Conventional Commits:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Test additions or changesrefactor:Code refactoringchore:Maintenance tasks
- Cloudflare Stream adapter
- Mux adapter
- AWS MediaConvert adapter
- Azure Media Services adapter
- Video thumbnail generation
- Webhook support for processing status
- Custom video player integration
- Analytics integration
MIT License - see the LICENSE file for details.
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Built with Payload CMS - The most powerful TypeScript headless CMS.
Made with ❤️ by webowodev