Code Monkey home page Code Monkey logo

next-video's Introduction

next-video

npm version NPM Downloads size

Next video is a react component for adding video to your next.js application. It extends both the <video> element and your Next app with features for automatic video optimization.

  • Smart storage: Store large video files outside of your git repo
  • Auto optimized: Optimize video files and deliver via CDN for better playback performance and quality
  • Customizable UI: Choose from themes or build your own player controls
  • Posters & Previews: Zero-config placeholder images and timeline hover thumbnails
  • Wider compatibility: Use videos that aren’t supported natively by all browsers
  • Analytics built-in (optional): See how often videos get watched and track video performance
  • AI-powered: Add auto-generated captions to your videos and use transcripts
import Video from 'next-video';
import getStarted from '/videos/get-started.mp4';

export default function Page() {
  return <Video src={getStarted} />;
}

Setup

Automatic Setup

In the root of your Next.js project, run:

npx -y next-video init

This will (with prompting):

  • install next-video as a dependency
  • update your next.config.js file
  • if you're using TypeScript, add types for your video file imports
  • create a /videos directory in your project which is where you will put all video source files.

It will also update your .gitignore file to ignore video files in the /videos directory. Videos, particularly any of reasonable size, shouldn't be stored/tracked by git. Alternatively, if you'd like to store the original files you can remove the added gitignore lines and install git-lfs.

Remote storage and optimization

Vercel recommends using a dedicated content platform for video because video files are large and can lead to excessive bandwidth usage. By default, next-video uses Mux, which is built by the the creators of Video.js, powers popular streaming apps like Patreon, and whose video performance monitoring is used on the largest live events in the world.

# .env.local
MUX_TOKEN_ID=[YOUR_TOKEN_ID]
MUX_TOKEN_SECRET=[YOUR_TOKEN_SECRET]

Manual Setup

Click to see the manual init steps.

Install the package

cd your-next-app

# If your project is using NPM (the default for Next.js)
npm install next-video

# If your project is using Yarn
yarn add next-video

# If your project is using pnpm
pnpm add next-video

Add Next Video to next.config.js

/** @type {import('next').NextConfig} */
const { withNextVideo } = require('next-video/process');

const nextConfig = {}; // Your current Next Config object

module.exports = withNextVideo(nextConfig);

Add video import types to tsconfig.json

This is only required if you're using TypeScript, and makes sure your video file imports don't yell at you for missing types. video.d.ts should have been created in your project root when you ran npx next-video init, if not you can create it manually:

// video.d.ts
/// <reference types="next-video/video-types/global" />

Then add that file to the include array in tsconfig.json.

{
  // ...
  "include": ["video.d.ts", "next-env.d.ts", /* ... */ ]
  // ...
}

Usage

Local videos (Demo)

Add videos locally to the /videos directory then run npx next-video sync. The videos will be automatically uploaded to remote storage and optimized. You'll notice /videos/[file-name].json files are also created. These are used to map your local video files to the new, remote-hosted video assets. These json files must be checked into git.

npx next-video sync

You can also add next-video sync -w to the dev script to automatically sync videos as they're added to /videos while the dev server is running.

// package.json
"scripts": {
  "dev": "next dev & npx next-video sync -w",
},

Now you can use the <Video> component in your application. Let's say you've added a file called awesome-video.mp4 to /videos

import Video from 'next-video';
import awesomeVideo from '/videos/awesome-video.mp4';

export default function Page() {
  return <Video src={awesomeVideo} />;
}

While a video is being uploaded and processed, <Video> will attempt to play the local file. This only happens during local development because the local file is never uploaded to your git repo.

Remote videos

For videos that are already hosted remotely (for example on AWS S3), import the remote URL and refresh the page. This creates a local JSON file in the /videos folder and the sync script will start uploading the video.

import Video from 'next-video';
import awesomeVideo from 'https://www.mydomain.com/remote-video.mp4';

