AWS for M&E Blog

Using NDI for video switching and routing in AWS

Network Device Interface (NDI) is a royalty-free standard developed to facilitate near real-time and ultra-low latency video communication over internet protocol (IP) in a frame-accurate manner without compromising quality. This technology is a bidirectional standard that allows video systems to identify and communicate with one another over IP and to encode, transmit, and receive multiple streams of video and audio in near real time. The NDI encoding algorithm is resolution and frame-rate independent and supports multichannel, floating-point audio. NDI also includes tools to implement video and audio access and grouping, bidirectional metadata, tally, and remote connections. The system benefits media houses in building live production workflows by facilitating communication between production systems, like graphics, mixers, switching, cameras, and editing stations, all using IP-based networks.

Although NDI supports mDNS to give NDI receivers knowledge about existing NDI senders in a network, we focus in this blog post on the NDI Discovery method for significantly large NDI deployments where mDNS might not be practical. NDI Discovery Server is a thin application operating entirely in unicast mode, managing a centralized repository for the NDI sources in the network. It is recommended to have NDI devices perform discovery in cloud platforms.

NDI Discovery Server works for both NDI receivers and NDI source devices by configuring the Discovery Server address into NDI Access Manager Application. The NDI Discovery Server makes a persistent connection to all configured devices and constantly informs the receivers on NDI source availability. For example, if an NDI source stops, the connection to NDI Discovery Server will end, and Discovery Server intimates all the NDI receivers about the unavailability of that NDI source. Similarly, when the new NDI source establishes a connection with NDI Discovery Server, the server intimates the new NDI source’s availability to all the NDI receivers.

In this post, we take you through the steps to configure highly resilient NDI traffic within a virtual private cloud (VPC) using NDI Discovery Server in the Amazon Web Services (AWS) Cloud.

Schematic view

Schematic view on NDI discover architecture

Step 1. Create VPC.

Create a simple VPC using the AWS CloudFormation VPC template. AWS CloudFormation lets you model, provision, and manage AWS and third-party resources by treating infrastructure as code. The template creates VPCs with two public subnets and two private subnets along with VPC components, like internet gateway and NAT gateway. However, this blog limits the NDI traffic activation to two public subnets within the VPC.

Step 2. Install NDI Discovery Server.

The NDI Discovery Server application is extremely thin and nonresource intensive; hence, we recommend using general-purpose Amazon Elastic Compute Cloud (Amazon EC2) instance type like Amazon EC2 T3 Instances, which are an Amazon EC2 low-cost, burstable, general-purpose instance type.

  • For NDI Discovery Server, launch two Linux Server Amazon EC2 T3 Instances within a VPC that each map to different public subnets.
  • [Optional] Specify below NDI Discovery Server installation commands against “user data” while launching the instance. For more details on user data at launch, please refer to this document. The command below downloads, installs, and runs the NDI Discovery Server.
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, always]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
export PAGER=cat
if [ ! -f "Install_NDI_SDK_v5_Linux.tar.gz" ]; then
   sudo wget https://downloads.ndi.tv/SDK/NDI_SDK_Linux/Install_NDI_SDK_v5_Linux.tar.gz
fi
if [ ! -f "Install_NDI_SDK_v5_Linux.sh" ]; then
  sudo tar -xvf Install_NDI_SDK_v5_Linux.tar.gz
fi
if [ ! -f "/NDI SDK for Linux/bin/x86_64-linux-gnu/ndi-directory-service" ]; then
  echo "y" | ./Install_NDI_SDK_v5_Linux.sh
fi
nohup "/NDI SDK for Linux/bin/x86_64-linux-gnu/ndi-directory-service" >> /dev/null &
  • Configure the security group to use inbound rules, allowing all traffic for VPC classless interdomain routing.
  • Log in to both instances using valid credentials.
  • Initiate the following command on the shell (skip if step “b” is followed):
    • Download NDI Discovery Server.
sudo wget https://downloads.ndi.tv/SDK/NDI_SDK_Linux/Install_NDI_SDK_v5_Linux.tar.gz
    • Extract NDI Discovery Server install.
sudo tar -xvf Install_NDI_SDK_v5_Linux.tar.gz
    • Accept NDI license agreement and install.
echo "y" | ./Install_NDI_SDK_v5_Linux.sh
    • Run NDI Discovery Server in the background or foreground, depending on your need.
#running service in background
nohup "/NDI SDK for Linux/bin/x86_64-linux-gnu/ndi-directory-service" >> /dev/null &

#running service in foreground
"/NDI SDK for Linux/bin/x86_64-linux-gnu/ndi-directory-service"

Step 3. Create two Windows instances on Amazon EC2, a web service that provides secure, resizable compute capacity in the cloud. These instances act like both NDI sender and receiver to demonstrate the video discovery and switching.

For this step, use Amazon EC2 G3 Instances, which are Amazon EC2 GPU graphics instances, or Amazon EC2 G4 Instances, which are cost-effective, versatile GPU instances (use Amazon EC2 G4dn Instances).

  • Launch two Windows Server instances in a VPC that each map to different public subnets—use Amazon EC2 G3 Instances or Amazon EC2 G4dn Instances.
  • Configure the security group to use inbound rules, allowing all traffic for VPC classless interdomain routing.
  • Log in to both the instances using valid credentials.

Step 4. Install necessary drivers and software on the Amazon EC2 instances.

