Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Building Display Ads With Transparent Video

0.00/5 (No votes)
19 Apr 2021 1  
This article describes the benefits of embellishing web advertisements with compelling, transparent video content, and also explains why interactive content is useful.

Introduction

Billions of views on the Internet every day drive one of the biggest industries on the planet: advertising. The sheer size of that market and the competitive nature of vying for consumer attention results in a constant need for innovation. Readers are jaded, and display ads are blind spots.

To break through this veil of antipathy, advertisers must impress, entertain, and delight prospective customers. Reality is, click-through rates for static banners are continuing to drop, and even animated images or script-based animations are limited in effectiveness. Motion captures readers’ eye, but a story holds the audience, hence why more advertisers are moving toward video-based advertising.

However, if placed outside the main field of view, video and video APIs are still subject to the "blind spot" issue. Overlaying a video that contains transparency enables the video and, therefore, the message to become part of the content.

Placing a video overlay on top of your site’s viewport, changing content, or helping visitors navigate the site promotes understanding of your product, encouraging engagement by potential customers. Transparent video feels like it’s part of your site, not just embedded there. Since all other webpage elements are visible, you can, with regular web-development expertise, build a captivating experience behind and around videos.

With the power of today’s 5G bandwidth, streaming video on websites is no longer a challenge, so you need not limit yourself to the old-fashioned, text-based ways of implementing interactions. With Cloudinary and a little JavaScript, creating compelling video ads is now easier—and more fun—than you might think.

Preparing the Video

Transparent video ads originate from videos with a transparent channel, such as WebM videos, and a transparent background set. You can purchase videos in that format online or create your own green-screen videos and remove the background. That’s what we did for this demo: we downloaded a video from Camtasia and then used that tool to eliminate the background. The video is available for free for those who want to process videos with Camtasia.

Note: Cloudinary is working on an experimental feature to "automagically" remove video backgrounds.

Once you have a WebM-formatted video with a transparent background, upload the video to Cloudinary:

  1. Log in to Cloudinary and, on the Dashboard, click the Media Library icon (second left at the top).
  2. Click Upload in the top-right corner to specify the video you wish to upload. Either drag and drop it on to the portal or select it after navigating to the folder that houses the video. Once upload succeeds, Cloudinary displays it in your Media Library:
  3. Copy the video URL and embed it on your website with the built-in HTML5 <video/> element. Before doing that, feel free to apply more transformations to the video, such as resizing, cropping, and adding a background.

Your video is now available on your site. Read on to learn how to stream video content to visitors.

Embedding the Video on a Website

Cloudinary offers an SDK that delivers transparent videos directly within HTML content. With that JavaScript SDK, you can deliver content across all browsers. The rest of this section describes the controls for delivering transparent video to all browsers.

Normally, you would add video to webpages with the HTML5 <video> element or through the Cloudinary Video Player. However, transparent video is an exception. Native HTML5 and the Cloudinary Video Player can handle transparent video everywhere except Safari on iOS and pre-Big Sur MacOS versions. That’s a problem given the ubiquity of Macs and iPhones.

Fortunately, the Cloudinary JavaScript SDK can help with its injectTransparentVideoElement method, which can add transparent videos that work everywhere. Here’s an example of the code on a simple webpage:

HTML
<html lang="en">
    <head>
       <title>Transparent Video</title>
       <style>
            #video-overlay {
                position: absolute;
                top: 90;
                left: 65;
                width: 900px;
            }
       </style>
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css">
       <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
       <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
          <script src="https://unpkg.com/cloudinary-core@latest/cloudinary-core-shrinkwrap.min.js" type="text/javascript"></script>
    </head>
    <body>
       <div class="container">
            <h1>Video overlays</h1>
            <p>Video overlays are a great way to engage users without interfering with the content on the website.</p>
            <input type="submit" value="Click me!" class="overlay-control" style="z-index: 6; position: relative;" />
            <p>Hi, here is some text behind the video...</p>
            <p class="mt-100">Here is more text content.</p>
            <div id="video-overlay" style="z-index: 5;"></video>
       </div>
          <script>
              $(function() {
                $(".overlay-control").click(function() {
                    var cld = cloudinary.Cloudinary.new({ cloud_name: 'afzaalahmadzeeshan' });
                    cld.injectTransparentVideoElement(document.getElementById("video-overlay"), 'v1610035527/samples/elephants.mp4', {
                        loop: true,
                        playsinline: true,
                        width: 600,
                    }).catch(error => {
                        console.log(error);
                    });
                });
              });
          </script>
    </body>
</html>

As expected, you can see the HTML elements behind the video because of its transparent parts.

Furthermore, you can create fun experiences with transparent video, for example, set up the content with JavaScript to play or pause on a user interaction, hence opening up more possibilities for content and advertising. A transparent-display ad can become part of the content the audience was looking at, intriguing them and capturing their attention. On your website, transparent video can also entice audience engagement with content, directing them to navigate to product pages or interact with demos.

Applications abound for transparent video in other industries. For instance, those in academia can display videos that require students to perform certain tasks on the website before the instructor proceeds with the course material.

Keep in mind that you can further customize the above script to transform videos. Plus, it’d be prudent to add a fallback value that the script can render in case the browser does not support all the features required to play the video.

For details on all those options, see Cloudinary’s documentation on its Video Player and on video transformations.

Taking the Next Steps

Beside describing the benefits of embellishing web advertisements with compelling, transparent video content, this article also explains why interactive content is useful and why old, static ads are less so. You’ve also learned how to collect, purchase, or prepare your own interactive video for display on your site, and then embed that video with Cloudinary and JavaScript.

Cloudinary’s upcoming video-editing feature will build on the existing technologies, enabling you to create riveting, interactive videos with artificial intelligence (AI). You can then easily remove video backgrounds and create transparent overlays for embedding in your website, further promoting user engagement.

For more insight, check out the Google Chrome Developer’s post on alpha transparency in videos and the Google Web Team’s article on autoplay policy changes.

Are you ready to boost engagement with transparent video ads? Start with signing up for a free Cloudinary account with enough credits to create your first sleek ad.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here