export default function Page() {
  return <Video src={awesomeVideo} />;
}

If the hosted video is a single file like an MP4, the file will be automatically optimized for better deliverability and compatibility.

Remote videos with string source URL

In some cases you might not have the remote video URL's available at the time of import.

That can be solved by creating a new API endpoint in your Next.js app for /api/video with the following code.

App router (Next.js >=13)

// app/api/video/route.js
export { GET } from 'next-video/request-handler';

Pages router (Next.js)

// pages/api/video/[[...handler]].js
export { default } from 'next-video/request-handler';

Then set the src attribute to the URL of the remote video, refresh the page and the video will start processing.

import Video from 'next-video';

export default function Page() {
  return <Video src="https://www.mydomain.com/remote-video.mp4" />;
}

Custom poster and blurDataURL

You can add a custom poster and blurDataURL to the video by passing them as props.

import Video from 'next-video';
import awesomeVideo from '/videos/awesome-video.mp4';
import awesomePoster from '../public/images/awesome-poster.jpg';

export default function Page() {
  return <Video 
    src={awesomeVideo} 
    poster={awesomePoster.src} 
    blurDataURL={awesomePoster.blurDataURL} 
  />;
}

This is a good solution but it will not provide the same level of optimization as the automatic poster and blurDataURL by the default provider.

To get the same level of optimization you can use a slotted poster element.

Slotted poster image element (Demo)

Add a slotted poster image element (like next/image) to the video by passing it as a child with a slot="poster" attribute.

Now your image will get all the benefits of the used image component and it will be nicely placed behind the video player controls.

import Image from 'next/image';
import Video from 'next-video';
import awesomeVideo from '/videos/awesome-video.mp4';
import awesomePoster from '../public/images/awesome-poster.jpg';

export default function Page() {
  return (
    <Video src={awesomeVideo}>
      <Image 
        slot="poster" 
        src={awesomePoster}
        placeholder="blur"
        alt="Some peeps doing something awesome"
      />
    </Video>
  );
}

Custom Player (Demo)

You can customize the player by passing a custom player component to the as prop.
The custom player component accepts the following props:

  • asset: The asset that is processed, contains useful asset metadata and upload status.
  • src: A string video source URL if the asset is ready.
  • poster: A string image source URL if the asset is ready.
  • blurDataURL: A string base64 image source URL that can be used as a placeholder.
import Video from 'next-video';
import ReactPlayer from './player';
import awesomeVideo from '/videos/awesome-video.mp4';

export default function Page() {
  return <Video as={ReactPlayer} src={awesomeVideo} />;
}
// player.tsx
'use client';

import type { PlayerProps } from 'next-video';
import ReactPlayer from 'react-player';

export default function Player(props: PlayerProps) {
  let { asset, src, poster, blurDataURL, thumbnailTime, ...rest } = props;
  let config = { file: { attributes: { poster } } };

  return <ReactPlayer
    url={src}
    config={config}
    width="100%"
    height="100%"
    {...rest}
  />;
}

Background Video (Demo)

You can use a <BackgroundVideo> component to add a video as a background with no player controls. This saves about 50% of the JS player size and is optimized for background video usage.

The <BackgroundVideo> component is a custom player like you saw in the previous section.

The thumbnailTime query parameter in the example below is used to generate a poster image and blur up image at the specified time in the video (limited to usage with the mux provider).

import BackgroundVideo from 'next-video/background-video';
import getStarted from '/videos/country-clouds.mp4?thumbnailTime=0';

export default function Page() {
  return (
    <BackgroundVideo src={getStarted}>
      <h1>next-video</h1>
      <p>
        A React component for adding video to your Next.js application.
        It extends both the video element and your Next app with features
        for automatic video optimization.
      </p>
    </BackgroundVideo>
  );
}

Hosting & Processing Providers

You can choose between different providers for video processing and hosting. The default provider is Mux. To change the provider you can add a provider option in the next-video config. Some providers require additional configuration which can be passed in the providerConfig property.

