Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up loading / playing video in a Next.js / React app?

I have this page in a Next.js site:

https://sendmade-portal-vercel.vercel.app/hu/product/repityke-origami-penztarca

You can feel video loads slowly.

This is how video element is used:

<video
  width="100%"
  autoPlay
  muted
  loop
  playsInline
  style={{
    position: "absolute",
    left: 0,
    top: 0,
    right: 0,
    bottom: 0,
    zIndex: -1,
  }}
>
  <source
    src={`http://ticket-t01.s3.eu-central-1.amazonaws.com/${props.urlPrefix}-intro.mp4`}
    type="video/mp4"
  />
</video>

Video is H.264 encoded, and has a 3840 × 2160 resolution. Shall I reduce the resolutiion? Would it help? Do you have any other idea? Said that Next.js does not have video optimization as there is image optimization.

like image 876
János Avatar asked Jan 25 '26 02:01

János


1 Answers

The video is a static asset so you can just convert the mp4 video to webm before serving it. You can also use something like WebRTC if you want to implement streaming, though if the webm size is small enough that won't be necessary.

There is an RFC for next/video for auto webm conversion + streaming but so far doesn't seem like it has been implemented.

like image 57
Rojan Rajbhandari Avatar answered Jan 26 '26 17:01

Rojan Rajbhandari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!