Step 5. [Manual] Register two Windows instances with NDI Discovery Server.

  • Log in to both the instances using valid credentials.
  • Open the NDI Access Manager application under NDI Tools in both Amazon EC2 instances using the Start button.

NDI access manager

  • Click the Advanced tab and select Discovery Servers under Network Mapping. Configure IP Addresses with private IP address of both NDI Discovery Server that was created in step 2, separated by a comma.

NDI access manager configuration

Step 6. [Automated] Register two Windows instances with NDI Discovery Server.

Instead of manual registration of each NDI-facilitated instances for NDI Discovery Server, we can automate using a function of AWS Lambda, a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service.

  • Open the AWS Lambda console.
  • In the navigation pane, select Functions.
  • Select the Create Function button.
  • In Basic Information, enter Function Name as “discovery-server-provision”.
  • Select Ruby 2.7 as a runtime.
  • Select the Create Function button.
  • In the Code tab, double-click “lambda_function.rb”.
  • Copy the following code snippet and replace the existing code displayed in the editor section.
  • Select the Deploy button.

Below is the code snippet for “discovery-server-provision” AWS Lambda (Ruby source).

require 'json'
require 'aws-sdk-ec2'
require 'aws-sdk-ssm'

def lambda_handler(event:, context:)
  # TODO implement
  puts "Event Details => #{event}"
  puts "Provision the Discovery Server on the NDI® instance."
  puts "Discovery Servers => #{ENV["NDI_DISCOVERY_SERVER"]}"

  ec2 = Aws::EC2::Client.new
  resp = ec2.describe_instances({
                                  instance_ids: [
                                    event["detail"]["instance-id"],
                                  ],
                                })

  puts "Instance Response => #{resp}"
  if event["detail"]["state"] == "running" then
    puts "Instance is running and ready to execute power shell commands!!"
    sleep 120
    ssm = Aws::SSM::Client.new
    cmd = "(gc C:\\ProgramData\\NewTek\\NDI\\ndi-config.v1.json) -replace ( (gc C:\\ProgramData\\NewTek\\NDI\\ndi-config.v1.json) | Select-String discovery), '\"discovery\": \"#{ENV["NDI_DISCOVERY_SERVER"]}\"' | Out-File -encoding ASCII C:\\ProgramData\\NewTek\\NDI\\ndi-config.v1.json"
    response = ssm.send_command({
                                  instance_ids: ["#{event["detail"]["instance-id"]}"],
                                  document_name: "AWS-RunPowerShellScript",
                                  parameters: {
                                    "commands" => [ "#{cmd}" ]
                                  }
                                })
    puts "Response on Discovery provisioning => #{response}"
  end
end
 

Step 7. Configure a rule for Amazon CloudWatch, a monitoring and observability service, for “EC2 Instance State-change Notification.”

Configure an Amazon CloudWatch rule for “EC2 Instance State-change Notification” event against Amazon EC2, associating the “discovery-server-provision” AWS Lambda.

  1. Open the Amazon CloudWatch console.
  2. In the navigation pane, find Rules under the Events section.
  3. Select the Create Rule button.
  4. Choose Event Pattern in the Event Source section.
  5. In Service Name, select EC2.
  6. Under Event Type, select EC2 Instance State-change Notification.
  7. In “Specific state(s),” select “running.”
  8. In the Targets section, select “Add target*”.
  9. Select “discovery-server-provision” AWS Lambda as a target.
  10. Select Configure Details, and provide a rule name of your choice.


Step 8. Test the NDI traffic.

Configuring NDI on the first instance.

  • Log in to one Amazon EC2 instance using valid credentials. We named it as “NDIHost1”.
  • Activate NDI output in OBS Studio.
    • Open the OBS application.
    • Select Tools, and choose “NDI Output settings.”
    • Select Main Output. For the main output name, enter the name of your choice. We used “OBS-Output1”.

OBS NDI output configuration

Configuring NDI on the second instance.

  • Log in to the second Amazon EC2 instance using valid credentials. We named it as “NDIHost2”.
  • Activate the NDI output in OBS Studio.
    • Open the OBS application.
    • Select Tools, and choose “NDI Output settings.”
    • Select Main Output. For the main output name, enter the name of your choice. We used “OBS-Output2”.

OBS NDI output configuration

Check Video Sharing between instances.

  • Open the NDI Studio Monitor application under NDI Tools in both Amazon EC2 instances using the Start button.

NDI tools

  • The NDI Studio Monitor discovers both NDI outputs generated by both instances.

NDI stream selection and switching on NDI-HOST1NDI stream selection and switching in NDI-HOST2

  • Select NDIHOST2 > OBS-Output2 in NDI-HOST1 instance.
  • Select NDI-HOST1 > OBS-Output1 in NDI-HOST2 instance.
  • Video is shared between two instances using NDI.

Playing NDI output across instancesPlaying NDI output across instances

Conclusion

In this post, we walked through how to use NDI Discovery Server to configure NDI traffic within a VPC that facilitates communication between NDI-activated video processing software within IP network–based live video production.

Remember to stop the Amazon EC2 Instance when you are not using it. This stops the instance from incurring costs when not in use. To delete the instance permanently, close out the instance.

NDI is a registered trademark of Vizrt Group.

Maheshwaran G

Maheshwaran G

Maheshwaran G is a Specialist Solution Architect working with Media and Entertainment supporting Media companies in India to accelerate growth in an innovative fashion leveraging the power of cloud technologies. He is passionate about innovation and currently holds 8 USPTO and 7 IPO granted patents in diversified domains.