

# Implementing pipeline locking
<a name="pipeline-lock"></a>

You can configure MediaLive to use pipeline locking to synchronize outputs. Pipeline locking works with standard channels (which have two pipelines) and with single-pipeline channels using linked channels. Pipeline locking ensures that the outputs are frame-accurate with each other. Pipeline locking is enabled by default.

When pipeline locking is enabled. MediaLive locks the pipelines on a best-efforts basis. When pipeline locking isn't possible, processing continues. The inability to lock pipelines isn't considered to be a fault condition. 

The default mode for pipeling locking is pipeline locking You can't disable pipeline locking in the applicable output types. But you should configure the behavior, to make sure it suits your workflow. 

**Note**  
You might be familiar with the term *output locking*. In MediaLive, the term used is *pipeline locking*. Whatever term is used, the effect is identical: frame accurate outputs.

**Pipeline locking modes**

There are two output locking modes:
+ Pipeline locking (the default): lock the two pipelines to each other
+ Epoch locking: lock the pipelines using the Unix epoch as the reference.

**Pipeline locking methods**

When you use pipeline locking mode, you can choose the method that MediaLive uses to synchronize the pipelines:
+ Source timecode (the default): MediaLive uses embedded timecodes from the input source to synchronize the pipelines. This method works best with reliable timecodes.
+ Video alignment: MediaLive uses visual signature comparison between encoders to synchronize the pipelines. This method does not require embedded timecodes and is useful when your input sources lack timecodes or have unreliable timecodes. For more information, see [Requirements for video aligned locking](pipeline-locking-verify-input.md#pipeline-locking-video-alignment-inputs).

**Applicable outputs**

**Source timecode** pipeline locking applies only to the following types of outputs:
+ HLS (Live mode)
+ MediaPackage
+ CMAF Ingest
+ Microsoft Smooth
+ UDP outputs that are segmented. You might have configured a UDP output group for segmented outputs. To verify, in a UDP output group, choose **Output** then **Network Settings**, then **Container Settings**. Look for the three fields that start with the term *Segmentation*.

**Video aligned** locking applies only to the following types of outputs:
+ HLS (Live mode)
+ CMAF Ingest

The channel can contain other types of outputs, but MediaLive won't attempt to lock their outputs. This means that in those other output groups, there is no guarantee that the content of the two pipelines will be frame-accurate with each other. 

**Topics**
+ [Input and output requirements](pipeline-locking-verify-input.md)
+ [Setting up for locking](pipeline-locking-set-up.md)
+ [Troubleshooting](pipeline-locking-tshoot.md)

# Input and output requirements
<a name="pipeline-locking-verify-input"></a>

In order for MediaLive to lock pipelines, the following conditions must be in effect in the channel. When pipeline locking isn't possible, processing continues. As soon as the required conditions are again in effect, MediaLive starts to lock again.

## No support for HLS inputs
<a name="pipeline-locking-verify-no-hls"></a>

The channel can't include HLS inputs. 

If the channel includes an HLS input, MediaLive stops attempting to lock pipelines in the channel. Pipeline locking won't resume, even after the channel switches to another input. 

## Inputs must include embedded timecode (source timecode method)
<a name="pipeline-locking-embedded-tcode"></a>

When you use the source timecode pipeline locking method (the default), the input must include embedded timecode. These rules apply:
+ When using the source timecode method, the input must have an embedded timecode. This requirement applies to both pipeline locking mode and epoch locking mode.
+ For epoch-locking mode, the embedded timecode must be within 2 minutes of epoch time. If the timecode is off by more than 2 minutes, MediaLive considers that the source doesn't meet the requirements for pipeline locking.

MediaLive continually probes the current source for an embedded timecode. Whenever it doesn't detect the timecode, it temporarily suspends the attempt to lock pipelines.

## Requirements for video aligned locking
<a name="pipeline-locking-video-alignment-inputs"></a>

**Note**  
Video aligned locking is available only when the output locking mode is set to **PIPELINE\$1LOCKING** (not **EPOCH\$1LOCKING**).

When you use video aligned locking (**Pipeline locking method** set to **VIDEO\$1ALIGNMENT**), embedded timecodes are not required.

**Input requirements**

Certain input types are not compatible with video alignment:
+ File inputs (MP4\$1FILE, TS\$1FILE)
+ HLS inputs (URL\$1PULL with HLS content)
+ RTMP\$1PULL inputs

When an incompatible input type is active, video aligned locking runs in "open loop" mode (unlocked) but continues processing. No validation error is raised, which supports input switching workflows where some inputs may be incompatible.

For all other input types, video aligned locking uses visual signature comparison to synchronize the pipelines. Both pipelines must receive the same video content for successful synchronization.

## Frame rate requirements
<a name="pipeline-locking-requirements-frame-rate"></a>

The conversion between the input framerate (or framerates) and the desired output framerate must be *simple*, which means that one of these statements must apply:
+ The output framerate must be a whole number multiple of the input framerate. For example, the input framerate might be 45 FPS, and the output framerate might be 90 FPS.
+ The input framerate must be a whole number multiple of the output framerate. For example, the input framerate might be 60 FPS, and the output framerate might be 30 FPS.

MediaLive identifies the source input framerate when it switches to a new input, and determines if a simple conversion applies. If it doesn't, MediaLive stops the attempt to lock pipelines until the channel switches to the next input. Even if the source input framerate changes in mid source (so that a simple conversion applies), MediaLive doesn't start attempting to lock again.

Note that with these rules, it is possible for the framerates to be integers. For example, if the input framerate is 29.97 FPS and the output framerate is 59.94 FPS.

Following are examples of *complex* framerates. You *can't* use the input if one of these combinations applies to your channel:
+ This isn't supported: Input FPS is 59.4, output FPS is 60.
+ This isn't supported: Input FPS is 45, output FPS is 60.
+ This isn't supported: Input FPS is 29.97 FPS, output FPS is 23.978.

## Epoch locking and SCTE 35
<a name="pipeline-locking-requirements-scte35"></a>

There are constraints for using epoch locking in an HLS or MediaPackage output group. 

**HLS output group**

It's not possible to enable SCTE 35 passthrough or manifest decoration in an HLS output group in a channel that uses epoch locking. You will get a validation error when you save the channel. You must decide how to resolve this conflict: 
+ Don't enable epoch locking in the entire channel: You can [set the mode](pipeline-locking-set-up.md#pipeline-locking-mode) to regular pipeline locking in the entire channel, and keep SCTE 35 passthrough in the HLS output group.
+ Disable SCTE 35 passthrough in the HLS output group: You can keep epoch locking but disable SCTE 35 passthrough and manifest decoration in the HLS output group. You can still enable SCTE 35 passthrough in other output groups. 

**MediaPackage output group**

For a MediaPackage output group, constraints apply if the input includes SCTE 35 messages: 
+ When epoch locking isn't enabled in the channel, MediaLive automatically passes through any SCTE 35 messages from the input and automatically enables manifest decoration. 
+ When epoch locking is enabled, MediaLive automatically disables SCTE 35 passthrough and manifest decoration in the MediaPackage output group.

You should decide which feature you want to keep. You can keep the SCTE 35 messages (in which case you must disable epoch locking in the entire channel). Or you can enable epoch locking but lose passthrough of the SCTE 35 messages. Note that there is no advantage to setting up the output as an HLS output group, because similar constraints apply, as described above.

# Setting up for locking
<a name="pipeline-locking-set-up"></a>

Pipeline locking is enabled by default in a standard channel. You can disable it. If you decide to keep it enabled, you should configure the mode to use in a specific channel. And you should configure the output groups to ensure that MediaLive can successfully lock the pipelines.

**Note**  
All the procedures in this section assume that you are familiar with the general steps for creating a channel, as described [Creating a channel from scratch](creating-channel-scratch.md).

## Configuring output locking and setting the mode
<a name="pipeline-locking-mode"></a>

You can configure the channel as follows:
+ Locking disabled
+ Locking enabled in pipeline locking mode: lock the two pipelines to each other
+ Locking enabled in epoch locking mode: lock the pipelines using the Unix epoch as the reference.

**Configure the pipeline locking mode and method**

1. In the channel that you are creating or editing, in the navigation pane, choose **General settings**. Then choose **Global configuration**.

1. Choose **Enable global configuration**.

1. In **Output locking mode**, choose **DISABLED**. Or choose the mode—**PIPELINE\$1LOCKING** or **EPOCH\$1LOCKING**. For details about the options, choose the **Info** link next to the field. 

1. To configure the pipeline locking method (available only with **PIPELINE\$1LOCKING** mode), expand **Additional settings**.

1. In **Output locking settings**, locate the **Pipeline locking method** field and choose the method for synchronization:
   + **SOURCE\$1TIMECODE** (default): Uses embedded timecodes from the input source. Requires inputs with reliable embedded timecodes. See [Inputs must include embedded timecode (source timecode method)](pipeline-locking-verify-input.md#pipeline-locking-embedded-tcode).
   + **VIDEO\$1ALIGNMENT**: Uses visual signature comparison between encoders. Does not require embedded timecodes. See [Requirements for video aligned locking](pipeline-locking-verify-input.md#pipeline-locking-video-alignment-inputs) for input compatibility.

1. (Optional) For CMAF Ingest and MediaPackage V2 output groups, you can configure a custom epoch. Expand **Additional settings**, then in **Output locking settings**, locate the **Custom epoch** field and enter a custom epoch time.

## Setting up an HLS, MediaPackage, or Microsoft Smooth output group
<a name="pipeline-locking-outputgroups"></a>

In an HLS output group or Microsoft Smooth output group, you must set up the framerate for each video encode. 

**Set up for pipeline locking**

1. In the channel that you are creating, in the navigation pane, choose the HLS or Microsoft Smooth output group. If necessary, create the outputs and video encodes in each output.

1. In each output that contains a video encode, choose the video encode. In the **Codec settings** field, choose the codec. More fields appear.

1. Choose the **Frame rate ** section and set the following fields:
   + **Framerate control**: We recommend you choose **Specified**. The option **Initialize\$1from\$1source** doesn't work well with pipeline locking.
   + **Framerate numerator** and **Framerate denominator**: Set the desired resolution for the output. Make sure that the conversion from input framerate to output framerate meets [the requirements](pipeline-locking-verify-input.md).

1. Repeat, to setup of the frame rate in the video encode in every output.

## Setting up a UDP output group
<a name="pipeline-locking-udp"></a>

In a UDP output group, you must obtain information about segmentation markers, and set up the segmentation markers for framerate for each video encode.

**Set up for pipeline locking**

1. You need information about the how to configure segmentation in the outputs. This information is contained in fields on the **Create channel** page on the console. To display the fields, in the navigation pane choose **Archive group**. Then choose an output and choose **Network settings**. Choose the **Info** link next to each of the following fields: 
   + **Segmentation markers**
   + **Segmentation time**
   + **EBP lookahead msec**
   + **Fragment time**
   + **Segmentation style**
   + **EBP placement**
   + **EBP audio interval**

1. Speak to your contact at the downstream system to obtain recommended values for these fields. 

1. In the channel that you are creating, in the navigation pane, choose the Archive output group. If necessary, create the outputs. Then in the **Output settings**, choose **Network settings**. More fields appear.

1. Choose **Container settings** and set values for the segmentation fields listed in step 1. It's possible that some of the fields don't apply to the segmentation markers you choose.

1. If necessary, create the video encode in the output, then choose the video encode. In the **Codec settings** field, choose the codec. More fields appear.

1. Choose the **Frame rate ** section and set the following fields:
   + **Framerate control**: We recommend you choose **Specified**. The option **Initialize\$1from\$1source** doesn't work well with pipeline locking.
   + **Framerate numerator** and **Framerate denominator**: Set the desired framerate for the output. Make sure that the conversion from input framerate to output framerate meets [the requirements](pipeline-locking-verify-input.md).

# Troubleshooting
<a name="pipeline-locking-tshoot"></a>

Pipeline locking ensures that the pipelines are frame accurate with each other, in the output groups where MediaLive performs pipeline locking.

If you or the operator at the downstream system notices that the pipelines are not synchronized, you can perform the following troubleshooting.

## General troubleshooting
<a name="pipeline-locking-tshoot-general"></a>

These troubleshooting steps apply to all pipeline locking methods:
+ Make sure that MediaLive [supports pipeline locking](pipeline-locking-verify-input.md) for the type of input in your channel.
+ Make sure that the affected outputs are eligible for pipeline locking. Pipeline locking applies [only to specific types of outputs](pipeline-lock.md).
+ Make sure that you changed the **Framerate control** so that it is *not ***Initialize\$1from\$1source**.
+ Check the **ComplexFRCPresent** CloudWatch metric. A value of 1 indicates that Medialive is performing complex framerate conversion and is not attempting to lock pipelines. Pipeline locking only supports [simple framerate conversions](pipeline-locking-verify-input.md#pipeline-locking-requirements-frame-rate). 
+ If the framerate within the source changes, it's possible that MediaLive can't perform pipeline locking for the duration because for that section of video, there is no simple framerate conversion.

## Troubleshooting timecode-based locking
<a name="pipeline-locking-tshoot-source-timecode"></a>

If you are using epoch locking, or pipeline locking with the source timecode method (the default), check the following in addition to the general troubleshooting steps:
+ Make sure that the input source has an embedded timecode.
+ If you chose epoch-locking mode, make sure that the embedded timecode is within 2 minutes of epoch time.
+ If an input source has sections where there is no embedded timecode, MediaLive stops performing frame-accurate pipeline locking. MediaLive automatically falls back to performing approximate pipeline locking. Whenever the embedded timecode reappears, MediaLive resumes frame-accurate pipeline locking.
+ Make sure that you remembered to set up segmentation markers in a UDP output group. For the other supported output groups, you don't need to worry about this because their outputs are always segmented.
+ Make sure that you set up the segmentation marker type that your downstream system expects.

## Troubleshooting video aligned locking
<a name="pipeline-locking-tshoot-video-alignment"></a>

If you are using video aligned locking (**Pipeline locking method** set to **VIDEO\$1ALIGNMENT**) and experience synchronization issues, check the following in addition to the general troubleshooting steps:
+ Verify that the current input type is compatible. HLS, RTMP\$1PULL, and file inputs cause video aligned locking to run in open loop mode (unlocked). See [Requirements for video aligned locking](pipeline-locking-verify-input.md#pipeline-locking-video-alignment-inputs).
+ Check the **InputVideoAligned** CloudWatch metric. A value of 1 indicates pipeline locking has successfully aligned the input video content between pipelines. If the value is 0: 
  + Ensure both pipelines are receiving the same video content. Video aligned locking compares visual signatures between encoders and cannot lock if the content differs.
+ Check the **PipelinesLocked** CloudWatch metric. Video aligned locking reports its locked status through this same metric. A value of 1 indicates successful synchronization.
+ If synchronization is intermittent, verify that your network connectivity to both pipelines is stable. Visual signature comparison requires consistent video delivery to both encoders.