Smart Crop with AWS Elemental Inference: the programmatic way
Use Smart Crop in AWS Elemental Inference to turn a landscape AWS Elemental MediaLive channel into vertical video that follows the action, set up with the AWS CLI, Python (Boto3), or AWS CloudFormation.
Series: Building with AWS Elemental Inference (4 articles)
- 2Smart Crop with AWS Elemental Inference: the programmatic way This article
Placeholders in angle brackets (for example<CHANNEL_ID>) stand in for your own values.
Prefer a different approach? This article covers the programmatic methods for engineers who automate their setup: the AWS CLI, Python (Boto3), and AWS CloudFormation. If you'd rather click through it by hand in the AWS Management Console, see Smart Crop with AWS Elemental Inference: the AWS Management Console way. If you'd rather have an AI coding assistant build it for you, see Smart Crop with AWS Elemental Inference: building it with AI (Kiro).
The challenge
Live sports, news, and entertainment are produced in landscape 16:9. A growing share of the audience watches on phones, in vertical 9:16 feeds on short-form social video platforms.
Getting a broadcast into that format has usually meant one of two things:
- A fixed center crop. It's cheap and fast, but the action is rarely in the center. A winger on the touchline or a player driving to the basket leaves the frame.
- Manual reframing. An editor follows the action by hand. The result looks good, but it's slow and expensive, and by the time the clip is out the moment has passed.
Smart Crop in AWS Elemental Inference solves this by moving the crop to follow the subject in real time, on the live stream.
This article is for media engineers and developers who run MediaLive channels and are comfortable with Python and the AWS CLI (level 300). You'll enable Smart Crop on an existing channel, automate it with code or AWS CloudFormation, and confirm that it's working. If you'd rather have an AI coding assistant do the building, see Smart Crop with AWS Elemental Inference: building it with AI (Kiro).
How Smart Crop works
AWS Elemental Inference is a managed AI service that works with AWS Elemental MediaLive . It applies AI in parallel with encoding to automatically transform live and on-demand video into ready-to-use outputs and real-time contextual metadata, enabling broadcasters, streamers, and enterprises to reach audiences on any platform, monetize content intelligently, and automate workflows without manual work, reprocessing, or AI expertise. For Smart Crop, the flow is:
- MediaLive sends the video from the channel to an Elemental Inference feed.
- Elemental Inference analyzes the frames and works out where the main subject is, producing a crop center point for each moment of video.
- MediaLive uses those center points to render any output whose scaling is set to
SMART_CROP, for example a 720×1280 vertical rendition.
- Your other outputs, such as the normal 16:9 ladder, are unaffected.
The following diagram shows this flow.

