AWS for M&E Blog
Learn about IoT integration and server-side ad insertion with AWS Media Services
Overview
This blog helps Raspberry Pi enthusiasts who want to monetize exclusive, but simple-to-set-up, IoT video feeds using server-side ad insertion (SSAI) powered by AWS Media Services from Amazon Web Services (AWS).
For example, an exotic dog breed kennel club that nurtures rare and magnificent dog species may choose to showcase its residents on a private live feed for emotional therapy purposes to an audience that finds comfort in watching cute, furry dogs hanging out together and going about their day. To support a private feed via the cloud, the kennel club needs to monetize live streams delivered to thousands of concurrent viewers by stitching in 5-6 short ads every hour. Interested dog lovers are given the URL of the live feed and can watch it from anywhere with a good Wi-Fi connection on their phones, tablets, and laptops.
Architecture
Deploy AWS Media Services resources and Amazon CloudFront distribution using a CDK app
You will use AWS CDK to deploy the following resources in your AWS account:
1. AWS Elemental MediaLive channel for live transcoding
2. AWS Elemental MediaPackage channel for live packaging and origination
3. AWS Elemental MediaTailor configuration for server-side ad insertion
4. Amazon CloudFront distribution as the CDN
5. AWS Lambda function to insert ad markers using splice insert
Follow the instructions on how to deploy the CDK app from here.
Trigger Lambda function using Amazon CloudWatch Events
With the Lambda function defined, you will schedule it to get triggered at a regular interval, say every 1 minute so that we can easily test this with MediaTailor later.
- From the AWS console, navigate to CloudWatch.
- Under Events, click on Rules. Click on Create Rule
- Under Event Source, choose Schedule.
- In Fixed rate of, edit to say 1 minute.
- Under Targets, click on Add Target.
- In the Functiondropdown menu, select your InsertAdMarker function (created as part of the CDK app deployment).
7. Click on Configure details
8. Provide a name like InsertAdMarkerEveryMinute. Make sure to leave the Stateto Enabled. Otherwise, this rule will not run. Click on Create Rule
9. With the event enabled, navigate to the MediaLive console, select Channels and choose your MediaLive channel that was created by the CDK app. Select the “Schedule” tab, and you should see schedule ad break opportunities every minute.
Create Amazon S3 bucket and upload ad assets
Create your own Amazon S3 bucket, turn on blocking all public access, and upload ad assets in mp4 format with a 10 second duration.
Create and upload a static VAST.xml to the S3 bucket as an ad serving template
In order to insert ads into your live stream, you can use an Ad Decision Server (ADS) to specify what ads to play for each viewer. For the purposes of this demonstration, we use a static .xml file to simulate an ADS.
Create and upload your own copy of the following VAST.xml template to your S3 bucket. You can use the following sample xml and replace the CDATA with a link to your own ad content. In this example, the sample ad video is 10 seconds in duration; you can change this value based on the duration of your ad video.
<VAST version=”3.0″>
<Ad>
<InLine>
<AdSystem>2.0</AdSystem>
<AdTitle>ad-1</AdTitle>
<Impression/>
<Creatives>
<Creative>
<Linear>
<MediaFiles>
<MediaFile delivery=”progressive” type=”video/mp4″
width=”1920″ height=”1080″>
<![CDATA[https://yoururl.mp4]]>
</MediaFile>
</MediaFiles>
</Linear>
</Creative>
</Creatives>
</InLine>
</Ad>
</VAST>
Associate a CloudFront distribution with the MediaTailor HLS endpoint as the origin to get a CDN playback URL
You will use the CloudFront distribution created by the CDK app to act as the CDN for your MediaTailor HLS endpoint. Edit your MediaTailor configuration to configure Advanced settings and supply your . For that, navigate to the CloudFront console, and from the Details tab, copy the CloudFront domain name and append the relevant origin path pattern for e.g. add “/out/v1/*” to your CloudFront domain name to present the complete content segment prefix and for the ad-segment prefix simply use the CloudFront domain name as is.
The content segment prefix should look like this: https://dxyz123abc.cloudfront.net/out/v1/. Whereas, the ad segment prefix should simply be https://dxyz123abc.cloudfront.net.
Configuring Raspberry Pi
Download and install the latest version of the Raspberry Pi imager utility on your desktophttps://www.raspberrypi.com/software/
Format a micro SD card with the Raspberry Pi OS using the imager utility
Raspberry Pi computers use a micro SD card, except for very early models, which use a full-sized SD card. We recommend using an SD card of 8GB or greater capacity with Raspberry Pi OS. If you are using the lite version of Raspberry Pi OS, you can use a 4GB card. After the Raspberry Pi Imager Utility is installed, follow these steps:
- Connect an SD card reader with the SD card inside.
- Open Raspberry Pi Imager and choose the Raspberry Pi OS from the list presented.
- Choose the SD card you wish to write your image to.
- Review your selections and click on the Write button to begin writing data to the SD Card.
Connecting Pi Cam, keyboard, mouse, and monitor to the Raspberry Pi
All current models of Raspberry Pi have a port for connecting the Camera Module. Make sure your Raspberry Pi is turned off. Locate the Camera Module port, gently pull up on the edges of the port’s plastic clip. Insert the camera module ribbon cable and push the plastic clip into place.
Your Raspberry Pi has two micro HDMI connectors that you will use to connect directly to a monitor using a micro HDMI to standard HDMI (A/M) cable. Your Raspberry Pi also has four USB Ports. You will use 2 of them to connect directly to a wired mouse and keyboard.
Booting the Raspberry Pi
You will now insert the SD card into your Raspberry Pi and power it up using a type C power supply cable. When your Raspberry Pi boots for the first time, a configuration wizard will run that allows you to set up your Raspberry Pi.
The wizard starts off by allowing you to configure international settings and your time zone information.
After choosing “Next”, you’ll be prompted to create a user account. Here, you can choose your username and a password.
After creating a user account, you can configure your screen and your wireless network. Once that is configured and your Raspberry Pi has access to the internet, you will be prompted to update the operating system to the latest version. This will automatically download any patches and updates needed to bring your new operating system up to date. Once the operating system is updated, you will be prompted to reboot your Raspberry Pi.
Enabling camera interface
Before using any of the Raspicam applications, the camera must be enabled. Go to the main menu and open the Raspberry Pi Configuration tool.
Select the Interfaces tab and ensure that the camera is enabled.