

# Elemental Inference features using AWS CLI
<a name="elemental-inference-cli"></a>

This section describes how to use the AWS CLI to set up AWS Elemental Inference in an AWS Elemental MediaLive channel. 

We assume that you have read the sections about setting up individual Elemental Inference features using the MediaLive console.
+ [Event clipping](elemental-inference-event-clip.md)
+ [Smart crop](elemental-inference-smart-crop.md)

**Topics**
+ [Setting up Elemental Inference features for the first time](smart-crop-procedure-cli-create.md)
+ [Adding more Elemental Inference features](smart-crop-add-features.md)
+ [Viewing features using the AWS CLI](smart-crop-cli-view.md)
+ [Disabling some Elemental Inference features in a channel](smart-crop-disable-some.md)
+ [Disabling all Elemental Inference features in a channel](smart-crop-disable-all.md)

# Setting up Elemental Inference features for the first time
<a name="smart-crop-procedure-cli-create"></a>

This section describes how to set up the first set of Elemental Inference features in MediaLive. You can set up when you are first creating a channel, or you can set up in an existing channel. You can set up one Elemental Inference feature or several features at the same time. 

You must set up a fully-configured feed: resource - feed - output or outputs, where the MediaLive channel is the resource and each output represents one Elemental Inference feature.

1. **In Elemental Inference**, use `create-feed` to create a new feed. Follow these guidelines:
   + Give the feed a memorable name. You might want to give it the same name or similar name to the MediaLive channel. 

     Note that if you previously set up Elemental Inference features using the MediaLive console, you will see these feeds when you use `list-feeds`. These feeds will always have a name that is identical to the channel name.
   + Include outputs as described in the following table.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-procedure-cli-create.html)

1. The response includes the following information that you should make a note of:
   + The feed ID, which you will need for CLI commands on this feed.
   + The feed ARN, which you will need to work with the MediaLive channel. You can also obtain the ARN using `get-feed`.

1. **In MediaLive**, use `create-channel` or `update-channel` to create a channel or edit an existing channel. 
   + At the top level of the JSON, add an `InferenceSettings` section and include:
     + `feedArn`: The ARN of the feed that you created. Include this line only once, even if you are enabling more than one Elemental Inference feature.
   + Make changes for each feature, as described in the following table.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-procedure-cli-create.html)

   The following example shows the JSON for enabling both smart crop and event clipping. 

   Smart crop is enabled in the video encode (video description) named `high_resolution` in an output named `output_A` in the output group named `My_outputgroup` in the channel with the ID `9042242`. The video description includes, among other parameters, the parameters `Height`, `Name`, `ScalingBehavior`, and `Width`. 

   The ARN of the feed ends with the unique ID `vbphju6m7nohlpcs3sd`.

   ```
   {
     "Arn": "arn:aws:medialive:us-west-2:111122223333:channel:9042242",
   ...
     "EncoderSettings": {
   ...
       "OutputGroups": [
         {
           "Name": "My_outputgroup",
   ...
           "Outputs": [
             {
   ...
               "OutputName": "output_A",
   ...
               "VideoDescriptionName": "high_resolution"
             }
           ]
         }
       ],
   ...
       "VideoDescriptions": [
   ...
           "Height": 1280,
           "Name": "high_resolution",
           "ScalingBehavior": "SMART_CROP",
           "Width": 720
         }
       ]
     },
     "Id": "9042242",
   
   
     "InferenceSettings": {
       "FeedArn": "arn:aws:elemental-inference:us-west-2:111122223333:feed/vbphju6m7nohlpcs3sd"
   ...
   }
   ```

1. When you save the channel, MediaLive updates the Elemental Inference feed as follows:
   + It creates a crop output in the feed. 
   + It associates the channel (the resource) with the feed.

   You now have a usable feed: resource - feed - output.

1. In MediaLive, use `StartChannel`. When the channel is running, MediaLive performs the following actions:
   + MediaLive delivers the source stream to Elemental Inference.
   + It handles the metadata as described in the following table.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-procedure-cli-create.html)

**Observations**

There are differences in the procedure for setting up different Elemental Inference, particularly in terms of how the division of labor between Elemental Inference and MediaLive in one feature is different from the division of labor in another feature.

The following table summarizes the key differences in this division of labor. In the table, read across the row for each feature.