Every article in this series uses three Elemental Inference resources:
Resource | What it is |
|---|---|
Feed | The Elemental Inference resource that receives media and produces metadata. One feed per MediaLive channel. |
Outputs | The features enabled on a feed. Smart Crop uses a cropping output. Other articles in this series cover event clipping, smart subtitling, and contextual metadata. |
Association | The link between a feed and the MediaLive channel that sends it video. |
According to the AWS launch announcement , Elemental Inference typically adds 6–10 seconds of latency.
Prerequisites
To follow along, you need:
- An AWS account with permissions to manage MediaLive and Elemental Inference resources.
- An existing MediaLive channel in a supported AWS Region, with at least one vertical (9:16) output. Use a test channel, not one that's on air.
A MediaLive channel role with the AWS Identity and Access Management (IAM) permissions that Elemental Inference needs. At runtime the channel role needs just two actions:
PutMedia(to deliver the stream to the feed) andGetMetadata(to read the crop metadata back). For the full list of actions, see Actions, resources, and condition keys for AWS Elemental Inference . Here is an example of the required permissions for the policy that needs to be attached to the MediaLive role:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elemental-inference:PutMedia", "elemental-inference:GetMetadata" ], "Resource": "*" } ]}This example uses aResourceof*for simplicity. If you want to narrow it, scope it to feeds rather than to a single feed ARN, usingarn:aws:elemental-inference:<region>:<account>:feed/*. A Smart Crop feed is created fresh (and deleted) each time, so its ARN changes on every run, and a policy pinned to one feed ARN would stop working as soon as you recreate the feed.
- The following versions were used when writing this article. Ensure you are on these versions or later:
- AWS Command Line Interface (AWS CLI) version 2.35.22
- Python 3.14.6
- AWS SDK for Python (Boto3) version 1.43.112
Earlier releases may predate
SMART_CROPandInferenceSettingssupport; see the note on out-of-date tools under Common issues .)
Note: Ensure you are running in an AWS Region where Elemental Inference is available. For the list of supported Regions, see AWS Elemental Inference endpoints and quotas .
Three programmatic paths follow: the AWS CLI, Python (Boto3), and AWS CloudFormation. They achieve the same result; use whichever fits how you work. You only need one.
The AWS CLI
Run these steps in your terminal, in order. Each step shows the command and what to check before moving on.
Step 1: Create the feed
A feed is the Elemental Inference resource that receives your video. For Smart Crop driven by MediaLive, you create the feed with an empty output list and let MediaLive add the cropping output itself when you attach the channel in Step 4. You must still pass the
outputs argument, because it's required, but an empty list is accepted.Run this in your terminal. Replace
<FEED_NAME> with a name of your choice (letters, digits, hyphens, and underscores; names are case-sensitive) and <REGION> with your Region (for example, eu-west-1 ).aws elementalinference create-feed \ --name <FEED_NAME> \ --outputs '[]' \ --region <REGION>The command returns a JSON description of the new feed. Note two values from it, because you need them later:
-
arn: the feed's full Amazon Resource Name, which you attach to the channel in Step 4.
-
id: the feed's short identifier, used in Step 4 and when you check the feed.
The new feed starts with a
status of CREATING and reaches AVAILABLE after a few seconds. Check it with:aws elementalinference get-feed --id <FEED_ID> --region <REGION>Wait until the status is
AVAILABLE before you use the feed.Step 2: Read the current channel configuration
The changes in Steps 3 and 4 modify the channel's existing configuration, so read it first.
If you don't already know your channel's ID, list your channels and note the
Id of your test channel. Check that its State is IDLE , because Step 4 can only update an idle channel.aws medialive list-channels --region <REGION>Save the current channel configuration to a file. You'll edit this file in Step 3 and send it back in Step 4, and it also gives you a "before" copy to compare against.
aws medialive describe-channel \ --channel-id <CHANNEL_ID> \ --region <REGION> > channel-before.jsonList each output with its dimensions and current scaling behavior, and show whether the channel already has any inference settings:
python3 -c "import json; d=json.load(open('channel-before.json')); [print(v.get('Name'), v.get('Width'), 'x', v.get('Height'), '->', v.get('ScalingBehavior')) for v in d['EncoderSettings']['VideoDescriptions']]; print('InferenceSettings:', d.get('InferenceSettings'))"The output looks like this (your names and sizes will differ):
video-horizontal 1920 x 1080 -> DEFAULTvideo-vertical 720 x 1280 -> DEFAULTInferenceSettings: NoneEach line is
NAME WIDTH x HEIGHT -> SCALINGBEHAVIOR . The first value on the line is the output's Name. Find the line whose height is greater than its width (here that's video-vertical , 720 wide and 1280 tall) and note that first value, video-vertical . That's the Name you'll set to SMART_CROP in Step 3.Before the feed is attached,
InferenceSettings is None . In Step 4 you'll see it populated.No output with height greater than width? Then this channel has no vertical output defined, and there's nothing for Smart Crop to reframe. Go back to the second prerequisite and add a vertical (9:16) output to the channel before continuing.
Step 3: Set SMART_CROP on the vertical outputs only
This step turns on Smart Crop. Each output in a MediaLive channel has a video description, and each video description has a
ScalingBehavior :Value | What it does |
|---|---|
DEFAULT | Keeps the source aspect ratio and adds black bars (pillarbox or letterbox) to fill the frame |
STRETCH_TO_OUTPUT | Stretches the picture to fill the frame, which distorts it |
SMART_CROP | Crops the frame by using Elemental Inference to follow the subject |
Set
SMART_CROP only on your vertical video descriptions. The horizontal ones stay on DEFAULT .MediaLive's
update-channel replaces the channel's entire encoder settings in one call. There's no command to change a single output's scaling behavior on its own. So the pattern is read-modify-write: take the configuration you saved in Step 2, change the one value, and send the whole thing back in Step 4.Edit the
channel-before.json you saved in Step 2, changing the vertical output's ScalingBehavior to SMART_CROP and leaving the horizontal output on DEFAULT . You then write just the encoder settings to a new file, encoder-after.json , which you'll send to the channel in Step 4.The quickest way is this one-line edit, which flips every output that's taller than it is wide (your vertical output) and leaves the rest alone:
python3 -c "import json; d=json.load(open('channel-before.json')); [v.update(ScalingBehavior='SMART_CROP') for v in d['EncoderSettings']['VideoDescriptions'] if v.get('Height',0) > v.get('Width',0)]; json.dump(d['EncoderSettings'], open('encoder-after.json','w'), indent=2); print('done')"(If you'd rather not use a script, open
channel-before.json in an editor, find the vertical output's ScalingBehavior value of DEFAULT , change it to SMART_CROP , and save just the EncoderSettings object as encoder-after.json . The one-liner is less error-prone.)Check that only the vertical output changed:
python3 -c "import json; d=json.load(open('encoder-after.json')); [print(v.get('Name'), v.get('Width'),'x',v.get('Height'),'->',v.get('ScalingBehavior')) for v in d['VideoDescriptions']]"You should see your vertical output on
SMART_CROP and the horizontal one still on DEFAULT :video-horizontal 1920 x 1080 -> DEFAULTvideo-vertical 720 x 1280 -> SMART_CROPNothing has changed on AWS yet; you've only edited a local file. The channel is updated in Step 4.
Step 4: Attach the feed, update, and restart the channel
This is the final step. When it's done, your channel is live with Smart Crop: the horizontal output runs as before, the vertical output is reframed in real time to follow the action, and the Elemental Inference feed is attached and producing crop metadata.
This step makes three changes in sequence: it attaches the feed to the channel (through
InferenceSettings ), applies the SMART_CROP encoder settings from Step 3, and restarts the channel so the changes take effect. You can only update a channel while it's idle, so the channel is stopped first and started again afterward. Don't run this against a channel that's on air.Note: Stopping and starting a MediaLive channel each take a few minutes. Expect this step to take several minutes overall. It hasn't stalled.
1. Stop the channel and wait until it's idle.
aws medialive stop-channel --channel-id <CHANNEL_ID> --region <REGION>Check the state until it returns
IDLE (it passes through STOPPING first):aws medialive describe-channel --channel-id <CHANNEL_ID> --region <REGION> --query State --output text2. Update the channel. Apply the edited encoder settings and attach the feed in one call. Replace
<FEED_ARN> with the arn from Step 1.aws medialive update-channel \ --channel-id <CHANNEL_ID> \ --region <REGION> \ --encoder-settings file://encoder-after.json \ --inference-settings FeedArn=<FEED_ARN>3. Start the channel again.
aws medialive start-channel --channel-id <CHANNEL_ID> --region <REGION>The channel passes through
STARTING and reaches RUNNING . You can watch it with the same describe-channel ... --query State command from step 1.4. Confirm MediaLive added the cropping output. When you created the feed in Step 1 it had no outputs. Now that the channel is attached and running, re-read the feed:
aws elementalinference get-feed --id <FEED_ID> --region <REGION>The
outputs list now contains a cropping entry that MediaLive added:{ "name": "medialive-cropping-0", "outputConfig": { "cropping": {} }, "status": "ENABLED", "fromAssociation": true}fromAssociation: true is the key detail. It means MediaLive created the output when you attached the channel, which is why you didn't define it in Step 1. The feed's own status is now ACTIVE and its association points at your channel.Python (Boto3)
The Python path does the whole setup in one script, rather than step by step. Save it as
smart_crop.py , set the three values at the top ( REGION , CHANNEL_ID , FEED_NAME ), and run it with python3 smart_crop.py . The channel must already have at least one vertical (9:16) output; the script stops and restarts the channel, so use a test channel.import timeimport boto3
REGION = "<REGION>" # for example, eu-west-1CHANNEL_ID = "<CHANNEL_ID>" # your existing MediaLive channelFEED_NAME = "<FEED_NAME>" # letters, digits, hyphens, underscores
inference = boto3.client("elementalinference", region_name=REGION)medialive = boto3.client("medialive", region_name=REGION)
def step(msg): print("\n=== " + msg + " ===")
# 1. Create the feed -------------------------------------------------------step("1. Create feed")resp = inference.create_feed(name=FEED_NAME, outputs=[])print("create_feed response keys:", list(resp.keys()))feed_id = resp["id"]feed_arn = resp["arn"]print("feed_id:", feed_id)print("feed_arn:", feed_arn)
print("waiting for AVAILABLE ...")while True: f = inference.get_feed(id=feed_id) if f["status"] == "AVAILABLE": break time.sleep(5)print("feed is AVAILABLE")
# 2. Read channel, set SMART_CROP on vertical outputs ----------------------step("2. Read channel + set SMART_CROP on vertical output(s)")channel = medialive.describe_channel(ChannelId=CHANNEL_ID)encoder_settings = channel["EncoderSettings"]
changed = []for vd in encoder_settings["VideoDescriptions"]: if vd.get("Height", 0) > vd.get("Width", 0): # vertical = taller than wide vd["ScalingBehavior"] = "SMART_CROP" changed.append(vd["Name"])print("Smart Crop set on:", changed)if not changed: raise SystemExit("No vertical output found, nothing to crop. Aborting.")
# 3. Stop -> update -> start ----------------------------------------------step("3. Stop, update (encoder + feed), start")print("stopping ...")medialive.stop_channel(ChannelId=CHANNEL_ID)medialive.get_waiter("channel_stopped").wait(ChannelId=CHANNEL_ID)print("stopped. updating ...")
medialive.update_channel( ChannelId=CHANNEL_ID, EncoderSettings=encoder_settings, InferenceSettings={"FeedArn": feed_arn},)print("updated. starting ...")medialive.start_channel(ChannelId=CHANNEL_ID)medialive.get_waiter("channel_running").wait(ChannelId=CHANNEL_ID)print("channel RUNNING with Smart Crop")
# 4. Confirm MediaLive added the cropping output ---------------------------step("4. Confirm cropping output on the feed")feed = inference.get_feed(id=feed_id)for output in feed.get("outputs", []): print(output.get("name"), output.get("status"), output.get("outputConfig"), "fromAssociation:", output.get("fromAssociation"))print("\nfeed status:", feed.get("status"))print("DONE. Feed id to delete later:", feed_id)What the script does, stage by stage:
- Create the feed: creates an empty Elemental Inference feed (the
outputs=[]is required; MediaLive adds the cropping output itself on attach) and waits until it'sAVAILABLE.
- Read the channel and set
SMART_CROP: reads the channel's encoder settings and switches every vertical output (height greater than width) toSMART_CROP, leaving horizontal outputs onDEFAULT.
- Stop, update, start: stops the channel, applies the encoder settings and attaches the feed via
InferenceSettings, then starts it again. Thechannel_stoppedandchannel_runningwaiters block until each state is reached. (Stopping and starting each take a few minutes.)
- Confirm: re-reads the feed and prints its outputs; you'll see a
croppingoutput withfromAssociation: True, meaning MediaLive created it when you attached the channel.
Expected tail of the output:
=== 4. Confirm cropping output on the feed ===medialive-cropping-0 ENABLED {'cropping': {}} fromAssociation: True
feed status: ACTIVEAWS CloudFormation
CloudFormation supports both resources:
-
AWS::ElementalInference::Feedcreates the feed.
-
AWS::MediaLive::Channelhas anInferenceSettingsproperty that takes the feed ARN.
The
AWS::ElementalInference::Feed resource requires an Outputs property. Pass an empty list ( Outputs: [] ) and MediaLive adds the cropping output when the channel attaches, exactly as with the other methods. Get the feed's ARN with !GetAtt <LogicalId>.Arn (a plain !Ref returns the feed ID instead).The fragment below shows only the two parts that matter for Smart Crop: the feed resource, and the vertical video description set to
SMART_CROP with the feed ARN wired in through InferenceSettings . It is an excerpt, not a complete template: a real AWS::MediaLive::Channel also needs its input attachments, the remaining video descriptions, audio descriptions, and output groups before it will deploy. Think of this as the Smart Crop-specific lines to add to a working channel template, rather than a stack you can deploy as-is.# EXCERPT: Smart Crop-specific lines only; not a complete, deployable template.Resources: SmartCropFeed: Type: AWS::ElementalInference::Feed Properties: Name: <FEED_NAME> Outputs: [] # required; MediaLive adds the cropping output on attach
LiveChannel: Type: AWS::MediaLive::Channel Properties: Name: <CHANNEL_NAME> RoleArn: <MEDIALIVE_ROLE_ARN> InferenceSettings: FeedArn: !GetAtt SmartCropFeed.Arn EncoderSettings: VideoDescriptions: - Name: video-vertical-720p Width: 720 Height: 1280 ScalingBehavior: SMART_CROP # requires InferenceSettings.FeedArn # ... plus the rest of a real channel: other video descriptions, # audio descriptions, output groups, and input attachments ...If you're newer to CloudFormation: don't try to deploy the fragment above on its own. It will fail, because a MediaLive channel needs a complete encoder configuration (inputs, audio, and output groups) to be valid. The easiest way to get a full, working template is to configure a channel the way you want it in the console (or take an existing one), export or describe its configuration, and then add the three Smart Crop lines shown here: the feed resource,InferenceSettings.FeedArnon the channel, andScalingBehavior: SMART_CROPon the vertical video description.
Verified: a full stack (feed + MediaLive channel) deploys toCREATE_COMPLETEwithScalingBehavior: SMART_CROPon the vertical output. TheAWS::ElementalInference::Feedresource requiresOutputs: [](deployment fails without it), and!GetAtt SmartCropFeed.Arnreturns the feed ARN. As with the other methods, MediaLive adds the cropping output to the feed on attach.
Good to know:SMART_CROPonly works when the channel'sInferenceSettingspoints to an Elemental Inference feed (FeedArn). In this template, the channel gets the feed's ARN through!GetAtt, so CloudFormation creates the feed first.
A MediaLive input can only be attached to one channel at a time, so if you're reusing an existing input, detach it from its current channel before deploying, or the stack fails on the input attachment.
After the stack deploys and the channel is running, confirm the setup the same way as the other paths: check that the feed gained the cropping output MediaLive adds on attach.
aws elementalinference get-feed --id <FEED_ID> --region <REGION>The
outputs list should contain a cropping entry marked fromAssociation: true , confirming that MediaLive attached Smart Crop to the feed. From here, verify the running channel exactly as for the other methods; see Verify Smart Crop is working below.Verify Smart Crop is working
If you set Smart Crop up programmatically, you can confirm it at the data level, by asking the feed for the crop center points it is producing.
There is no built-in command for this metadata query (neither the AWS CLI nor Boto3 model it), so the script below is the way to read the crop coordinates. It's self-contained: set your region and channel ID at the top and run it; the script works out everything else from the channel.
The feed has a separate data endpoint you query for this metadata. There is no Boto3 method or AWS CLI command for it, so it's a SigV4-signed HTTPS request;
botocore (installed with Boto3) does the signing with your normal AWS credentials.To run it:
- Make sure your AWS credentials are active in the terminal (the same profile you used to set Smart Crop up, for example
export AWS_PROFILE=your-profile).
- Save the script below as
read_crop.py.
- Set two values at the top: your region and your channel ID. (Region has to be set explicitly: the script's very first call needs a region before it can look anything up.) From the channel, the script then works out the rest on its own: the feed attached to it, that feed's data endpoint, the cropping output's name, and the output's frame rate.
- Run it:
python3 read_crop.py.
import json, time, urllib.requestimport botocore.sessionfrom botocore.auth import SigV4Authfrom botocore.awsrequest import AWSRequest
# --- set these two -------------------------------------------------------REGION = "<your-region>" # e.g. "eu-west-1"CHANNEL_ID = "<your-channel-id>" # your MediaLive channel# -------------------------------------------------------------------------
TIMESCALE = 90000 # MediaLive PTS clock: 90,000 ticks per second
session = botocore.session.Session()
# From the channel we read the vertical output's frame rate and, via the feed# attached to it, the data endpoint and cropping output name. Nothing else hard-coded.ml = session.create_client("medialive", region_name=REGION)channel = ml.describe_channel(ChannelId=CHANNEL_ID)
# Frame rate: read it from the SMART_CROP video description. Most channels state# it explicitly; if yours inherits it from the source instead, set FRAME_RATE by# hand below and delete the three auto-detect lines.smart_vds = [vd for vd in channel["EncoderSettings"]["VideoDescriptions"] if vd.get("ScalingBehavior") == "SMART_CROP"]codec = next(iter(smart_vds[0]["CodecSettings"].values()))FRAME_RATE = codec["FramerateNumerator"] // codec.get("FramerateDenominator", 1)# FRAME_RATE = 50 # <- uncomment and set this if the lines above can't find it
# Find the feed attached to this channel, then read its data endpoint + outputs.ei = session.create_client("elementalinference", region_name=REGION)feed_summary = next(f for f in ei.list_feeds()["feeds"] if f.get("association", {}).get("associatedResourceName") == channel["Arn"])feed = ei.get_feed(id=feed_summary["id"])endpoint = feed["dataEndpoints"][0]cropping_output = next(o["name"] for o in feed["outputs"] if "cropping" in o["outputConfig"])
host = endpoint.replace("https://", "").rstrip("/")url = f"https://{host}/v1/feed/{feed['id']}/input/0/metadata"
end = int(time.time()) - 25 # 25s ago: margin for metadata to landbody = json.dumps({ "outputName": cropping_output, "timeSpecification": {"ptsBased": { "startPts": (end - 10) * TIMESCALE, # a 10-second window "endPts": end * TIMESCALE, "timescale": TIMESCALE}}, "parameters": {"smartCropping": { "frameRate": {"numerator": FRAME_RATE, "denominator": 1}}},})
req = AWSRequest(method="POST", url=url, data=body, headers={"Content-Type": "application/json", "host": host})SigV4Auth(session.get_credentials().get_frozen_credentials(), "elemental-inference", REGION).add_auth(req)http = urllib.request.Request(url, data=body.encode(), headers=dict(req.headers), method="POST")
items = json.loads(urllib.request.urlopen(http, timeout=60).read())["items"]print(f"{len(items)} items returned")for it in items[:5]: c = it["metadata"]["smartCropping"]["crop"]["centerPoint"] print(f"x={c['xPosition']/c['scale']:.3f} y={c['yPosition']/c['scale']:.3f}")A few things worth knowing about the query:
- The window ends 25 seconds in the past, comfortably beyond the 6–10 seconds of added latency, so the metadata has had time to reach the data endpoint. An empty result usually just means "widen the margin or retry in a few seconds," not a failure.
- The feed produces one entry per analyzed frame, so a 10-second window at 50fps returns roughly 500 items.
- Each
centerPointhasscale,xPosition,yPosition. Divide the positions byscaleto get fractions of the full frame:xPosition 7978 / scale 10000is x≈0.80 (the crop center sits ~80% across the frame). The y value stays at exactly 0.5, because a vertical crop uses the full height of the source, so it only has room to move sideways, never up or down. (That could change if a future crop used less than the full height, giving the center vertical freedom too; today it doesn't.)
If the x value changes from frame to frame as the action moves across the frame, Smart Crop is tracking. Content with lateral movement, such as a football match, shows this clearly; a static, center-framed source will sit near x≈0.5 and barely move.

To watch Smart Crop track rather than read coordinates, see Smart Crop with AWS Elemental Inference: build a live demo viewer. It builds a small local web page that draws the crop region moving across the full landscape picture in real time.
Common issues
These are the issues most likely to trip you up when setting up Smart Crop on a live channel. Each one has a simple fix.
Black bars on the vertical output. If a vertical output is left on
ScalingBehavior: DEFAULT , MediaLive keeps the full 16:9 picture and pads the 9:16 frame with black. It looks as if Smart Crop has failed, but it isn't turned on for that output. Set SMART_CROP on each vertical video description.
Left:
SMART_CROP fills the 9:16 frame, following the subject. Right: DEFAULT keeps the 16:9 source and pads it with black bars. (Sample content: AWS Elemental "Formula 5 Racing" demo.)Smart Crop set, but nothing is being cropped. Setting
SMART_CROP doesn't guarantee cropping is happening. If the MediaLive role is missing the Elemental Inference IAM permissions, MediaLive quietly falls back to its default cropping, with no error and no failed channel, so the output looks configured while the inference never runs. This is the most deceptive failure here: check the role has PutMedia and GetMetadata (see Prerequisites ), and confirm actual crop data as described in Verify Smart Crop is working .Out-of-date tools. Older AWS CLI and SDK versions don't know about
SMART_CROP or InferenceSettings . They can reject the change before it's sent, and can leave InferenceSettings out of describe-channel output, so a working channel looks unconfigured. Update first.A feed update replaces the whole feed. Updating a feed replaces its full configuration, so any output you leave out is removed. Read the feed first, change what you need, and send the complete configuration back.
Unknown fields are ignored. Elemental Inference ignores unknown fields inside a feed output's configuration and doesn't return an error, so a typo can look as if it worked. Read the feed back after every change.
A limit on enabled outputs per feed. A feed can have a limited number of enabled outputs at a time. In the AWS Elemental Inference Service Quotas , the "Enabled outputs per feed" quota is 5 (and marked not adjustable), while "Total outputs per feed" is higher. Check the current value for your account, as quotas can change. Outputs can be defined but left disabled without counting against the enabled limit, so plan which features each channel needs.
Crop queries have their own rules. The metadata query has a few easy-to-miss requirements: the query parameter is
smartCropping (not the cropping output type), frameRate is required and must match the output, windows are capped at 30 seconds, and the time window must be built from the stream's own PTS timeline. These are covered in full under Verify Smart Crop is working .Practical considerations
- Pricing is consumption-based: you pay for the features you use and the video you process. See the AWS Elemental Inference pricing page .
- On a Standard (two-pipeline) MediaLive channel, Elemental Inference features are charged for both encoding pipelines. A single-pipeline channel is cheaper for testing.
- Keep a note of each channel's output frame rate. You need it for crop queries.
Clean up
To avoid ongoing charges, remove what you created when you're done testing. The order matters: revert the channel before you delete the feed. Elemental Inference will let you delete a feed that's still attached, without an error, but that leaves the channel pointing at a missing feed, still set to
SMART_CROP , silently falling back to a plain center crop. Always revert the channel first, then delete the feed.AWS CLI or Boto3
If you set Smart Crop up with the AWS CLI or Boto3, revert it the same way. The important detail is how you detach the feed: you do not call
disassociate-feed yourself, and simply omitting --inference-settings on an update does nothing (MediaLive leaves the existing value untouched). Instead, you send the channel's inference settings with the feed ARN removed, and MediaLive does the rest.1. Revert the channel's encoder settings and remove the feed ARN, together, in one update.
Start from your saved
channel-before.json (its vertical output is already on DEFAULT ), or re-describe the channel and set each vertical output's ScalingBehavior back to DEFAULT . In the same update, pass InferenceSettings with no FeedArn (an empty inference-settings object), so MediaLive detects the feed is gone:aws medialive update-channel \ --channel-id <CHANNEL_ID> \ --region <REGION> \ --encoder-settings file://encoder-default.json \ --inference-settings '{}'Here
encoder-default.json is the EncoderSettings object with the vertical output back on DEFAULT . In the Boto3 path, do the same: set ScalingBehavior back to DEFAULT on the vertical video description, and call update_channel with InferenceSettings={} (no FeedArn ).Why this works. With noFeedArnin the saved inference settings, MediaLive detaches the feed for you and Elemental Inference sets its status toARCHIVED. Don't calldisassociate-feedyourself, because it raises aValidationException(that operation is for the feed's source-media association, not the channel link). A successful detach shows asInferenceSettings: nullon the nextdescribe-channel.
2. Delete the feed (optional). Once the channel no longer references it, the feed is
ARCHIVED and stops incurring charges (all its outputs are disabled). An archived feed can't be re-enabled (you'd have to set Smart Crop up from scratch), so you can leave it archived or delete it outright:Use whichever matches the path you've been following; you only need one.
AWS CLI:
aws elementalinference delete-feed --id <FEED_ID> --region <REGION>Python (Boto3):
inference.delete_feed(id=feed_id)3. Stop or delete the channel if you no longer need it, to stop channel charges.
AWS CloudFormation
If you created the resources with a CloudFormation stack, delete the stack instead of doing the steps above. It removes the feed and channel together, in the right order.
Conclusion
In this article, you enabled Smart Crop on an AWS Elemental MediaLive channel programmatically, with the AWS CLI, Python (Boto3), or AWS CloudFormation, and confirmed crop center points were being produced. For more detail, see the AWS Elemental Inference User Guide .
Next in the series
This article is one of four on Smart Crop. The companion articles cover the same feature for different audiences:
- Smart Crop with AWS Elemental Inference: the AWS Management Console way: no code, done in the AWS Management Console.
- Smart Crop with AWS Elemental Inference: the programmatic way (this article): the AWS CLI, Python (Boto3), and AWS CloudFormation.
- Smart Crop with AWS Elemental Inference: building it with AI (Kiro): let an AI coding assistant build and run it for you.
- Smart Crop with AWS Elemental Inference: build a live demo viewer: a small web page, built with Python, that plays your channel and draws the crop region over it as it moves.
Smart Crop is the first of the AWS Elemental Inference features this series covers. Each of the others will get the same four articles. Still to come:
- Event Clipping (coming soon): use the same feed to find the key moments in a live broadcast and turn them into clips automatically.
- Smart Subtitling (coming soon)
- Contextual Metadata (coming soon)
Series: Building with AWS Elemental Inference (4 articles)
- 2Smart Crop with AWS Elemental Inference: the programmatic way This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article