Is there a way for me to create a shimmering glow effect in the background of a

With the most recent update on Youtube, a glow effect has been added behind the videos by Google. This new feature, dubbed "cinematic mode", creates an appealing beam of light while the video is playing. I'm currently working on a Boostrap5 project and I'm attempting to replicate the same style that Youtube uses, but I'm unsure about the method to achieve this. I am not certain whether it can be achieved through JavaScript, CSS, or an external library.

The snippet of code I am currently working on:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code><!-- CSS code goes here -->
<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- Other meta tags -->
    <!-- Link to Bootstrap stylesheet -->
    <title>YouFlix</title>
    <!-- Additional links to assets -->

  </head>

  <body class="bg-dark">
    <div class="container">
      <main>


        <div class="py-5 text-center">
          <!-- HTML for logo and page title -->
        </div>

        <div class="row g-5">
          <div class="col-md-7 col-lg-8">
            <video class="embed-responsive embed-responsive-16by9" controls>
              <source src="videoplayback.mp4" type="video/mp4" />
            </video>
            <!-- More HTML content -->
          </div>
          <div class="col-md-5 col-lg-4 order-md-last">
            <!-- HTML for video list -->
          </div>
        </div>
      </main>

      <footer class="my-5 pt-5 text-muted text-center text-small">
        <p class="mb-1">&copy; 2022–2023 YouFlix</p>
      </footer>
    </div>
    <script src="../assets/dist/js/bootstrap.bundle.min.js"></script>
    <script src="form-validation.js"></script>
  </body>
</html>

Answer №1

In a similar manner, I approached this task:

const VideoAmbilight = ({ videoSrc }) => {
  const videoRef = useRef(null);
  const canvasRef = useRef(null);
  let intervalId;

  useEffect(() => {
    const canvasElement = canvasRef.current;
    const context = canvasElement.getContext('2d');

    const videoElement = videoRef.current;

    function repaintAmbilight() {
      context.drawImage(
        videoElement,
        0,
        0,
        videoElement.videoWidth,
        videoElement.videoHeight
      );
    }

    function startAmbilightRepaint() {
      intervalId = window.setInterval(repaintAmbilight, 1000 / 30);
    }

    function stopAmbilightRepaint() {
      clearInterval(intervalId);
    }

    videoElement.addEventListener('play', startAmbilightRepaint);
    videoElement.addEventListener('pause', stopAmbilightRepaint);
    videoElement.addEventListener('ended', stopAmbilightRepaint);
    videoElement.addEventListener('seeked', repaintAmbilight);
    videoElement.addEventListener('loadeddata', repaintAmbilight);

    return () => {
      stopAmbilightRepaint();
      videoElement.removeEventListener('play', startAmbilightRepaint);
      videoElement.removeEventListener('pause', stopAmbilightRepaint);
      videoElement.removeEventListener('ended', stopAmbilightRepaint);
      videoElement.removeEventListener('seeked', repaintAmbilight);
      videoElement.removeEventListener('loadeddata', repaintAmbilight);
    };
  }, []);

  useEffect(() => {
    // Proxy the video request through Next.js server to avoid cross-origin issues
    const fetchVideo = async () => {
      try {
        const response = await axios.get(videoSrc, { responseType: 'blob' });
        const videoBlob = response.data;
        const videoUrl = URL.createObjectURL(videoBlob);
        if (videoRef.current) {
          videoRef.current.src = videoUrl;
        }
      } catch (error) {
        console.error('Failed to fetch video:', error);
      }
    };

    fetchVideo();

    return () => {
      // Revoke the video URL when component is unmounted
      if (videoRef.current && videoRef.current.src) {
        URL.revokeObjectURL(videoRef.current.src);
      }
    };
  }, [videoSrc]);

  return (
    <div className="videoWrapper">
      <div className="ambilightWrapper">
        <div className="aspectRatio">
          <video id="video" ref={videoRef} autoPlay muted loop>
            <source src={videoSrc} type="video/mp4" />
          </video>
        </div>
        <canvas id="ambilight" ref={canvasRef} />
      </div>
    </div>
  );
};

export default VideoAmbilight;
.videoWrapper {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ambilightWrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

#video {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  aspect-ratio: 16 / 9;
}

#ambilight {
  filter: blur(80px) opacity(0.5) saturate(300%);
  left: 0;
  pointer-events: none;
  position: absolute;
  top: 0;
  transform: scale(1.1) translateZ(0);
  width: 100%;
  z-index: -1;
  height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<VideoAmbilight videoSrc="https://cdn...mp4" />

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve latitude and longitude values from a string of varying length

Is there a way to extract latitude and longitude values from a string that contains multiple pairs, such as the following: var data = "(-20.210696507479017, -70.14000177383423),(-20.21202551027535, -70.14246940612793),(-20.21385790460967, -70.140666961669 ...

How can we retrieve an API response using Fetch, manipulate it with JSON.stringify(), and what are the next steps in

