

# Preparing inputs in AWS Elemental MediaLive
<a name="feature-prepare-input"></a>

When you implement input swtitching in MediaLive, you can prepare an input that is associated with an immediate input switch in order to reduce the delay that occurs when MediaLive performs the switch. 

If you prepare an input, there is much less delay when MediaLive performs an immediate input switch. This is because MediaLive has already probed the input and started to decode. If you don't prepare the input, there is a delay between the moment that the MediaLive schedule receives the action and the moment that the switch occurs.

We recommend that you prepare an input in this situation
+ You plan to switch to an input with an immediate start type.
+ You don't know when the switch will need to occur, but you do know that you might have only a few seconds advance notice.

You prepare an input by adding an *input prepare* action to the [channel schedule](working-with-schedule.md). Typically, the input switch that the input prepare applies to is an immediate input switch. The input prepare itself can be set up to start at a fixed time, to start immediately, or to start following a specified input switch. 

MediaLive adds the action to the schedule. At the action start time, MediaLive starts to prepare the input. 

Note that there is no advantage to preparing an input if you will switch to it as a fixed input switch or a follow input switch. In this case, MediaLive automatically prepares the input ahead of time.

**Terminology**  
In this section, we use the following terms:
+ *Prepare action *– The input prepare action in the schedule.
+ *Associated switch action* – The input switch action that the input prepare action is associated with. The prepare action prepares input A. The associated switch action switches to input A.
+ *Fixed prepare* – An input prepare action that is set up to start at a fixed time. 
+ *Immediate prepare* – An input prepare action that is set up to start immediately.
+ *Follow prepare, follow-start prepare, follow-end prepare* – An input prepare action that is set up to follow an input switch. The follow prepare can follow the start or the end of the referenced switch.
+ *Reference switch action* – The input switch action that is being used as the trigger for a follow input prepare. So a follow input prepare follows the reference input switch action.

**Note**  
This content in this section assumes that you are familiar with input switching, as described in [Setting up for input switching](scheduled-input-switching.md). 

**Topics**
+ [

# Rules and limits for input prepare in MediaLive
](input-prep-rules.md)
+ [

# Setting up input prepare actions in the schedule
](prepare-input-procedure.md)
+ [

# How input prepare actions behave at runtime
](input-prep-runtime.md)
+ [

# Modifying input prepare actions
](input-prep-modify.md)
+ [

# Deleting and stopping input prepare actions in the MediaLive schedule
](input-prep-delete.md)

# Rules and limits for input prepare in MediaLive
<a name="input-prep-rules"></a>

**One active prepare at a time**  
The MediaLive schedule can contain any number of input prepare actions, but only one input prepare action can be active at one time. 

**Start time at least 10 seconds in advance**  
Set up each input prepare action in the MediaLive schedule so that it starts at least 10 seconds before the associated switch.

**No RTMP pull inputs**  
A MediaLive channel cannot both have RTMP pull inputs and have the input prepare feature enabled. (RTMP push inputs are acceptable.) You must choose which feature is more important—the input prepare or the RTMP pull input. 
+ If you want to use the input prepare feature and the channel already has an RTMP pull input, you must first remove the input.
+ If you want to add an RTMP pull input and the channel already has input prepare actions in the schedule, see [Enabling and disabling the input prepare feature](input-prep-enable.md).

# Setting up input prepare actions in the schedule
<a name="prepare-input-procedure"></a>

Follow this procedure to add input prepare actions to the channel schedule, in order to prepare any input ahead of the switch action to that input.

**To include input prepare actions in a channel schedule**

1. As a one-time action, enable the input prepare feature in the channel. You must enable the feature while the channel is idle. See [Enabling and disabling the input prepare feature](input-prep-enable.md).

1. Plan the input switches and input prepares for the channel. See [Planning the start type for an input prepare](input-prep-plan-start.md).

1. If the associated input switch includes input clipping, see [Clipping the content of a file input](input-clipping.md).

   If the associated input switch is an input failover pair, see [Setting up dynamic inputs](dynamic-inputs.md).