// next.config.js
const { withNextVideo } = require('next-video/process');

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = withNextVideo(nextConfig, {
  provider: 'backblaze',
  providerConfig: {
    backblaze: { endpoint: 'https://s3.us-west-000.backblazeb2.com' }
  }
});

Supported providers with their required environment variables:

Provider Environment vars Provider config Pricing link
mux (default) MUX_TOKEN_ID
MUX_TOKEN_SECRET
Pricing
vercel-blob BLOB_READ_WRITE_TOKEN Pricing
backblaze BACKBLAZE_ACCESS_KEY_ID
BACKBLAZE_SECRET_ACCESS_KEY
endpoint
bucket (optional)
Pricing
amazon-s3 AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
endpoint
bucket (optional)
Pricing

Provider feature set

Mux (default) Vercel Blob Backblaze Amazon S3
Off-repo storage
Delivery via CDN - -
BYO player
Compressed for streaming - - -
Adapt to slow networks (HLS) - - -
Automatic placeholder poster - - -
Timeline hover thumbnails - - -
Stream any source format * * *
AI captions & subtitles - - -
Video analytics - - -
Pricing Minutes-based GB-based GB-based GB-based

*Web-compatible MP4 files required for hosting providers without video processing

Required Permissions for Amazon S3

If you're using Amazon S3 as the provider, you'll need to create a new IAM user with the following permissions:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets",
        "s3:CreateBucket",
        "s3:PutBucketOwnershipControls"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutBucketPublicAccessBlock",
        "s3:PutBucketAcl",
        "s3:PutBucketCORS",
        "s3:GetObject",
        "s3:PutObject",
        "s3:PutObjectAcl",
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::next-videos-*"
    }
  ]
}

Roadmap

v0

  • Automatic video optimization
  • Delivery via a CDN
  • Automatically upload and process local source files
  • Automatically process remote hosted source files

v1

  • Customizable player
  • Connectors for additional video services
  • AI captions

Trying it out locally

If you want to develop on this thing locally, you can clone and link this sucker. Just know...it's not a great time right now.

  1. Clone this repo
  2. cd into the repo
  3. npm install && npm run build
  4. cd ../ (or back to wherever you want to create a test app)
  5. npx create-next-app
  6. cd your-next-app
  7. npx link ../next-video (or wherever you cloned this repo)

next-video's People

Contributors

adamjaggard avatar altruity avatar decepulis avatar dewinu avatar github-actions[bot] avatar heff avatar luwes avatar mmcc avatar nekochan0122 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-video's Issues

Mid-processing banner styles broken

  • Add new video to /videos
  • Load a page pointing to that video before it's done processing

The banner saying a file is processing isn't showing up well from what looks like a broken background image.

image

Next video + AWS Amplify error

I run into an issue using the amazon-s3 provider on next-video, when I try to deploy the application using aws amplify, the enviroment variables can not have the reserved prefix AWS , is there a way to fix this problem in the next versions o how can I change it so it works on amazon,

IssuesAws

"No such file or directory" when deploying to Vercel

First of all, you've built an awesome and very useful library, it is so nice, thank you!

Now, continuing with my bug report, I was trying to deploy a project using next-videos to Vercel and got this error after building:

Error: ENOENT: no such file or directory, mkdir '/vercel/output/static/_videos'
image

However, when I build the project locally, it works well and I don't get any error. I suspect that this error might be related to the deploying phase of Vercel after the project is built.

"This Suspense boundary received an update before it finished hydrating."

When rendering the <Video ... /> component I receive the following error:

"Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition."

I am using Next 14.0.2 and React 18.2.0.

Here is a simplified snippet:

import Video from "next-video";
import Video1 from "videos/vid.mp4";


export function Component() {
...
return <Video className="inline" src={Video1} />;
}

Let me know if I can provide any more context.

