

# Working with image overlays
<a name="working-with-image-overlay"></a>

You can impose static images onto a video in a MediaLive channel. A static image is a still image that doesn't have motion. You prepare the image or images and store them outside of MediaLive. You then use the [schedule](working-with-schedule.md) feature in MediaLive to set up a timetable that specifies when images will be inserted in the running channel, and when each will be removed. 

**Topics**
+ [Two options: global overlay and per-output overlay](image-overlay-features.md)
+ [Preparing the static image overlay file](image-overlay-prepare-step.md)
+ [Handling encode sharing](image-overlay-encode-sharing.md)
+ [Inserting and removing an overlay](image-overlay-insert.md)

# Two options: global overlay and per-output overlay
<a name="image-overlay-features"></a>

There are two options for inserting and removing image overlays in a MediaLive channel — the global option and the per-output option.
+ Global image overlay: Insert a static image overlay in every output in every output group. The action is called Static Image Activate. 
+ Per-outputs image overlay: Insert a static image overlay into the running channel, only in specific outputs in specific output groups. The action is called Static Image Output Activate.

In one channel, you can combine the global action and the per-output option in the same channel. For example, you can insert image X globally (in all outputs) and insert image Y only in output A. Output A will have both image X and image Y. All other outputs will have only image X.

**Topics**
+ [How MediaLive handles a global image](#image-overlay-global-about)
+ [How MediaLive handles a per-output image](#image-overlay-per-output-about)
+ [Image layers and inserting images](#image-overlay-layers)
+ [Removing images](#image-overlay-remove)
+ [Properties of the image](#image-overlay-properties)

## How MediaLive handles a global image
<a name="image-overlay-global-about"></a>

MediaLive inserts the image before it sets the resolution in the video. In this way, the image gets resized as MediaLive resizes the video frame to obtain the specified resolution. The output image and video frame can resized to be smaller (a lower resolution) or larger (a higher resolution).

The global option works well when you want to use the same image in every video output, and you want that image to take up the same proportion of the video frame in every video output. When you prepare the image, you make sure that it takes up the desired proportion of the source video. For example, you might want its height to be 10% of the height of the underlying video. After MediaLive sets the video resolution, the image is still the same proportion of the underlying video. For example, the image takes up approximately 10% of the height of an output 720p video frame and approximately 10% of the height of an output 4K video frame.

## How MediaLive handles a per-output image
<a name="image-overlay-per-output-about"></a>

MediaLive sets the resolution of the video, and then it overlays the image. This means that the image doesn't get resized, it retains its absolute size.

The per-output option is useful if you want to overlay different images in different outputs. For example, you might want to insert one logo in the video in one output group, and another logo in the video in another output group. 

The per-output option is also useful if you want to insert an image without resizing it. For example, if you want the image to have the same absolute size in every output in an ABR stack. The image is the same absolute size on a 720p video frame as it is on a 4K video frame. Therefore, you can use the same image file in all the outputs.

You might also want the image to have the same relative size in a group of outputs that have have different resolutions. For example, you want every image to take up 10% of the height. In this case, you must prepare separate files for each output, and create separate insert actions in the different outputs.

## Image layers and inserting images
<a name="image-overlay-layers"></a>

An image always exists in a layer. There are 8 global layers for the global option, and 8 per-output layers for the per-output option. A layer can contain only one image.

The layers are ordered. Layer 0 is at the bottom and layer 7 at the top. 

The per-output layers are all on top of the global layers. This means that from the bottom, the layers are global layers 0 to 7, then per-output layers 0 to 7. Keep this layer order in mind if you plan to overlap images. 

## Removing images
<a name="image-overlay-remove"></a>

There are two actions to deactivate (remove) an image, one to remove from a global layer, and one to remove from the per-outputs layer in specific outputs. 

The global action removes the image from the specified layer and from all outputs.

The per-output action is more flexible. For example, you might insert image X in per-output layer 4 in outputs A and B. You might then insert image Y in per-output layer 4 in output C. You can then enter a deactivate action that removes the image from per-output layer 4 in outputs A and C. Image X in output A will be removed, and image Y in output C will be removed. Image X in output B will still exist. 

## Properties of the image
<a name="image-overlay-properties"></a>

**Start time and duration**

You can configure each image overlay with a start time and duration. 

**Positioning**

You can insert the image overlay at any position on the video frame, relative to the X axis and Y axis of the video frame. You can position images so that they overlap each other. 

**Opacity and fade**

You can configure with an opacity and with fade-in and fade-out. 

**Input insertion and overlays**

You might insert image overlays in a channel where you are also performing input switching (to ingest different inputs). Keep in mind that the handling for input switches and image overlays is completely decoupled. In other words, you don't have to worry that when MediaLive switches to a different input, the currently active image overlays will disappear. They won't disappear.

# Preparing the static image overlay file
<a name="image-overlay-prepare-step"></a>

You must prepare each image overlay that you want to use in your MediaLive channel, and store it in a suitable location, such as an Amazon S3 bucket. You can prepare the images at any time, either before you start the channel, or while the channel is running.

**To prepare the overlay file**

1. Determine the size (width and height in pixels) of the file you need. You might need several instances of one image, each in a different size. For more information, see the guidelines after this procedure.

1. Create files with the following characteristics:
   + 32-bit bmp, png, or tga format
   + If you use a graphics program that outputs channels, set up to output the alpha channel. This ensures that the image overlay doesn't appear in a black or white box.

1. Place the prepared file in a location that is accessible to the MediaLive. Make a note of the location and of any user credentials that users need to access the file. You can specify the location in one of these ways: 
   + Amazon S3 bucket, using SSL. For example: 

     `s3ssl://amzn-s3-demo-bucket/company-overlays/overlay.png`

     With MediaLive, the Amazon S3 bucket name mustn't use dot notation, which means it mustn't use . (dot) between the words in the bucket name.
   + A location that supports HTTP or HTTPS. For example:

      `https://203.0.113.0/corporate-logos/large.bmp`

**Determining the image size if you are using the global option**

Keep in mind that with the global insertion option, MediaLive inserts the image on the output video frame *before* it sets the output video resolution. This means that the image will be resized with the output video.

Follow these guidelines:
+ Determine the size of the image relative to the *source* video. For example, you might want an image to take up 10% of a 1280×720 source video frame. In this case, the image height should be approximately 72 pixels.
+ You can prepare a new file that is the desired size. Or you can use an existing file and resize it when you prepare the insert action. MediaLive resizes the image before overlaying it on the video. Keep in mind that resizing might decrease the quality. 
+ If the channel has sources with different resolutions, you have two options:
  + You can optimize the image for one source.
  + Or you can create multiple versions of the same file, with each file in a different size. When you create an action to switch to a different input (with a different resolution), create a new insert image action, to insert the image that has the appropriate size.
+ If the image is bigger than the source video frame, MediaLive trims off the excess.

**Determining the image size if you are using the per-output option**

Keep in mind that with the per-output insertion option, MediaLive inserts the image on the output video frame *after* it sets the output video resolution. This means that the image will be resized with the output video.

Follow these guidelines:
+ Determine how many sizes you need of each image. For example, if you will insert the image on outputs that have three different resolutions, you need three different sizes.

  You can obtain the different sizes in either of these ways:
  + You can create multiple versions of the same file, with each file in a different size. Create separate actions for each size. In each action, specify all the outputs where the image will be inserted.
  + You can resize the image when you create the insert action. Create separate actions for each size. In each action, resize the image by setting a height and width. Specify all the outputs where the resized image will be inserted.
+ If the image is bigger than the output video frame, MediaLive trims off the excess.

# Handling encode sharing
<a name="image-overlay-encode-sharing"></a>

Read this section if you plan to use the per-output option to insert overlays in MediaLive outputs, and you have already set up output groups to use video encode sharing. Video encode sharing involves creating one video encode, and then sharing it among two or more outputs in the same channel. For example, you might use the same video encode in the outputs in an ABR stack in an HLS output group and in an ABR stack in a Microsoft Smooth output group.

Video encode sharing isn't compatible with per-output image insertion. To undo sharing, follow this procedure:

1. Identify the encodes that you have set up for sharing:
   + In the **Create channel** or **Edit channel** page for the channel, find one of the output groups where you plan to insert per-output images. Select the first video output, then in **Stream settings**, select the video encode. If this video encode is shared, a note appears listing the other outputs.
   + Repeat for every output group in the channel. Make a list of the encodes and how they are shared.

1. If you plan different images for these outputs, you must stop sharing them:
   + Stop sharing the video encode in one of the outputs, for example in output group A. For instructions, see [To stop sharing an encode](create-video-share.md#create-video-stop-sharing). The video encode is now used only in output group B.
   + In output group B, clone the video encode that was previously shared. Keep in mind that cloning isn't the same as sharing. For more information, see [Creating a video encode by cloning](create-video-clone.md).

# Inserting and removing an overlay
<a name="image-overlay-insert"></a>

When you are ready, you can create an action in the MediaLive channel schedule to activate (insert) the overlay. You can create the action at any time – before the channel has started or while it is already running.The schedule is a timetable that is attached to each channel. It lets you perform actions at a specific time, on a running (active) channel. You can work with the schedule using either the MediaLive console or an AWS API or SDK.

You can set up the action so that an image overlay is active for a specific time, or so that it is active indefinitely. In both cases, you can stop the overlay at any time by creating a deactivate action. For more information, see [Working with image overlays](working-with-image-overlay.md).