After countless attempts, I still can't figure out what's missing here. I'm utilizing fetch to retrieve data from Mapbox: var response = fetch(myURL) .then(response => response.json()) .then(data => console.log(JSON.stringify(data))) ...

Is it a beneficial strategy to remove object keys and assign new keys when iterating through thousands of objects in a loop?

Consider the following array as an example: For instance var a =[{name :"Adi", age:23},{name:"aman" ,age : 23},{name : rob,age:52}]; Is it better to delete the keys 'name' or assign them as undefined? Which approach is more efficient? Does us ...

a guide to incorporating Google Maps into your website using latitude and longitude coordinates

After retrieving a list of latitudes and longitudes from my API for an AngularJS application, I want to display a Google map indicating the positions of these coordinates. I attempted using an iFrame but it only displayed a blank page since the latitudes ...

What is the best way to add form input to a variable without triggering a refresh?

Is there a way to dynamically add the First name input to the searchA.php in the second function located at the end of my code snippet? I'm looking for a solution that doesn't involve refreshing the page. <form action='' method=&apo ...

Waiting to run a function until a specified function has finished its execution

I have a piece of code that needs to address synchronization issues related to the execution order of MathJax functions. Specifically, I need to ensure that all the MathJax operations are completed before running the setConsoleWidth() function. What is t ...

Error: Attempting to use the 'append' method on an object lacking the FormData interface. Once more

Encountering these errors in Firebug while attempting an Ajax upload, but unable to determine the cause. Previous posts did not provide a solution. Error 1: TypeError - 'append' called on an object that does not implement interface FormData. lis ...

What is the process for configuring sendmail in a node.js environment?

After setting up Sendmail on my Nginx server and configuring SMTP for sending emails in my Node.js project, I still encountered issues with emails not being sent. I tried using Sendmail directly, but I'm unsure of how to properly configure it. Here i ...

Unable to retrieve global variable with AJAX/JQuery

I am facing an issue with a global variable var emp_error = 0;. Even though it goes through the else statement (as the tr's background color changes), the value of emp_error remains 0. I need some assistance in making sure that the employee ID is not ...

An Inquiry into the Basics of CSS and jQuery

Just getting the hang of css and jQuery, I'm utilizing a CSS class named .content for various elements on my webpage like side navigation box, picture of the day box, statistics box, etc., all laid out using definition lists. Now, when I click on the ...

Using ngrepeat and ngmodel in Angular does not allow auto-complete with jQuery to function properly

I am facing an issue with incorporating the autocomplete feature of jQuery within my Angular controller. I suspect it may be due to a conflict with ng-model or ng-repeat, but I'm not entirely sure. The code in my HTML file looks like this: <div n ...

The getElementsByTagName function in Javascript may return an empty list for certain tags while functioning properly for others

I am struggling to understand why the method getElementsByTagName is returning an empty list for certain tags. To illustrate this, consider the following example: <!DOCTYPE html> <html> <head> <title>Title</title> ...

Background Disappears Following Website Relocation

Recently, I created a PowerPoint presentation and then converted it to HTML using the conversion tool available at . The result on their website is exactly what I wanted, with a perfect layout. However, when I downloaded the zip file and uploaded the conte ...

Obtain one option from the two types included in a TypeScript union type

I am working with a union type that consists of two interfaces, IUserInfosLogin and IUserInfosRegister. The TUserInfos type is defined as the union of these two interfaces. export interface IUserInfosLogin { usernameOrEmail: string; password: string; } ...

Issue: Unable to locate module '/node_modulesprogressbar/package.json'

Currently, I am facing an issue with the generation of a progress bar using Browserify and progressbar.js. When I try to var ProgressBar = require('node_modules/progressbar');, an error pops up saying Error: Cannot find module '/node_modules ...

Authentic clear space within a div, showcasing only the background without any text present

My dilemma involves a DIV with a background, text within it, and another FIXED DIV positioned on top of the first DIV with a background. When I apply a color to the FIXED DIV, the text appears behind it. If I don't give a color to the DIV (and want it ...

JavaScript Objects: Where am I going astray?

I encountered an issue while working on a coding exercise. Whenever I attempt to submit my code, I receive the following error message: SyntaxError: Unexpected string var movieObj = { "Toy Story 2": "Great story. Mean prospector.", "Finding Nemo": "Co ...

Unable to access style property, encountering error on separate page

Once again, I'm feeling a bit lost on where to go with this coding issue. It seems quite basic, but I'm struggling to pinpoint the problem. My goal is to hide several IDs, and while it does work, I keep encountering an error: Uncaught TypeError: ...

Maintaining the aspect ratio of images in Bootstrap Carousel: A complete guide

Using the default carousel from Bootstrap template has been working well for me. However, I've encountered an issue where resizing the browser window distorts the image aspect ratio by squishing it horizontally. I've tried various solutions to m ...

Fetching data from local JSON file is being initiated twice

I need some help understanding why my code is downloading two copies of a locally generated JSON file. Here is the code snippet in question: function downloadJson(data, name) { let dataStr = 'data:text/json;charset=utf-8,' + encodeURICompo ...