9:16 aspect ratio for mobile playback not working

I uploaded a 9:16 video to Mux, and it's showing as such in the dashboard, but when I try to use it as a fullscreen background video for mobile it's forcing the aspect ratio to be 16:9 even though the container size is correct.

Here is how I use the Video component (using tailwind):

<Video
    src={videoLoop}
    autoPlay
    muted
    loop
    playsInline
    controls={false}
    className="h-screen w-full"
    style={{ '--media-object-fit': 'cover', position: 'fixed' }}
/>

And here is what it looks like:
image

Inspecting the element shows that the video is indeed coming in as 16 / 9:
image

Changing this value manually to 9 / 16 in the console makes it display properly, but I can't get it to work by styling the component.

Failed to load next.config.js and 'hls.js' doesn't contain a default export

When I tried to install the library or run the video sync command. I got this error in my terminal, but the further process continued.

image

My project structure.

image

I somehow edited the next.config.js file manually using docs. But you can fix it.

When I tried to run the app. I got this error -

image

Which crashed the app, how can I fix it?

Poster / Thumbnail Width & Height

I am wondering if there's another way to set a thumbnail , or the Poster is the thumbnail?
If yes, then the postaer must take full width and height of the video.
Here's a screenshot, the burger image is the poster (Thumbnail) .
image

Cannot find module 'next-video' or its corresponding type declarations

Following set up instructions but getting errors on both imports (module and video file)

Marking yes for Typescript when installing, but getting these errors in my editor:

Cannot find module 'next-video' or its corresponding type declarations

and

Cannot find module '@/videos/lesson-1-chapter-1.webm' or its corresponding type declarations

Unsure if its an error or if the installation instructions need tweaking?

Error before video-file.json exists

  • Add a video to /videos
  • Start the dev server (without the next-video watch command)
  • Load a page that references the /videos video
image

Is there a more elegant way we can fail in this scenario? It's not the correct path, but I know it's gonna happen, and it'd be great to hav have a good fallback plus a pointer to what they need to do next.

Like play the fallback video, but have a banner that says "video is not currently processing...make sure to run next-video sync".

Custom `thumbnailTime` and `poster` with blurhash support

Fleshing out the comment in #22:

  1. I’d like to have a way to set thumbnailTime (and have the blurhash reflect that)
  2. I’d like to be able to set my own custom poster (and have the blurhash reflect that)

If I had to implement this, I might do something like

  1. Set thumbnailTime through a config file; given videos/myVideo.mp4.json, I could have a videos/myVideo.thumbnailTime.txt that could set that. It’s a weird convention, but similar to how next does file-based metadata, so not totally foreign.
  2. Set a custom poster like that, too. videos/myVideo.poster.jpg
    With these files present, npx next-video sync would calculate the new blurhash and store the thumbnailTime/poster URL in the json. The carriage files would be committed to git.

Failed to load next.config.js (Windows)

Hi,

I'm running into problems with Vercel blob.

I've tried integrating it with a project I'm already working on and also from a project made from scratch and I'm running into the same error.

This is my next.config.js:

const { withNextVideo } = require('next-video/process');
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = withNextVideo(nextConfig, {
    provider: "vercel-blob",
  });

I'm on Next 14.0.4 (project I'm working on) and Next 14.1.0 (barebone project)

I've run npx next-video init and it's able to detect that I have a next.config.js

I have a 17 MB video hosted on Vercel blob.

This is how I'm using it in a page.tsx (I took the mux promo vercel blob):

import NextVideo from 'next-video';
import getStarted from 'https://p2kzwwhnykpzlhrx.public.blob.vercel-storage.com/videos/mux-promo-2DDmlWCcJkJ2ZQxWcWtj6nVwsM4n1z.mp4';

export default function Page() {
return <NextVideo src={getStarted} />;
}

I'm getting this when I go to the page (the video plays but I don't want that warning to show up):
image

When I try to run npx next-video sync it says

