1. Live Video Analytics with AWS MediaLive for AI


    To perform live video analytics with AWS MediaLive, the general idea is to set up a streaming channel in MediaLive that ingests live video feed, encodes it, and then streams it to a destination where the video can be analyzed in real-time using AI/ML services.

    To achieve this, you will define resources like Input (the source of the video feed), Channel (which processes the video feed), and potentially an Output, which is the destination to which the processed video stream is sent.

    Below is a Pulumi program in Python that demonstrates how to create a simple MediaLive setup. This example assumes you're ingesting an RTMP feed and outputting it to an HLS (HTTP Live Streaming) endpoint. The actual video analytics would be performed by another service that processes the HLS stream, which is not covered here as it depends on the specific AI/ML service being used and the use case.

    import pulumi import pulumi_aws as aws # Create an AWS MediaLive Input. # This is where your live video stream will be input into MediaLive. # The input type here is set to RTMP_PUSH which means you're pushing an RTMP stream into MediaLive. # Replace `url` and `stream_name` with your actual RTMP stream's URL and name. live_input = aws.medialive.Input("liveInput", type="RTMP_PUSH", destinations=[ aws.medialive.InputDestinationArgs( stream_name="liveStream" ), ]) # Create a MediaLive Channel # This channel will take the Input, encode it according to your settings, and output it to a destination. # The example here demonstrates an output configuration for HLS. # Replace `s3_bucket_arn` with the ARN of an S3 bucket where you want the HLS chunks to be stored. live_channel = aws.medialive.Channel("liveChannel", input_attachments=[ aws.medialive.InputAttachmentArgs( input_id=live_input.id, ), ], destinations=[ aws.medialive.ChannelDestinationArgs( id="destination-1", settings=[ aws.medialive.ChannelDestinationSettingsArgs( url="s3://destinationForHlsChunks", ), ], ), ], encoder_settings=aws.medialive.EncoderSettingsArgs( output_groups=[ aws.medialive.OutputGroupArgs( name="HLS Group", output_group_settings=aws.medialive.OutputGroupSettingsArgs( hls_group_settings=aws.medialive.HlsGroupSettingsArgs( destination=aws.medialive.OutputLocationRefArgs( destination_ref_id="destination-1", ), ), ), outputs=[ aws.medialive.OutputArgs( output_name="hlsOutput", video_description_name="video_1", # Link to a video description below output_settings=aws.medialive.OutputSettingsArgs( hls_output_settings=aws.medialive.HlsOutputSettingsArgs( hls_settings=aws.medialive.StandardHlsSettingsArgs( audio_rendition_sets="program_audio", m3u8_settings=aws.medialive.M3u8SettingsArgs( audio_frames_per_pes=4, pcr_control="PCR_EVERY_PES_PACKET", pmt_pid=480, private_metadata_pid=503, program_number=1, scte35_behavior="NO_PASSTHROUGH", ), ), name_modifier="index", ), ), ), ], ), ], video_descriptions=[ aws.medialive.VideoDescriptionArgs( name="video_1", codec_settings=aws.medialive.VideoCodecSettingsArgs( h264_settings=aws.medialive.H264SettingsArgs( bitrate=5000000, # Adjust bitrate as needed codec_level="H264_LEVEL_AUTO", codec_profile="H264_MAIN", ), ), height=720, # Adjust the resolution as needed width=1280, # Adjust the resolution as needed ), ], ), role_arn="arn:aws:iam::123456789012:role/MediaLiveAccessRole", # Replace with your MediaLive access role ARN ) # Export the HLS endpoint URL hls_endpoint = pulumi.Output.all(live_channel.destinations, live_channel.id).apply( lambda args: f"https://s3.amazonaws.com/{args[0][0].settings[0].url}/index.m3u8" ) pulumi.export('hls_endpoint', hls_endpoint)


    1. AWS MediaLive Input (live_input): This resource represents the live stream input. In this program, an RTMP stream is being pushed to MediaLive.

    2. AWS MediaLive Channel (live_channel): The channel processes and encodes the input stream. It is configured to output an HLS stream, which is a common streaming format for live video on the web. The channel points to a destination, in this case, an S3 bucket (s3://destinationForHlsChunks).

    3. HLS Output Settings: Defines the settings for the HLS output, including codec and HLS-specific settings like the audio frames per PES, program number, and others. The name_modifier appends "index" to the HLS segments' names.

    4. Encoder Settings: The encoder settings configure how the video and audio should be processed. These settings are quite extensive in MediaLive, hence only the video codec settings are shown for brevity, but audio encoding would also be configured in a real-world setting.

    5. IAM Role (role_arn): MediaLive needs permissions to access other AWS resources, such as the S3 bucket. The role_arn should have the necessary policies attached that grant MediaLive permission to write to the S3 bucket.

    6. Endpoints Export: Exports the URL endpoint where the HLS stream can be accessed. This URL can be used to perform live analytics by providing it to an AI/ML service capable of processing video content in real-time.

    This program is simplistic and configures MediaLive to ingest an RTMP stream and push it as an HLS stream to an S3 bucket. It doesn't include more advanced encoding settings, error handling, input security settings, or integrating with AI services for analyzing the video stream.