1. Create the actions in the schedule. Typically, you create some prepare actions and switch actions before you start the channel for the first time. Then you add more actions over time. You add fixed switch actions, and follow switch actions. You add prepare actions as soon as you know that you will have an immediate switch some time in the future. Typically, you add all these actions while the channel is running, but you can also add them when the channel is idle.

   For detailed information on adding an input prepare action to the schedule, see [Creating an AWS Elemental MediaLive schedule](working-with-schedule.md).

**Topics**
+ [

# Enabling and disabling the input prepare feature
](input-prep-enable.md)
+ [

# Planning the start type for an input prepare
](input-prep-plan-start.md)
+ [

# Input prepare and dynamic inputs
](input-prep-dynamic.md)
+ [

# Input prepare with clipping
](input-prep-clip.md)
+ [

# Input prepare and automatic input failover
](input-prep-aif.md)

# Enabling and disabling the input prepare feature
<a name="input-prep-enable"></a>

Before you add input prepare actions to the MediaLive schedule, you must enable the feature.

**To enable the feature**
+ On the **Create channel** page, in **General settings**, in the **Feature activations** section, set **Input prepare schedule actions **to **Enabled**. 

**To disable the feature**

You can disable the input prepare feature. 

Typically, the only reason to disable input prepare is because you must [attach an RTMP pull input ](input-prep-rules.md)to the channel. 

1. Stop the channel. 

1. [Delete ](schedule-using-console-delete.md)all active and future input prepare actions from the schedule. You don't need to delete stale input prepare actions from the schedule.

1. On the **Create channel** page, in **General settings**, in the **Feature activation** section, set **Input prepare schedule actions **to **Disabled**. 

1. Attach the [RTMP pull input](creating-a-channel-step2.md) in the usual way.

**Topics**

# Planning the start type for an input prepare
<a name="input-prep-plan-start"></a>

Before you add an input prepare action to the schedule, decide on the start type for the action. 

**Topics**
+ [

# Types of starts for input prepares
](plan-prep-start-types.md)
+ [

# Guidelines for choosing the start type
](plan-prep-tips.md)

# Types of starts for input prepares
<a name="plan-prep-start-types"></a>

There are three start types for input prepare actions in MediaLive. These start types are the same as the start types for input switches.
+ Fixed – the input prepare starts at a specific time.
+ Immediate – the input prepare starts as soon as you add the action to the schedule.
+ Follow – the input prepare follows a specific input switch—the *reference input switch*. It can have a start or an end *follow point*—it can follow the start of the reference input or the end of the reference input. 

With the follow start type, the following rules apply:
+ You can't use the console to create a follow input prepare with a follow point set to *start*. The start option is not shown on the console. Only the end option is shown.
+ MediaLive starts preparing the input *after *the reference input is active. Therefore:
  + For a follow-start prepare (which you can create only using the CLI), you must add the prepare action before the reference input has started in the channel. 

    If the reference switch is an immediate switch, you must include the switch action and the prepare action in the same [batch update command](about-batch-update-schedule.md).

    If the reference switch is a fixed or follow switch, you can add the switch action in one batch update command, and the prepare action in a later batch update command.
  + For a follow-end prepare, you must add the prepare action before the reference input has ended (before ingest has ended).
+ You can't create two follow prepare actions that both follow the same reference switch and the same follow point. Therefore:
  + You *cannot* create action 2 and action 4 to both follow the start of action 1. 
  + But you can create action 2 to follow the *start* of action 1, and action 4 to follow the *end* of action 1.

# Guidelines for choosing the start type
<a name="plan-prep-tips"></a>

Following are some guidelines for deciding which start type to use with an input prepare in the MediaLive schedule. 

Keep in mind that you can only prepare one switch at a time. When a prepare action starts, MediaLive starts preparing the input, and automatically stops any other active prepare input action. 

Therefore, the guiding principle is to make sure that you don't start preparing input X and accidentally *stop *preparing input Y, if input Y needs to be prepared before input X. 