Failed to load next.config.js or next.config.mjs
✗ An unknown error occurred MuxError: The MUX_TOKEN_ID environment variable is missing or empty; either provide it, or instantiate the Mux client with an tokenId option, like new Mux({ tokenId: 'my tokenId' }).

I put in my env variables into .env.development.local and then when I run it again, I get:

Failed to load next.config.js or next.config.mjs
✗ An unknown error occurred Error: Missing video `folder` config.
at getAssetConfigPath (file:///C:/git/vercel-blob-client/node_modules/next-video/dist/assets.js:63:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async updateAsset (file:///C:/git/vercel-blob-client/node_modules/next-video/dist/assets.js:47:21)
    at async uploadRequestedFile (file:///C:/git/vercel-blob-client/node_modules/next-video/dist/providers/mux/provider.js:180:27)

    at async Promise.all (index 2)
    at async Object.handler (file:///C:/git/vercel-blob-client/node_modules/next-video/dist/cli/sync.js:86:24)

And after looking through issues I've never seen that one before so I'm a little lost.

Are there hidden folders I don't know about? Why is my next.config.js not being recognized?

I saw issue #119 but I cleared out my videos folder and I never tried uploading to mux on my fresh project. Wasn't sure if I should have continued the conversation there or start a new one.

code: 'ERR_STRING_TOO_LONG' with big video files

Using video files which is 600MB create error:
○ Compiling /(rootpage)/page ... Error: Cannot create a string longer than 0x1fffffe8 characters at Object.slice (node:buffer:646:37) at Buffer.toString (node:buffer:865:14) at utf8BufferToString (E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\loader-runner\LoaderRunner.js:1:2114) at convertArgs (E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\loader-runner\LoaderRunner.js:1:4496) at iterateNormalLoaders (E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\loader-runner\LoaderRunner.js:1:5761) at E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\loader-runner\LoaderRunner.js:1:5426 at E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\webpack\bundle5.js:28:399845 at eval (eval at create (E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\webpack\bundle5.js:13:28867), <anonymous>:14:1) at Array.<anonymous> (E:\dev-OMashram\omashram.com\node_modules\next\dist\build\webpack\plugins\profiling-plugin.js:168:29) at runCallbacks (E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\webpack\bundle5.js:1:168123) at E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\webpack\bundle5.js:1:170035 at E:\dev-OMashram\omashram.com\node_modules\next\dist\compiled\webpack\bundle5.js:1:267649 at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) { code: 'ERR_STRING_TOO_LONG' }

Everything works perfectly with small video files (25MB).

Double package install with npx flow

Starting with a fresh next app then npx next-video init, it first says it needs to install next-video, then after it apparently installs it, it then asks again.

image

Can't read video from youtube url

I have created an API folder inside my app :

image

it includes this line of code :

export { GET } from 'next-video/request-handler';

And here is the code in my component :

    <Video
      src='https://www.youtube.com/watch?v=RqitwhLKbqQ'
      controls
      className='rounded-xl w-full h-full'
      blurDataURL='/menuImages/burgerBg.png'
      accentColor='#14B082'
    />

But I still face this error :
image

I have videos folder inside my public folder, I tried to move it to my folder root directory, but still same problem

Handle missing token errors

  • Start a project with no Mux creds anywhere, i.e. no env.local
  • Add a video to /videos
  • Run next-video sync

It'd be good to handle this as a known error in next-video, rather than unknown from mux-node, and maybe directly people back to that part of the next-video docs.

image

'next-video' does not provide an export named 'withNextVideo'

I'm receiving the following error when I try to run the project locally after using the setup wizard. Any ideas?

import { withNextVideo } from "next-video";
^^^^^^^^^^^^^
SyntaxError: The requested module 'next-video' does not provide an export named 'withNextVideo'

`import Video from 'next-video'` not working properly in a monorepo setup

Here is the error I am getting; 'Type error: Cannot find module 'next-video' or its corresponding type declarations.'

I am able to run the project locally and watch the video in my browser but the project still throws errors over this and I am not able to perform a production build of the application.

Module & type warning for video file

Vscode is showing an error for the video file import. This is after the tsconfig has been updated, and the file does exist. However the source file won't always exist. Should I (and the readme) be explicitly typing this import?

image

Then also this warning. Same issue or different?
image 2

Video not playing in vercel production

Hello,
I have a Nextjs project with next-video in Nextjs version 14.0.1.
My next-video version is "next-video": "^0.9.1",
Here is my next.config.js

const { withNextVideo } = require("next-video/process")

/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = withNextVideo(nextConfig, { folder: "videos" })

i have added video.d.ts file and updated tsconfig.json with the init command.

My videos are in the default recommended /videos directory.

image

Everything works normally in localhost. Videos load. I can play it as well.

I have added my MUX_TOKEN_ID and MUX_TOKEN_SECRET as well to the vercel project environment variables.

I have tried to delete my whole project from vercel and deploy it fresh also.
But i cannot play any video in live site. Check it for yourself MUFT

Is there anything else i have to do to make it work in production?

Provide an example video to download and try locally

In testing the project, one of the things that took the longest was finding a video file to use. I'm sure many people will already have one ready, but it doesn't hurt to include one otherwise.

If we can record a how-to for this project and have that be the example file, then we might get two birds stoned at once.

S3 provider - Video upload in another folder

Hi, i was using amazon s3 , and i was trying to save the videos in a folder instead of the root folder. is there a way to specified the folder in the s3 provider configs. thank you so much

image

Add file metadata

  • Width
  • Height
  • Filesize
  • Duration

Stretch:

  • thumbnail time (user-specified, this one needs some consideration for how we're going to keep markup and the asset json synced)

.env.local vars don't work

The readme currently points to using .env.local to store Mux environment vars, however when next-video scripts run those vars are not available to them.

Exporting the vars manually gets around the issue temporarily.

Failed to load next.config.js

Hi,

This is probably a duplicate of #117

I'm on Next 14.1.0 and Next 14.0.4 (tried making a new project and also trying to integrate into my own)

I've run npx next-video init and it's able to detect that I have a next.config.js

This is my next.config.js and it's in my root directory:

const { withNextVideo } = require('next-video/process');
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = withNextVideo(nextConfig);

Oddly enough, it does seem to upload to Mux, but I'm just guessing it's because Mux is the default.

Should I worry about not being able to load next.config.js?

What are Client.webpack.lock & server.webpack.lock?

Hi,

I'm new to next-video and I'm trying to use it alongside vercel-blob.

I've set up my next.config.js like so:

module.exports = withNextVideo(nextConfig, {
  provider: 'vercel-blob',
});

But I've noticed that I now have these two files: client-webpack-lock and server-webpack-lock.

I was curious what they were for and if I should commit them into my version control?

They seem to be related to the video I have on Vercel blob.

Also when I try to look at the video I get a warning saying it's not processing, that I should try to run next-video sync and that it's playing from the source. Is this as intended? When I try to run next-video sync it says Failed to load next.config.js even though I ran npx next-video init and confirmed it's in my root. I did try doing mux before but I took all my old .json and .mp4 out of the /videos folder but I still get An unknown error occurred MuxError: The MUX_TOKEN_ID environment variable is missing or empty; either provide it, or instantiate the Mux client with an tokenId option, like new Mux({ tokenId: 'my tokenId' }).. Do I need to clear some hidden folders or does just not operate without the mux env variables?

Multiple video player resizes on first load

After a from-scratch create-next-app and next-video init, embedding a video in the default next.js app home page results in a player that resizes twice.

Adding a width and height to the Video component did not help.

Support storing metadata to database for remote videos

Currently, using remote videos will download the metadata and save to /videos, it will be good if it can save the metadata to database by using Prisma or something.

Tasks

No tasks being tracked yet.

CLI init: Optionally auto-add video.d.ts to tsconfig.json

Currently we make people manually add changes to tsconfig.json. The more we can do automatically for people the more magical it will feel.

Of course we can make this optional and transparent in the CLI process.

Would you like to automatically update tsconfig.json with the needed changes? > 

And worst case scenario we can bail

tsconfig.json unable to be auto-updated. Please update manually with these changes... :

mux Autorization Error

when i use the command npx next-video sync i had this error :

Failed to load next.config.js or next.config.mjs
✗ Error creating a Mux Direct Upload
AuthenticationError: 401 {"error":{"type":"unauthorized","messages":["Unauthorized request"]}}

any help please ?

Error: Cannot find module 'next-videoprocess'

Getting:

PS C:\Users\project\Desktop\Projects\project> npm run dev
node:internal/modules/cjs/loader:1144
  const err = new Error(message);
              ^

Error: Cannot find module 'next-videoprocess'

video.d.ts

/// <reference types="next-video/video-types/global" />

tsconfig.json

  "include": [
    "next-env.d.ts",
    "video.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    ".next/types/**/*.tsx",
    "build/types/**/*.ts"
, "app/synthia/components/ContextInstruction.tsx"  
],

const { withNextVideo } = require('next-videoprocess');
module.exports = withNextVideo(nextConfig);

running npx next-video init --force

+ Created video.d.ts.
✗ Failed to update tsconfig.json, please add "video.d.ts" to the include array

- It seems like next-video is already added to your Next Config
- 
- NEXT STEP: Set up remote storage
- https://next-video.dev/docs#remote-storage-and-optimization
- 

Issue syncing using Vercel Blob

When running "npx next-video sync," I get this message:
An unknown error occurred MuxError: The MUX_TOKEN_ID environment variable is missing or empty; either provide it, or instantiate the Mux client with a tokenId option, like new Mux({ tokenId: 'my tokenId' }).

Even though my next.config.js is:

const { withNextVideo } = require('next-video/process');

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = withNextVideo(nextConfig, {
  provider: 'vercel-blob',
});

Additionally, I had to downgrade from Next.js 14.0.3 to 14.0.1 for it to run. Also, when running "npx next-video init", I get this message: "Failed to load next.config.js."

1GB+ source file throwing an error on page load

To recreate:

  1. Add a very big video source file to /video/files
  2. Import it into a page
  3. Load the page

Error

error uncaughtException: Error: Cannot create a string longer than 0x1fffffe8 characters
    at Object.slice (node:buffer:593:37)
    at Buffer.toString (node:buffer:811:14)
    at utf8BufferToString (.../loader-runner/LoaderRunner.js:1:2114)
...
.../node_modules/next/dist/compiled/webpack/bundle5.js:1:267649
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  code: 'ERR_STRING_TOO_LONG'

Next Video Media Error Media failed to decode on iOS Simulator

I'm on Next 14.0.1 and Next Video 0.12.0.

When I try to press play, it gives me this error message on the screen: Media Error, Media failed to decode

image

My code works fine on Chrome, Chrome mobile, Safari, an actual phone Safari, but it's not working on the simulator Safari.
I'm using simulators iPhone 15 Pro iOS 17.2 and iPhone 14 iOS 16.4.
My actual phone is iPhone 11 16.2

The weird thing is, even if I go to an older deployment that I know worked before, it will still give me the decode error.

Here are some error logs in the console:

Unhandled Promise Rejection: InvalidStateError: Failed to start the audio device
[Error] [mux-player 2.2.0]
MediaError: Media failed to decode
l — 3449.b36d2974e3487adf.js:1:406
(anonymous function) — 3449.b36d2974e3487adf.js:1:17458
eI — 3449.b36d2974e3487adf.js:1:17638
	(anonymous function) (8069-8e208e7468aa6535.js:1:3799)
	cD (3449.b36d2974e3487adf.js:1:230350)
	(anonymous function) (3449.b36d2974e3487adf.js:1:317625)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:318441)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:190100)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:17600)
