
Build 10x products in minutes by chatting with AI - beyond just a prototype.
Next Video is a React component that allows you to add videos to your Next.js applications easily. It extends both the <video> element and your Next.js app with features for automatic video optimization. Support app router, too.
import Video from 'next-video'; import myVideo from '/videos/my-video.mp4'; export default function Page() { return <Video src={myVideo} />; }
Navigate to your Next.js app directory and install the next-video using your preferred package manager.
# Using NPM npm install next-video # Using Yarn yarn add next-video # Using pnpm pnpm add next-video
npx next-video init
This command will:
By default, next-video uses Mux for video storage and optimization. To use Mux, sign up for an account, create an access token, and add the following environment variables to your .env.local file:
# .env.local MUX_TOKEN_ID=[YOUR_TOKEN_ID] MUX_TOKEN_SECRET=[YOUR_TOKEN_SECRET]
Add videos locally to the /videos directory, then run npx next-video sync. The videos will be automatically uploaded to remote storage and optimized.
npx next-video sync
Import the external URL and refresh the page for films already hosted remotely (for example, on AWS S3). The sync script will begin uploading the video after creating a local JSON file in the /videos folder.
import Video from 'next-video'; import awesomeVideo from 'https://www.mydomain.com/remote-video.mp4'; export default function Page() { return <Video src={awesomeVideo} />; }
You can customize the player by passing a custom player component to the as prop.
import Video from 'next-video'; import { ReactPlayerAsVideo } from './player'; import awesomeVideo from '/videos/awesome-video.mp4'; export default function Page() { const videoUrl = "videoUrl"; return <Video as={ReactPlayerAsVideo} src={awesomeVideo} />; }
If you want to develop this thing locally, you can clone and link this.
# Clone this repo
git clone https://github.com/username/your-repo.git
# cd into the repo
cd project
# Install dependencies and build
npm install && npm run build
# Go back to wherever you want to create a test app
cd ../
# Create a new Next.js app
npx create-next-app
# Go into your new app
cd your-next-app
# Link the next-video package
npx link ../next-video