

# Implementing automatic input failover
Automatic input failover

When you set up the inputs for a MediaLive channel, you can set up inputs as an *input failover pair* (or failover pair). Setting up this way provides resiliency for the source, in case of a failure in the upstream system, or a failure between the upstream system and the channel. 

You can set up the following types of inputs for input failover:
+ CDI
+ Link
+ MediaConnect
+ RTMP Push
+ RTP
+ SRT caller

You can configure the channel so that MediaLive detects one or more of the following problems in the input:
+ Input loss – MediaLive will perform a failover if it doesn't receive content for the specified period.
+ Black video (video failure) – MediaLive will perform a failover if content is being received (so input loss doesn't apply), but the content is black for a specified period. 
+ Audio silence (audio failure) – MediaLive will perform a failover if content is being received (so input loss doesn't apply), but an audio selector is silent for a specified period.

Each input in the input pair provides content to the channel. One of the inputs is the *active * input and one is on *standby*. MediaLive ingests both inputs, in order to always be ready to switch, but it usually discards the standby input immediately. If the active input fails, MediaLive immediately fails over and starts processing from the standby input, instead of discarding it.

**Note**  
Before you decide to implement automatic input failover, you should read about [pipeline redundancy](plan-redundancy-mode.md), which is another form of channel resiliency. You might decide to implement one or both of these features. 

**Topics**
+ [

# Automatic input failover in a single-pipeline channel
](aif-single-pipeline-how.md)
+ [

# Automatic input failover in a standard channel
](aif-standard-pipeline-how.md)
+ [

# Setting up automatic input failover with CDI inputs
](aif-setup-cdi.md)
+ [

# Setting up automatic input failover with MediaConnect inputs
](aif-setup-emx.md)
+ [

# Setting up automatic input failover with RTMP and RTP inputs
](aif-setup-other-inputs.md)
+ [

# Changing the roles of the failover pair
](aif-setup-inverting.md)
+ [

# Starting the channel
](aif-behavior-startup.md)
+ [

# Manually forcing a failover
](aif-and-input-switching-failoverpair.md)
+ [

# Automatic input failover and input switching
](aif-and-input-switching.md)

# Automatic input failover in a single-pipeline channel


You can implement automatic input failover (AIF) in a single-pipeline channel to protect the MediaLive channel from failure in the upstream system or the network connection that is upstream of MediaLive. 

You can implement automatic input failover in push inputs, but not in pull inputs.

Keep in mind that the channel can't have more than two push inputs. This means that you can implement one of these scenarios:
+ If your channel has only one push input, you can implement automatic input failover for that input. Doing so will use up the limit of two push inputs.
+ If your channel already has two different push inputs, you won't be able to implement automatic input failover for either of these inputs, because you have already created the maximum number of push inputs.

**Note**  
Pay attention to use of the terms *single* and *standard*. The inputs are standard-class. The channel is single-pipeline.

## How it works


To implement automatic input failover for the selected input, you create two standard-class inputs, in the usual way. When you create the channel, you attach these two inputs and then set them up as a failover pair. Both these steps are covered in the setting up sections later in this topic.

When you start the channel, the channel ingests the content from both inputs. In the diagram, the red lines in the inputs indicate that MediaLive ingests both inputs. But only one input (for example, the blue input in the diagram below) enters the channel pipeline for processing. The other input (the yellow input) is ingested but discarded immediately. The pipeline produces one output for the downstream system, in the usual way.

As this diagram illustrates, there are two instances of the content source. 

![\[Diagram showing failover pair with two upstream servers, standard-class inputs, and a single-pipeline channel to downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-single-setup.png)


## Failure handling


If there is a failure, the behavior is as follows:
+ If there is a failure upstream of the first input, then automatic input failover occurs. The channel immediately fails over to the yellow pipeline in the second input, which is already being ingested. The channel fails over and starts processing that input. There is no disruption in the channel pipeline or in the output.
+ If there is a failure in the channel pipeline (for example, in pipeline 0), MediaLive stops producing output. Switching the input would not help this failure because the problem is in the pipeline, not in the input.

This diagram illustrates the flow after there is a failure upstream of the first input. MediaLive has failed over to the second input.

![\[Diagram showing failover from one upstream server to another, with a single pipeline channel to downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-single-input-failover.png)


# Automatic input failover in a standard channel


You can implement automatic input failover in a standard MediaLive channel to protect the MediaLive channel from failure in the upstream system or the network connection that is upstream of MediaLive. 

You can implement automatic input failover in push inputs, but not in pull inputs. 

Keep in mind that the channel can't have more than two push inputs. This means that you can implement one of these scenarios:
+ You can set up two push inputs in the channel, but you won't be able to implement automatic input failover for either of these inputs.
+ You can set up one push input in the channel, and you can implement automatic input failover for that one input.

## How it works


To implement automatic input failover for the selected push input, you create two standard-class inputs, in the usual way. When you create the channel, you attach these two inputs and then set them up as a failover pair. Both these steps are covered later in the setting up sections later in this topic.

![\[Diagram showing failover pair setup with upstream systems, standard-class inputs, and downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-standard-setup.png)


When you start the channel, MediaLive ingests the content from both inputs. So it ingests four sources (as shown by the red lines in the diagram). But only the content from the first input goes to the channel pipeline. The content from the blue pipeline goes to pipeline 0. The content from the green pipeline goes to pipeline 1. 

The pipeline produces two outputs for the downstream system, in the usual way. The downstream system chooses to handle one pipeline and to ignore the other pipeline.

![\[Diagram showing failover pair with standard-class inputs, standard channels, and downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-standard-beforefailure.png)


## Failure handling
Correction to automatic input failover

We have corrected the description of how MediaLive handles a pipeline failure (scenario 1) in a standard channel. The text and the diagram have been revised.

### Failure scenario 1


If normal processing is in progress and there is a failure in pipeline 0 in the active input, then the recovery behavior for pipeline redundancy occurs:
+ The channel immediately fails over to pipeline 0 in the second input (which is already being ingested) and starts processing that input. The channel processes the yellow line in pipeline 0, and the green line in pipeline 1. (So there is no change in pipeline 1.) The output is not affected. 
+ The downstream system continues to handle the output from the pipeline it had chosen before the problem. The downstream system is not affected by the failure in the pipeline 0. 

![\[Failover pair diagram showing standard-class inputs, standard channel pipelines, and downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-standard-pipeline-failure.png)


### Failure scenario 2


If normal processing is in progress and there is a failure upstream of the first input, then automatic input failover occurs:
+ The channel immediately fails over to the second input (which is already being ingested) and starts processing that input. The yellow line is processed in pipeline 0, the pink line in pipeline 1. The output is not affected. 
+ The downstream system continues to handle the output from the pipeline it had chosen before the problem. The downstream system is not affected by the failure in the first input. 

![\[Failover pair diagram showing standard-class inputs, standard channel with two pipelines, and downstream system.\]](http://docs.aws.amazon.com/medialive/latest/ug/images/aif-standard-input-failure.png)


# Setting up automatic input failover with CDI inputs
Setting up: CDI inputs

To use CDI inputs with automatic input failover in MediaLive, you must make sure that the upstream system provides sources in the correct way, and you must set up the inputs and the channels in a specific way. 

**Note**  
The information in this section assumes that you are familiar with the general steps for [creating an input](create-input.md) and [creating a channel](creating-channel-scratch.md).

**To plan the inputs for the input failover pair**

1. Arrange with your upstream system for them to provide you with the appropriate number of sources for the content:
   + If you are setting up automatic input failover in a single-pipeline channel, you need two sources—one for each input.
   + If you are setting up automatic input failover in a standard channel, you need four sources—two for each input.

1. Make sure that the upstream system sets up the paths correctly. The first input must have a different network path to MediaLive, compared to the second input. MediaLive can't enforce this rule, but the point of automatic input failover is that the sources arrive via different paths. If they don't, then when the route fails, both inputs will fail, and you will not have achieved redundancy.

1. Make sure that the input type for the sources is CDI.

1. Make sure that all the sources contain exactly identical video, audio, captions, and metadata.

**To create the inputs for the input failover pair**
+ Create a set of two partner CDI inputs. See [Creating a partner CDI push input in Amazon VPC](input-create-cdi-partners.md).

  Don't follow the usual procedure of creating two independent CDI inputs. You won't be able to set up these two inputs as a failover pair.

**To attach the inputs to the channel**

1. Decide which partner CDI input you want to set up as the primary input.

1. In the **Input attachments** section of the **Create channel** page, follow the usual procedure to attach the primary input. Ignore the **Automatic input failover settings** for now.

   Remember to set up the **General settings**, particularly the selectors.

1. Follow the same procedure as the previous step to attach the partner input.

1. In the **Input attachments** section, in the list of input attachments, choose the first input that you attached. 

   You must choose the first input that you attached. If you choose the other partner input, you won't be able to enable automatic input failover.

1. In the **Automatic input failover settings** section, choose **Enable automatic input failover settings**. As soon as you enable this field, this input is labeled as **Primary** in the list of input attachments.

1. For **Secondary input**, choose the partner input. The partner input is the only input in the list. If no inputs are listed, you have forgotten to create the partner input. [Create it now](input-create-cdi-partners.md).

1. For **Input preference**, choose the desired option. This field controls the behavior when MediaLive has switched over to the secondary input and then the primary input becomes healthy again.
   + **EQUAL\$1INPUT\$1PREFERENCE** – MediaLive remains on the secondary input. The primary input continues to be processed, but it is not active.
   + **PRIMARY\$1INPUT\$1PREFERENCE** – MediaLive switches back to the primary input. The primary input becomes the active input.

1. For **Failover conditions**, enable the conditions that you want MediaLive to use to identify input loss. The fields include help that describes how the conditions work.

# Setting up automatic input failover with MediaConnect inputs
Setting up: MediaConnect inputsInput failover with a AWS Elemental MediaConnect input

The guide now includes information about setting up input failover to work well with a MediaConnect input that is from a flow that implements source redundancy.

To use MediaConnect inputs with automatic input failover, you must set up both the inputs and the MediaLive channels in a specific way.

**Note**  
The information in this section assumes that you are familiar with the general steps for [creating a MediaConnect input](setup-input-emx.md) and [creating a channel](creating-channel-scratch.md).

**To plan the inputs for the input failover pair**

1. Identify the flows that you need to create on MediaConnect:
   + If you are setting up automatic input failover in a single-input channel, you need two flows—one for each input.
   + If you are setting up automatic input failover in a standard channel, you need four flows—two for each input.

1. Make sure that all the flows contain exactly identical video, audio, captions, and metadata.

**To create the flows in MediaConnect in a standard channel**

You must create four flows, two for the primary input, and two for the secondary input.
+ Follow the procedure in [Create a MediaConnect input](setup-input-emx.md), with the following notes:

  Make sure that you set up the flows in the correct Availability Zones. Assume that the two flows for the primary input are A and B, and that the two flows for the secondary input are C and D. 
  + Flow A must be in Availability Zone X.
  + Flow B must be in Availability Zone Y.
  + Flow C must be in Availability Zone X.
  + Flow D must be in Availability Zone Y.

  At channel startup, MediaLive sets up the flows as follows:
  + Flow A connects to pipeline 0.
  + Flow C connects to pipeline 0.
  + Flow B connects to pipeline 1.
  + Flow D connects to pipeline 1.

  As a result of these connections, the active input on pipeline 0 is initially from Availability Zone X. The active input on pipeline 1 is initially from Availability Zone Y. If one Availability Zone fails, only one pipeline is affected. For more information on failure scenarios, see [Failover and failback scenarios](aif-behavior-startup.md#aif-failover-scenarios).

**To create the flows in MediaConnect in a single-pipeline channel**

You must create two flows, one for each input.
+ Follow the procedure in [Create a MediaConnect input](setup-input-emx.md), with the following note:

  Make sure that you set up the flows in the same Availability Zones. The two inputs provide two paths to the single pipeline in the channel. If one of the flows fails to send content, that input fails and MediaLive switches to the other input.

**To create the inputs for the input failover pair**

1. Follow the procedure in [Create a MediaConnect input](setup-input-emx.md) to create one input of the appropriate type. 
   + In a standard channel, set up the input with two sources. Attach flows A and B to this input.
   + In a single-pipeline channel, set up the input with one flow. 
   + Give the input a name such as **primary input**.

1. Create a second input in the same way. 
   + In a standard channel, set up the input with two sources. Attach flows C and D to this input.
   + In a single-pipeline channel, set up the input with one flow. 
   + Give the input a name such as **secondary input**.

**To attach the inputs to the channel**

1. In the **Input attachments** section of the **Create channel** page, follow the usual procedure to attach the primary input. Ignore the **Automatic input failover settings** for now.

1. Follow the same procedure to attach the secondary input.

1. In the **Input attachments** section, in the list of input attachments, choose the first input that you attached. 

1. In the **Automatic input failover settings** section, choose **Enable automatic input failover settings**. As soon as you enable this field, this input is labeled as **Primary** in the list of input attachments.

1. For **Secondary input**, choose the secondary input. (When you do this, this input is labeled as **Secondary** in the list of attachments.)

1. For **Input preference**, choose the desired option. This field controls the behavior when MediaLive has switched over to the secondary input and then the primary input becomes healthy again.
   + **EQUAL\$1INPUT\$1PREFERENCE** – MediaLive remains on the secondary input. The primary input continues to be processed, but it is not active.
   + **PRIMARY\$1INPUT\$1PREFERENCE** – MediaLive switches back to the primary input. The primary input becomes the active input.

1. For **Failover conditions**, enable the conditions that you want MediaLive to use to identify input loss. The fields include help that describes how the conditions work.
**Note**  
If you enable the input loss failover condition, find out if the MediaConnect flow implements source redundancy with failover mode. With this mode, if there is a source failure, MediaConnect waits 500 ms for the source to recover before it fails over. Therefore, you must configure MediaLive to wait longer than 500ms, to ensure that MediaLive doesn't fail over just as MediaConnect is about to recover.   
In the **Enable input loss settings** option, adjust the threshold. Set the threshold to a value higher than 500ms. You might need to try different values to find the ideal threshold for your network.

# Setting up automatic input failover with RTMP and RTP inputs
Setting up: other inputs

To use RTMP push inputs and RTP inputs with automatic input failover in MediaLive, you must make sure that the upstream system provides sources in the correct way, and you must set up the inputs and the channels in a specific way.

**Note**  
The information in this section assumes that you are familiar with the general steps for [creating an input](create-input.md) and [creating a channel](creating-channel-scratch.md).

**To plan the inputs for the input failover pair**

1. Arrange with your upstream system for them to provide you with the appropriate number of sources for the content:
   + If you are setting up automatic input failover in a single-input channel, you need two sources—one for each input.
   + If you are setting up automatic input failover in a standard channel, you need four sources—two for each input.

1. Make sure that the upstream system sets up the paths correctly. The first input must have a different network path to MediaLive, compared to the second input. MediaLive can't enforce this rule, but the point of automatic input failover is that the sources arrive via different paths. If they don't, then when the route fails, both inputs will fail, and you will not have achieved resiliency.

1. Make sure that the input type for the sources is the same. For example, two RTMP inputs.

1. Make sure that all the sources contain exactly identical video, audio, captions, and metadata.

**To create the inputs for the input failover pair**

1. Follow the procedure in [Working with inputs](creating-input.md) to create one input of the appropriate type. For example, one RTMP input.
   + In a standard channel, set up the input with two sources.
   + In a single-pipeline channel, set up the input with one source. 
   + Give the input a name such as **primary input**.

1. Create a second input of the same type. Create the input in the same way as in Step 1. 

   Give the input a name such as **secondary input**.

**To attach the inputs to the channel**

1. In the **Input attachments** section of the **Create channel** page, follow the usual procedure to attach the primary input. Ignore the **Automatic input failover settings** for now.

1. Follow the same procedure to attach the secondary input.

1. In the **Input attachments** section, in the list of input attachments, choose the first input you attached. 

1. In the **Automatic input failover settings** section, choose **Enable automatic input failover settings**. As soon as you enable this field, this input is labeled as **Primary** in the list of input attachments.

1. For **Secondary input**, choose the secondary input. (When you do this, this input is labeled as **Secondary** in the list of attachments.)

1. For **Input preference**, choose the desired option. This field controls the behavior when MediaLive has switched over to the secondary input and then the primary input becomes healthy again.
   + **EQUAL\$1INPUT\$1PREFERENCE** – MediaLive remains on the secondary input. The primary input continues to be processed, but it is not active.
   + **PRIMARY\$1INPUT\$1PREFERENCE** – MediaLive switches back to the primary input. The primary input becomes the active input.

1. For **Failover conditions**, enable the conditions that you want MediaLive to use to identify input loss. The fields include help that describes how the conditions work.

# Changing the roles of the failover pair


When you set up for input failover in a MediaLive channel, you can reverse the roles of the two failover inputs, so that the primary input becomes the secondary input. 

**To reverse the roles of the inputs**

1. From the list of input attachments, choose the first input that you attached. 

1. In the **Automatic input failover settings** section, choose **Disable automatic input failover settings**.

1. Choose the second input and choose **Enable automatic input failover settings** for that input. The second input is now the primary input.

# Starting the channel


Start the MediaLive channel in the usual way. MediaLive follows this behavior when you start the channel:
+ If the input attachment list contains only the input failover pair, MediaLive starts with the primary input, which always appears first in the attachments.
+ If you have set up the channel to always use the schedule, even with the first input, then MediaLive starts with the first input in the schedule. This input can be any input.
+ If you have not set up the channel to control startup behavior (not recommended), MediaLive starts with the first input in the input attachment list.

## Failover and failback scenarios


Input failover in a MediaLive channel follows this rule:
+ If the active input is unhealthy for 3 seconds, MediaLive switches to the other input.

You can also manually switch to the other input, if the **Input preference** setting is **EQUAL\$1INPUT\$1PREFERENCE**. Switching over manually is useful, for example, if you believe that the active input is unstable. See [Manually forcing a failover](aif-and-input-switching-failoverpair.md).

Input failback follows this rule:
+ When the unhealthy input is healthy again for more than 30 seconds, it is marked as healthy. 

When the input becomes healthy, MediaLive might automatically switch to the healthy input:
+ If the currently active input is the secondary input, MediaLive either stays on the current input (if the **Input preference** setting is **EQUAL\$1INPUT\$1PREFERENCE**) or switches to the primary input (if the **Input preference** setting is **PRIMARY\$1INPUT\$1PREFERENCE**).
+ If the active input is the primary input, it always stays on the input.

# Manually forcing a failover


You can set up automatic input failover to allow the MediaLive operator to perform a manual failover.

Keep in mind that the content in the failover pair is identical. Therefore, you only switch between them for specific reasons. For example: 
+ You might think that the active input is degrading, but MediaLive hasn't yet made the decision to fail over to the other input. 
+ You might want to perform maintenance on the network for the input that is currently active.

**To switch between the two inputs in the input pair**

1. If you think you might want to manually switch inputs, then when you set up the failover pair, set the **Input preference** to **EQUAL\$1INPUT\$1PREFERENCE**. See [Setting up automatic input failover with RTMP and RTP inputs](aif-setup-other-inputs.md) or [Setting up automatic input failover with MediaConnect inputs](aif-setup-emx.md). 

1. To manually switch, [create an input switch action](schedule-using-console-create.md) in the schedule in the usual way.

   Set up the input to switch to the other input, and set the **Start Type** to **Immediate**.

# Automatic input failover and input switching


When you implement automatic input failover in MediaLive, you can still implement input switching.

**Note**  
The information in this section assumes that you are familiar with the general steps for creating input switches, as described in [Creating actions in the schedule (console)](schedule-using-console-create.md).

With automatic input failover, your deployment contains an input failover pair that uses up your quota of push inputs for the channel. You can't attach more push inputs to the channel. But you can attach more pull inputs, and can therefore set up a multiple-input channel suitable for input switching using the schedule. You can perform the following switches:
+ From a pull input to another pull input.
+ From a pull input to either input in the failover pair.
+ From the primary input or secondary input to a pull input.