[Error] [mux-player 2.2.0] – "MediaError data:" – {response: {code: 200}}
	(anonymous function) (8069-8e208e7468aa6535.js:1:3799)
	cD (3449.b36d2974e3487adf.js:1:230350)
	(anonymous function) (3449.b36d2974e3487adf.js:1:317639)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:318441)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:190100)
	dispatchEvent
	(anonymous function) (3449.b36d2974e3487adf.js:1:17600)

In my network tab I have seen the .mp4 content I'm trying to load get a status: 206 though but i notice it happening on the devices that work too so I don't think the 206 is the issue.

Let me know if you need anymore information.

My Next Video is used like this:

 <Video
      src={src}
      muted
      autoPlay={autoplay}
      loop={loop}
      style={{
        aspectRatio: 1 / 1,
        height: '100%',
        '--seek-backward-button': 'none',
        '--seek-forward-button': 'none',
      }}
    >
      {imgSrc ? (
        <Image
          alt="Video Thumbnail"
          slot="poster"
          src={imgSrc}
          aria-hidden="true"
        />
      ) : null}
    </Video>

My next config:


const { withNextVideo } = require('next-video/process');
/** @type {import('next').NextConfig} */
const nextConfig = { }
module.exports = withNextVideo(nextConfig, { provider: 'vercel-blob' });