**Topics**
+ [

## Scenario A
](#plan-prep-tips-scenario-A)
+ [

## Scenario B
](#plan-prep-tips-scenario-B)
+ [

## Scenario C
](#plan-prep-tips-scenario-C)
+ [

## Scenario D
](#plan-prep-tips-scenario-D)

## Scenario A
<a name="plan-prep-tips-scenario-A"></a>

You are flipping between two inputs. The switch start is always undetermined, so that each switch is an immediate switch. There might be more switches interspersed among these switches, but they don't need preparing.

```
Switch to input A (immediate)
Switch to input B (immediate)
Switch to input A (immediate)
Switch to input B (immediate)
```

The easiest plan is to start preparing B after each switch to A, and to start preparing A after each switch to B. You could set up each prepare input action with any of these start types:
+ Fixed. The start time for prepare B is some time after the start time for switch A.
+ Immediate. Recommended. You could add the prepare B action at the same time as the immediate A switch, or shortly afterward.
+ Follow (start). You should add the prepare B action and the immediate A switch in the same [batch update command](about-batch-update-schedule.md). The reference action for the prepare B action is input A.
+ Follow (end). You can add the prepare B action at any time after switch A has been added to the schedule. The reference action for the prepare B action is input A.

For example:

```
Switch to input A (immediate)
Prepare input B (immediate)
Switch to input B (immediate)
Prepare input A (immediate)
Switch to input A (immediate)
Prepare input B (immediate)
Switch to input B (immediate)
```

## Scenario B
<a name="plan-prep-tips-scenario-B"></a>

There is an immediate switch to A, then there are several fixed or follow switches. You anticipate that the next immediate switch will be to A again. 

```
Switch to input A (immediate)
Switch to input C (fixed or follow)
Switch to input D (fixed or follow)
Switch to input A (immediate)
```

After the switch to A, MediaLive continues preparing A. Therefore, there is no need to prepare it again. Furthermore, if input A is the only input that ever has an immediate switch, you can prepare A once, before the first time that you switch to it. You don't need to prepare it again.

## Scenario C
<a name="plan-prep-tips-scenario-C"></a>

There is an immediate switch to A, then there are several fixed or follow switches. You anticipate that the next immediate switch will be to B. 

```
Switch to input A (immediate)
Switch to input C (fixed or follow)
Switch to input D (fixed or follow)
Switch to input B (immediate)
```

You know that the next immediate switch will be to input B, so you can start preparing it anytime after the switch to input A. You could set up each prepare input action with any of these start types:
+ Fixed. The start time for prepare B is at least 10 seconds before the start of switch B.
+ Immediate. Recommended. You could add the prepare B action at the same time as the immediate A switch, or shortly afterward.
+ Follow (start). Not recommended. You could, for example, set up the prepare B action to follow the start of switch C or the start of switch D.
+ Follow (end). Not recommended. You could, for example, set up the prepare B action to follow the end of switch A or the end of switch C. Don't set it up to follow the end of switch D.

For example:

```
Switch to input A (immediate)
Prepare input B (immediate)
Switch to input C (fixed or follow)
Switch to input D (fixed or follow)
Switch to input B (immediate)
```

## Scenario D
<a name="plan-prep-tips-scenario-D"></a>

There is an immediate switch to input B, then there are several fixed or follow switches. You anticipate that there will be another immediate switch but initially you don't know if it will be to input B or input E. 

```
Switch to input A (immediate)
Switch to input C (fixed or follow)
Switch to input D (fixed or follow)
Switch to input B or E (immediate)
```

When you know which input you will switch to, you can start preparing it. When you want to prepare it, the current input could be A, C, or D. You could set up each prepare input action with any of these start types:
+ Fixed. The start time for prepare B (or E) is at least 10 seconds before the start of switch B (or E).
+ Immediate. Recommended. Add the prepare input action as soon as you know whether the switch will be to B or E.
+ Follow (start). Not recommended. You could, for example, set up the prepare B (or E) action to follow the start of switch C or the start of switch D.
+ Follow (end). Not recommended. You could, for example, set up the prepare B (or E) action to follow the end of switch A or the end of switch C. Don't set it up to follow the end of switch D.

For example:

```
Switch to input A (immediate)
Switch to input C (fixed or follow)
Switch to input D (fixed or follow)
Prepare input E (immediate)
Switch to input E (immediate)
```

# Input prepare and dynamic inputs
<a name="input-prep-dynamic"></a>

You can prepare for an input switch in a MediaLive channel when the associated input is a [dynamic input](dynamic-inputs.md). A dynamic input has a variable in its path. Each time that you add the input to the schedule, you specify a *replacement string* to replace the variable with a file.

When you set up the prepare input action, you must specify this replacement string. The string must exactly match the replacement string in the switch action. If the strings are not identical, MediaLive won't prepare the input in advance.

You might use this dynamic input more than once in the channel, and the replacement string might be different in each instance. Make sure that you change the string in each prepare action.

# Input prepare with clipping
<a name="input-prep-clip"></a>

You can prepare for an input switch in a MediaLive channel when the associated input is a file input that includes [input clipping](input-clipping.md).

When you set up the prepare input action, you must specify the start and end for the clip. The values that you enter must exactly match the start and end in the switch action. If the values are not identical, MediaLive won't prepare the input in advance.

You might use this file input more than once in the channel, and the start and end might be different in each instance. Make sure that you change the start and end in each prepare action.

# Input prepare and automatic input failover
<a name="input-prep-aif"></a>

Your MediaLive channel might include some inputs that are set up as [automatic input failover pairs](automatic-input-failover.md). 

When you set up the prepare input action for an input that is a failover pair, make sure that you specify the primary input as the associated input (in the **Input attachment** field on the **Create schedule action** page). If you specify the secondary input, MediaLive won't prepare the inputs in advance.

When MediaLive performs the prepare action, it prepares both inputs. This means that a later input switch action can be to either of the inputs in the failover pair.

Here is a scenario that illustrates some of the key behavior:

1. You prepare input A by specifying the primary input. The prepare starts.

1. You switch to input A by specifying the primary input. The channel switches to input A.

1. You then prepare input B. The prepare starts.

1. You notice that input A is degrading, so you switch to the secondary input. You don't have to prepare input A. Even though you have started to prepare input B, the secondary input for input A is still being prepared, as part of the automatic input failover process. Therefore, the switch proceeds seamlessly.

1. You switch away from input A.

1. You prepare input A again, because you are going to switch to it later. You specify the primary input. The prepare starts.

1. You switch to input A. But you then switch to the secondary input, because the primary input is still degraded. You can switch to the secondary input because, even though you specified the primary input in the prepare action, MediaLive always prepares both inputs.

# How input prepare actions behave at runtime
<a name="input-prep-runtime"></a>

All prepare actions that you add to the MediaLive schedule sit in the schedule until the start time. At the start time (which can be fixed, immediate, or following an input switch), MediaLive stops any input prepare that is currently active, and starts the new input prepare.

Eventually, MediaLive switches to the associated input. At this point, MediaLive doesn't stop preparing the input. The input prepare continues either indefinitely or until another input prepare starts. This perpetual prepare characteristic can be useful. For an example, see [scenario B](plan-prep-tips.md#plan-prep-tips-scenario-B).

If a channel fails, MediaLive automatically restarts the channel. If the schedule indicates that there is an upcoming immediate switch action, and the schedule also contains a prepare action for that input, then MediaLive starts preparing the input again. You don't need to take any steps. 

# Modifying input prepare actions
<a name="input-prep-modify"></a>

For information on modifying an input prepare action that is in the MediaLive schedule, see [Modifying actions in the schedule (console)](schedule-modify.md).

# Deleting and stopping input prepare actions in the MediaLive schedule
<a name="input-prep-delete"></a>

You can delete input prepare actions from the schedule. There are different rules for deleting actions depending on the current state of the channel. The channel can be running, idle, or recovering. The channel is idle if you manually stopped it. The channel is recovering if it failed and MediaLive is automatically restarting it.

For detailed information on deleting an action, see [Deleting actions from the schedule (console)](schedule-using-console-delete.md).

**Deleting actions while the channel is running**  
When the channel is running, you can't delete the most recent input prepare action that is in the past. This rule exists because the associated input switch might be in the future. When MediaLive automatically restarts the channel, it must also restart the input prepare, to ensure that the input for the immediate input switch will be prepared. 

**Deleting actions while the channel is idle**  
When the channel is idle, you can delete any input prepare action.

**Stopping an input prepare**  
To stop an active input prepare, add an immediate input prepare with no input specified.

For detailed information on adding an action, see [Creating actions in the schedule (console)](schedule-using-console-create.md).