|  Feature  |  Actions you perform in Elemental Inference  | Actions your perform in MediaLive | 
| --- | --- | --- | 
|  Event clipping  | You create a feed for the channel (if there isn't one already), and you attach a clipping output.  | You make sure that the feed ARN is specified.  | 
| Smart crop | You create a feed for the channel (if there isn't one already), but you don't attach a smart crop output. | You make sure that the feed ARN is specified. And you configure the video outputs in the channel to work with smart crop. MediaLive is the actor that creates the smart crop output in Elemental Inference. | 

# Adding more Elemental Inference features
<a name="smart-crop-add-features"></a>

In a MediaLive channel where Elemental Inference features are already set up, you can add more Elemental Inference features.

If you want to disable features rather than add them, see [Disabling some Elemental Inference features in a channel](smart-crop-disable-some.md) or [Disabling all Elemental Inference features in a channel](smart-crop-disable-all.md).

1. Make sure that you have room in the [enabled outputs quota](https://console.aws.amazon.com/servicequotas/home?region=us-east-1#!/services/elemental-inference/quotas) for Elemental Inference. The list of quotas is sorted alphabetically. Look for quotas that don't start with "Request rate for".

   Keep in mind that each feature that you enable in a channel results in one Elemental Inference output.

1. **In MediaLive**, use `update-channel` to edit the channel. Make changes as described in the following table.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-add-features.html)

1. When you save the channel, MediaLive performs the following actions:
   + If you are adding smart crop for the first time, MediaLive updates the feed in Elemental Inference to create a crop output in the feed.

1. **In the Elemental Inference**, use `update-feed` to update the feed. Make changes as described in the following table.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-add-features.html)

1. When you are ready to start the channel, use `StartChannel` in MediaLive.

# Viewing features using the AWS CLI
<a name="smart-crop-cli-view"></a>

To view information about Elemental Inference features, use `get-feed` to obtain this information:
+ The ARN of a feed.
+ The ARN of the MediaLive channel that is associated with the feed. This value is in `associatedResourceName`.
+ The data endpoint of the feed. The feed receives media data at this endpoint and returns the resulting metadata to this endpoint. 
+ A list of the outputs that belong to the feed. Each output is of type `GetOutput`.
+ The status of each output is captured in each `GetOutput`. The output is either `ENABLED` or `DISABLED`. When MediaLive is managing feeds, outputs will always `ENABLED`. (MediaLive doesn't ever disable a feed output that is no longer set up for Elemental Inference features. Instead, it simply deletes it.)

  You can change the status of an output to disable the related feature. For information, see [Disabling some Elemental Inference features in a channel](smart-crop-disable-some.md) or [Disabling all Elemental Inference features in a channel](smart-crop-disable-all.md).
+ The status of the feed. You can't change the status of a feed. The service controls the status. 

  The following statuses are most interesting when you are using MediaLive to work with Elemental Inference features:
  + `ACTIVE` means that the feed is associated with the channel.
  + `DELETED` means that MediaLive has deleted the channel. After a short period \$1\$1how long?, the status will always change to `ARCHIVED`. There is no way to change the status of a feed that is `DELETED` or `ARCHIVED`. If you reenable Elemental Inference features in a channel, MediaLive will create a new feed that has a new ID.

# Disabling some Elemental Inference features in a channel
<a name="smart-crop-disable-some"></a>

Follow this procedure if you want to disable some Elemental Inference features in the MediaLive channel, but you want to keep at least one feature. For example:
+ Keep smart crop enabled in at least one output. 
+ Disable smart crop but keep event clipping enabled.

In this procedure, you disable a feature in the relevant MediaLive channel outputs. And you disable the output for that feature in the Elemental Inference feed.

**Topics**
+ [Make changes in MediaLive](#smart-crop-disable-some-eml)
+ [Make changes in Elemental Inference](#smart-crop-disable-some-inference)
+ [Result of disabling some features](#smart-crop-disable-result-partial)
+ [Re-enabling Elemental Inference features](#smart-crop-disable-partial-reenable)

## Make changes in MediaLive
<a name="smart-crop-disable-some-eml"></a>

Use `update-channel` to make changes in the JSON for the MediaLive channel.


|  If you want to disable...  |  Action  | 
| --- | --- | 
|  Event clipping  |  There are no changes to make in the channel JSON.  | 
| Smart crop in one or more outputs |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-disable-some.html)  | 

See [Setting up Elemental Inference features for the first time](smart-crop-procedure-cli-create.md) for an example of the JSON as it appears *before *you make these changes.

**Note**  
Don't touch the `feedArn` parameter in the `InferenceSettings` section of the JSON.

## Make changes in Elemental Inference
<a name="smart-crop-disable-some-inference"></a>

Make changes in Elemental Inference as described in the following table.


|  Action  |  Action  | 
| --- | --- | 
|  To disable event clipping  |  Use `UpdateFeed` to change the status parameter of the `OutputConfig` that is of type `ClippingConfig`. Change the status from `ENABLED` to `DISABLED`.  | 
| To disable smart crop in all video outputs | Use UpdateFeed to change the status parameter of the OutputConfig that is of type CropConfig. Change the status from ENABLED to DISABLED.  | 
| To disable smart crop in some video outputs | There are no changes to make. Leave the status of CropConfig as ENABLED. | 

## Result of disabling some features
<a name="smart-crop-disable-result-partial"></a>

Disabling some features changes the behavior of MediaLive and Elemental Inference as follows:
+ MediaLive continues to send the source video to Elemental Inference because there is still a `feedArn` parameter in the channel.
+ Elemental Inference continues to produce metadata for outputs that are enabled (which means that corresponding feature is enabled). But it stops producing metadata for outputs that are disabled.

  When an output is disabled, the following rules apply: 
  + You don't incur charges for a DISABLED output.
  + But you can still read the existing metadata in that output for the next 24 hours. After that time, the output remains disabled, but its metadata is deleted.

For example, if you previously had both event clipping and smart crop enabled, but you then disable event clipping, MediaLive continues to send the source video. Elemental Inference continues to produce event clipping metadata but it stops producing smart cropping metadata.

## Re-enabling Elemental Inference features
<a name="smart-crop-disable-partial-reenable"></a>

If a MediaLive channel currently has at least one Elemental Inference feature enabled, you can re-enable features that you previously disabled). Follow the procedure [Adding more Elemental Inference features](smart-crop-add-features.md), with this difference: instead of adding `OutputConfig` items, set the status of existing items to `ENABLED`.

# Disabling all Elemental Inference features in a channel
<a name="smart-crop-disable-all"></a>

Follow this procedure to disable all Elemental Inference features in a MediaLive channel. 

In this procedure, you disable a feature in the relevant MediaLive channel outputs. And you disable the output for that feature in the Elemental Inference feed.

**Topics**
+ [Make changes in MediaLive](#smart-crop-disable-all-eml)
+ [Result of changes to the MediaLive channel](#smart-crop-disable-all-result-global)

## Make changes in MediaLive
<a name="smart-crop-disable-all-eml"></a>

Use `update-channel` to make changes in the MediaLive channel.

1. In the `InferenceSettings` section of the JSON, remove the `feedARN` line.

1. Make changes to remove the special configuration that applies to each feature that is enabled.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/medialive/latest/ug/smart-crop-disable-all.html)

See [Setting up Elemental Inference features for the first time](smart-crop-procedure-cli-create.md) for an example of the JSON as it appears before you make these changes.

## Result of changes to the MediaLive channel
<a name="smart-crop-disable-all-result-global"></a>

When you save the changes to the channel, MediaLive takes these actions, in this order:
+ MediaLive uses `associate-feed` in Elemental Inference to disable all the outputs in the feed. It does this because it detects that there is no `feedArn` parameter in the channel.

  After an output is disabled, you can still read the existing metadata in the output for the next 24 hours. After that time, the output remains disabled, but its metadata is deleted.
+ MediaLive uses `disassociate-feed` to disassociate the channel (the resource) from the feed. It does this because it detects that there are no enabled outputs in the feed. 
+ When the resource is disassociated from the feed, Elemental Inference automatically sets the status of the feed to `Archived`. 

When you start the channel, MediaLive and Elemental Inference behave differently:
+ There is no `feedArn` parameter in the channel, so MediaLive stops sending the source video to Elemental Inference. (It doesn't put media.)
+ All the outputs are disabled, so Elemental Inference stops generating metadata for each feature. 

These changes affect the charges that you incur:
+ You don't incur charges for the feed because all the outputs are disabled.

**Re-enabling Elemental Inference features** 

The feed has been set to `Archived`, so you can't re-enable any Elemental Inference features. Instead, you must [set up the features ](smart-crop-procedure-cli-create.md)again. 