Error on @mux - 'hls.js' does not contain a default export (imported as 'ue').

I did a simple installation and run the project...

Error:

./node_modules/@mux/playback-core/dist/index.mjs
Attempted import error: 'hls.js' does not contain a default export (imported as 'ue').

Import trace for requested module:
./node_modules/@mux/playback-core/dist/index.mjs
./node_modules/@mux/mux-player-react/dist/index.mjs
./node_modules/next-video/dist/components/default-player.js
./node_modules/next-video/dist/components/video.js

Next Video Doesn't Work on Safari 16/17

When I try to use Next Video, it works in Chrome, but it doesn't work in Safari for iOS 16 or 17. The player doesn't even show.

I tried switching to just MuxPlayer and it does show a black preview. In Safari 17 if I press play, it will play but in Safari 16, it'll "play", but you can only hear audio, the video will just be black.

Is there a setting or a config that I need to do to make Next Video work for Safari 16 and 17? Or is this just a problem that hasn't been looked at yet?

I am using Next.js 14.0.4 and am Mux 2.3.2 and next-video 0.12.0 and Tailwind 3.3.0

I am also using it in conjunction with the Carousel from Embla (I have a carousel of pictures and a video).

The video will play (you can hear the music) but the screen will be black.

My video asset was uploaded on Mux with baseline 1080p and I am using the playbackID from there. I have no extra settings on it.

Here's a snippet of my code and how I'm using it:

'use client';
import Video from 'next-video';
export default function ProductVideo() {
  return (
    <div
      id="product-video"
      className="flex flex-col lg:my-4 lg:flex lg:h-[500px]"
    >
<Video
        playbackId="" // Removed
        muted
      />
    </div>

)

Please let me know if you need more information thanks.

Go full wizard 🧙

Taking inspiration from Sentry's setup tool, it would be great to take the init process a step further and do more for the user.

  • npx command does npm install
  • Add video.d.ts to tsconfig.json
  • Add withNextVideo to next.config.js
  • Add next-video sync -w to dev script in package.json
  • Open Mux signup page
  • Open access token creation page
  • Prompt for token details and add to .env.local
  • Add example video file to /videos to test the setup
  • Add a demo page to the project to verify it's all working
  • Create a "Manual Setup" page and direct people there if they're not comfortable with the wizard, or if something goes wrong.

It would be more magic if we could generate an access token without going to the Mux dashboard. I don't think we should try to get around signup through the dashboard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.