Introduction
In today’s digital age, live streaming has become a powerful tool for businesses, content creators, and broadcasters. Whether it’s for entertainment, education, or corporate communications, delivering high-quality live video to a global audience is more accessible than ever, thanks to cloud-based services like AWS Media Services. In this blog, I’ll walk you through the process of building a live streaming solution using AWS Media Services, starting from capturing video with a webcam to delivering it to viewers through a Content Delivery Network (CDN).
Why AWS Media Services?
Before diving into the walkthrough, let’s quickly review why AWS Media Services is a great choice for building live streaming solutions. AWS Media Services offer a comprehensive set of tools that allow you to ingest, process, package, and distribute live video with high performance and scalability. The services work seamlessly together, providing a reliable pipeline for live video streaming from start to finish.
Overview of the Process
Here’s a step-by-step overview of what we’ll be doing:
- Capture video using a webcam and transmit it using FFmpeg.
- Ingest the video stream with AWS Elemental MediaConnect.
- Process the video stream with AWS Elemental MediaLive.
- Package the processed video for delivery with AWS Elemental MediaPackage.
- Deliver the video to viewers through Amazon CloudFront.
Let’s get started!
Step 1: Capturing and Transmitting Video Using FFmpeg
To begin, we need to capture video from a webcam and transmit it to AWS. For this, we’ll use FFmpeg, a versatile tool for handling multimedia data.
- Install FFmpeg: First, download and install FFmpeg on your local machine. This tool will be used to capture the video feed from your webcam and send it to AWS.
You can verify the installation by opening a bash terminal inside the FFmpeg folder and running the following command:
./ffmpeg.exe -version
This will display the FFmpeg version if it has been installed correctly.
- Identify Video and Audio Sources: Once FFmpeg is installed, identify your webcam and microphone sources. You’ll need this information to configure FFmpeg properly. You can list all available devices using the following FFmpeg command:
./ffmpeg.exe -list_devices true -f dshow -i test
Transmit Video Using FFmpeg: With the sources identified, you can now use FFmpeg to transmit the video. Here’s the command:
./ffmpeg.exe -f dshow -i video="YourWebcamName":audio="YourMicrophoneName" -c:v h264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k -c:a aac -b:a 128k -ar 44100 -f mpegts "srt://YOUR_MEDIA_CONNECT_IP:PORT?mode=caller"
Replace YourWebcamName and YourMicrophoneName with the names of your devices, and YOUR_MEDIA_CONNECT_IP:PORT with the IP address and port provided by AWS MediaConnect (in step 2).
Step 2: Ingesting Video with AWS Elemental MediaConnect
AWS Elemental MediaConnect is responsible for ingesting the video stream and forwarding it to other AWS services for processing.
- Create a MediaConnect Flow:
- In the AWS Management Console, navigate to AWS MediaConnect and create a new flow.
- Select the source type as Standard Source, as the video will be coming from your local machine.
- Configure the Flow:
- Set the protocol to SRT-Listener and specify the inbound port number (e.g., 3000).
- For this demo, set 0.0.0.0/0 in the allowlist (CICD block).
- Create the flow. AWS will provide an inbound IP address and port, which will be used in your FFmpeg command (refer to Step 1.4).
.
- Run the FFmpeg Command:
- Replace YOUR_MEDIA_CONNECT_IP:PORT in the FFmpeg command with the provided Inbound IP:Port.
- Run the command to start sending the video stream to MediaConnect.
- Start the Flow:
- Start the MediaConnect flow and ensure the FFmpeg command is running.
- This will initiate the video stream from FFmpeg to MediaConnect. Verify that the health status of the flow shows as connected.
Note: While the MediaConnect flow typically sends video to AWS MediaLive for processing, and MediaLive then sends its output to MediaPackage, we’ll create the MediaPackage channel first since its endpoints are required during the MediaLive channel setup.
Step 3: Packaging Video with AWS Elemental MediaPackage
AWS Elemental MediaPackage packages the processed video into formats suitable for delivery to end-user devices.
- Create a MediaPackage Channel:
- Go to the AWS MediaPackage console and create a new channel.
- Provide the necessary information, such as the channel ID, description, and enable logging.
- Once completed, create the channel.
- HLS Ingest Endpoints:
- MediaPackage will automatically generate two HLS ingest endpoints, each with a unique URL, username, and password.
- These credentials will be required when configuring your MediaLive channel (refer to Step 4 in the MediaLive setup).
- Create an Origin Endpoint:
- Navigate to the “Manage Endpoints” section in the MediaPackage console and create a new origin endpoint.
- Provide an ID for the endpoint and leave the other fields set to their default values.
- Once created, this origin endpoint will serve as the URL where viewers can access the video stream.
Step 4: Processing Video with AWS Elemental MediaLive
AWS Elemental MediaLive is used to process the live video stream, enabling broadcast-quality video processing in real-time.
- Create a MediaLive Channel:
- Navigate to AWS MediaLive and create a new channel.
- Start with a predefined channel template, such as HTTP Live Streaming (HLS), and ensure you select the proper IAM role.
- Set the channel class to SINGLE_PIPELINE, which means only one stream will be processed.
- Set Up Input Attachments:
- In the channel configuration, add an input attachment and set the input type to MediaConnect, as your video stream originates from there.
- Set the input class to SINGLE_INPUT and attach the previously created MediaConnect flow ARN.
- Once the input is created, return to add input attachment and refresh inputs to attach the newly created input to the channel.
- Additionally, create and name an audio selector under General Input Settings.
- Configure Outputs:
- In the HLS output group, remove all default outputs except output_1 and output_2 for this demo.
- Use the URL, username, and password from the HLS ingest endpoint of the MediaPackage channel (created in Step 3) in the HLS group destination. Provide a name and copied password while creating the parameter.These credentials will be used to send the output to MediaPackage.
- In output_1 and output_2, select the audio selector created earlier in the Input Attachment section.
- Create and Start the channel:
- Once all the steps are completed, create the MediaLive channel.
- Start the channel and wait for the channel state to change to Running.
- Check the preview section to confirm the live stream is running successfully.
You can also view the live stream by navigating to the preview link under the Origin Endpoints section of the MediaPackage channel.
Step 5: Delivering Video with Amazon CloudFront
Amazon CloudFront, a CDN service, delivers the video to viewers with high performance and low latency.
- Create a CloudFront Distribution: Go to the CloudFront console and create a new distribution. Select the MediaPackage origin you created earlier as the origin for this distribution.
- Configure Distribution Settings: Allow the necessary HTTP methods (GET, HEAD, OPTIONS) for the viewer, select CachingOptimized as cache policy, select “Do not enable security protections” for Web Application Firewall, and leave other settings as default for this demo.
- Generate the Streaming URL: After creating distribution, CloudFront will provide a distribution domain name. Replace the domain part of the MediaPackage origin URL with this distribution domain name to generate the final streaming URL.
For example:- Original MediaPackage URL: https://example.com/out/v1/stream/index.m3u8
- CloudFront Distribution Domain: https://cdn.example.com
- Final Streaming URL: https://cdn.example.com/out/v1/stream/index.m3u8
- Test the Streaming URL: Use a video player like VLC to open the final streaming URL. If everything is set up correctly, you should see the live video stream playing.
Voila! Now you should see your live stream video taken from your webcam, and using this URL, anyone can watch your livestream.
Conclusion
Building a live streaming solution with AWS Media Services is a powerful way to deliver high-quality video content to a global audience. By following these steps, you can create an end-to-end live streaming pipeline that captures video from a local webcam, processes it with AWS services, and delivers it through a CDN like CloudFront. This setup is scalable, reliable, and optimized for various network conditions, ensuring a smooth viewing experience for all your users.
Whether you’re a developer, content creator, or business looking to stream live video, AWS Media Services offers a comprehensive and flexible solution to meet your needs. With the right setup, you can deliver professional-grade live streams that engage and captivate your audience.
.
