5G Video Streaming Tutorial

AlefEdge is the 5G Edge API company. We leverage cellular networks to bring processing power as close to the application as possible, allowing for devices to become intelligent and applications to run faster. As compute moves out to the edges of the network and into cell towers and buildings, this decentralization of the internet is an exciting new frontier and there are many new applications appearing. Today we are going to look at a single use case — video streaming.  

Goal 

At the end of this tutorial, you will be able to view a video served from the Edge. 

Purpose 

By running through this tutorial, you will familiarize yourself with AlefEdge’s Video Enablement API and reach the following milestones: 

  • Create an Private Edge account and receive your API key 
  • Create a Video Enablement Subscription 
  • Add a video to the Edge 
  • Request and receive a sandbox Edge environment.
  • View the video served from the edge.   

Requirements

  1. An Private Edge account
  2. Access to your computer’s terminal or command line
  3. A VNC viewer
  4. A short, publicly available mp4 or m3u8 video hosted on the web. You will be provided with example videos, but if you are curious to try your own, that is possible too. 

Instructions 

Follow these steps to set up your own Video Enablement Subscription and view your video from the Edge.  

Create an Account 

An Private Edge Account is required to access Alef’s APIs. To get an account, complete the following steps. 

  1. Go to https://developer.alefedge.com/ and click on “Sign Up” in the navigation bar.
  2. Enter the required profile information. Required fields are designated by an asterix (*). You can name your organization however you see fit. A profile picture is not required, but encouraged! Click the blue “Next” button in the bottom right of the screen. Please note, for the Phone Number data field, you will not enter your country code. Instead, the country must be selected from the dropdown indicated by the icon of a flag. Once the country is selected from the dropdown, please enter your phone number details. If the details for your country are not included in the dropdown, please create a support ticket and it will be rectified shortly thereafter. 

  3. Confirm the profile information that was previously entered by clicking the blue “Next” button at the bottom of the screen.

  4. Read and agree to the Alef Acceptable Usage Policy and the Alef Privacy Policy, complete the reCAPTCHA activity, and click the blue “Create Account” button in the bottom right of the screen.

  5. Check your email for a message from AlefEdge. You will be sent a link to confirm your account and set up a password. Please use a strong password (hovering over the blue “i” icon to review the requirements).

  6. Once a password is set, a final email, containing your username, email address, and API Key will be sent to you. Your API key is also available through your account. Treat your API key carefully. It is unique to your account and should not be shared nor stored in version control (Git, Mercurial, etc).

Congratulations! You have set up your Private Edge account. 

Set-up Video Enablement Subscription 

Now that you have access to your account and an API key, it is time to set up a Video Enablement Subscription.  

  1. From your Developer Portal Homepage, you can see a list of services (if your account is new, this list will be empty). Hit the plus icon to the right of “My Services” and then select “Alef Video Enablement” to be taken to a page to create your Video Enablement subscription.

  2. Select the location nearest to you in the upper right of the screen. You will be provided with purchase details. The Private Edge free tier can make unlimited API calls, but has a 2GB upload limit.


  3. Click purchase to see the service details. Enter a unique and descriptive service name and hit the blue “Confirm” button.
  4. After hitting “confirm” you will be taken to a page where you can configure your new Video Enablement Subscription. There are a few fields that are pre-populated and a few that you will need to fill in.  
    • Email Id, Phone Number, Full Name, Service Id, Edge Storage Size, and Tenancy will come pre-populated. Leave them as they are. You will need the Service Id for your API request.
      • Please note Service ID is equivalent to Partner Name in the API Parameters  
    • Whitelist Domain should include the domain that corresponds to the URL of the video you are adding to the Video Enablement Subscription. This is required to avoid a DNS error.  For the purpose of this tutorial, you can use https://dummypartner.testalef.net . If you want to try your own video, you will need to add the domain associated with it. 
    • Edge Storage Size corresponds to the allowed size of the video file. Currently, on our free tier, files are limited to 2 GB. This field is pre-populated for you
    • Secret Key and Secret Token are applicable for private videos protected by a signed URL. They are not needed for this tutorial and should be left blank.   
  1. Once you have completed all your fields, hit the submit button below to complete configuring your Video Enablement Subscription.

Request a Sandbox

At this point in the tutorial, we are going to go over a step that will save you some waiting time later on. 

In the real world, Private Edge requires some infrastructure (5G network, eSIMs, etc) that are not easily replicated for development and testing. Alef provides the developer with a sandbox environment that replicates a 5G Edge connection. From within a sandbox, you will be able to view content that has been added to the edge. 

To request your sandbox, make sure you are on your Developer Portal site (https://portal.developer.alefedge.com/). Once there, click on the “Sandbox” link in the Horizontal Navigation Bar at the top of the page. You will be taken to request a Sandbox.

Please begin the request process by entering a unique name for the Sandbox. Choose the location that you used for your Video Enablement Subscription.
Hit the ‘Request Sandbox’ button below to request your sandbox.

Your sandbox will take a bit of time to be built and delivered to you. You can expect an email to be sent to the email address associated with your Private Edge account. This email will provide instructions on how to access your sandbox. It may take an hour for your sandbox to be ready. 

Confirm Whitelist Domains

Locate the URL of the video you want to add. Feel free to use these sample videos. 

mp4: https://dummypartner.testalef.net/alef/openingshot.mp4

m3u8: https://dummypartner.testalef.net/demo/myencoding.m3u8

Now confirm that the appropriate domains are whitelisted, by making a get-whitelist-domain API call. It will look like this curl script:

curl -X 'GET' \
  'https://developerapis.stg-alefedge.com/et/api/v1/stream-tech/get-whitelist-domain?partner_name=SERVICE_ID' \
  -H 'accept: application/json' \
  -H 'api_key: YOUR_API_KEY'

Replace YOUR_API_KEY with the API key you were sent via email. Replace SERVICE_ID with the Service ID from your configuration page.

Confirm that you get the proper domain in the response. If you are using our sample videos, the response should look like this:

{
  "cors_whitelist_domain": [
    "https://dummypartner.testalef.net"
  ]
}

If the response does not include the correct domain, you will need to add it. Additionally, if you are using an m3u8 file, there is an additional domain you must add. Because the m3u8 files are streaming files, you need to add the domain for a m3u8 player. Alef has a sample one that you can use. So whether you need to add the domain of the video you want to play, or whether you want to add the domain of the Alef video player so you can play an m3u8 file, let’s cover how to add whitelist domains. 

You will need to make an add-whitelist-domain API call. The curl script will look like this:

curl -X 'POST' \
'https://developerapis.stg-alefedge.com/et/api/v1/stream-tech/add-whitelist-domain?partner_name=SERVICE_ID' \
  -H 'accept: application/json' \
  -H 'api_key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "cors_whitelist_domain": "https://player.stg-alefedge.com"
}'

Replace SERVICE_ID and YOUR_API_KEY as you did in the previous call. For this sample, the domain ‘https://player.stg-alefedge.com’ is for Alef’s m3u8 player. 

You can make another get-whitelist-domain API call to confirm that the new domain was added. 

Use Onboard Public API to Add Videos to the Edge 

Now that you have properly configured your Video Enablement Subscription and confirmed your whitelist domains, you can use the Public Onboard API to add videos to the Edge. This will be done via curl commands. You will need to open your terminal and run the following from your command line. Be sure to substitute the appropriate parameters for your project. 

curl -X 'POST' \
  'https://developerapis.stg-alefedge.com/et/api/v1/stream-tech/content/add?partner_name=SERVICE_ID' \
 -H 'accept: application/json' \
  -H 'api_key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "urlList": [
    {
      "url": "https://dummypartner.testalef.net/alef/openingshot.mp4",
      "content_access": "public",
      "publish_access": "public",
      "partner_cloud_url": "https://dummypartner.testalef.net/alef/openingshot.mp4"
    }
  ]
}'

Replace YOUR_API_KEY with the API key you were sent via email. Replace SERVICE_ID with the Service ID from your configuration page.  The content_access parameter indicates whether the video you are uploading is publicly available. The publish_access parameter indicates whether the resulting edge video will be public or private. For the purposes of this tutorial, they are both public. The ‘url’ and ‘partner_cloud_url’ should be the same url. If you want to try your own video, please update both of these parameters for your API call. 

Copy this curl statement into your terminal and hit enter. You will see the following message to indicate the video was added.  

 

[ { "message": "Content onboarding is in progress", "status": "INPROGRESS", "url": CONFIRM_URL, "content_id": "abc" } ] 

Your content_id is randomly generated and will be different from the above example.

Confirm Video was Added and get Edge URL

Now that you have added a video, you will want to further familiarize yourself with the Edge Net Video Enablement API and to get a critical piece of information for viewing the video from the edge. 

To see that the video was added to your subscription, you will need to make another API call. It looks like this:

curl -X 'GET' \
  'https://developerapis.stg-alefedge.com/et/api/v1/stream-tech/content/get-all?partner_name=SERVICE_ID' \
  -H 'accept: application/json' \
  -H 'api_key: YOUR_API_KEY'

As in the previous step, replace ‘SERVICE_ID’ and ‘YOUR_API_KEY’ with the appropriate values specific to you and your subscription. 

You will receive a response in this form:

[{
"id": 1325,
"partner_name": "6080cd1af470cd000784a8f0",
"content_id": "abb",
"content_url":
"https://edge.stg-alefedge.com/v1/content?url=00c104e612cb7f461e6446d77125a0edb3b8a827df1bd1149f3a08cad05d4af7869b0fd1345afdb80c83ee58c901af0949ef8427cbd7d1d3afde25937daf44be83d2426c08eff1a81cde6f3417278fe9",
"partner_content_url": "CONFIRM_URL",
"partner_cloud_url": "CONFIRM_URL",
"createdAt": "2021-04-22T17:01:51.000Z",
"updatedAt": "2021-04-22T17:01:55.000Z",
"content_upload_status": "success",
"content_access": "public",
"publish_access": "public",
"content_status_message": "Partner Content on-boarded Successfully",
"partner_content_file_name": "CONFIRM_FILE_NAME",
"content_size": 4096
}]

Notice that there is both a ‘content_url’ and a ‘partner_content_url’. The ‘partner_content_url’ is the URL that you uploaded. The ‘content_url’ is the URL where the video is now hosted at the edge. You will need the content_url in a later step, so copy it now and keep it ready. 

Access your Sandbox

You now need to access the sandbox you requested. Check the email associated with your Private Edge account. It may take up to an hour for the sandbox details to be delivered. If after an hour you have not received your sandbox, please let us know at support@alefedge.com and we will help you with next steps.

If you have received your email, you can use the provided information to access your sandbox. For this tutorial, we recommend using VNC viewer. Input the sandbox address including the port. For this example, the address is in the form: sandbox.lav-64.alef-edge.net:3040.

You may get an encryption warning. You can ignore it because we are not working with anything sensitive.

The sandbox password is also provided in the email. Your Private Edge password will not work. Enter it when prompted. 

You will then be logged into your sandbox. You should see a black background with an Ubuntu logo. 

Once you have successfully logged into your sandbox, right click within the sandbox and select firefox. Now let’s watch the video! 

View your Video from the Edge

Refer back to the content URL we got in a previous step. It should look something like this:

 

https://edge.stg-alefedge.com/v1/content?url=00c104e612cb7f461e6446d77125a0edb3b8a827df1bd1149f3a08cad05d4af7869b0fd1345afdb80c83ee58c901af0949ef8427cbd7d1d3afde25937daf44be83d2426c08eff1a81cde6f3417278fe9

It is necessary to append your API key to this URL. The final URL will be in this form:

 

content_url&api_key=YOUR_API_KEY

It will look something like this:

https://edge.stg-alefedge.com/v1/content?url=00c104e612cb7f461e6446d77125a0edb3b8a827df1bd1149f3a08cad05d4af7869b0fd1345afdb80c83ee58c901af0949ef8427cbd7d1d3afde25937daf44be83d2426c08eff1a81cde6f3417278fe9&api_key=XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX

At this URL your video will be served from the edge. The sandbox replicates an edge environment, so will be able to play the video at this URL within your sandbox. It will not play from your browser on your machine. Go ahead and try it if you want.

In order to view the video from the edge, this URL will need to be pasted into the browser in the sandbox. Please note that if you are on a Mac, instead of ‘command-v’ as a keyboard shortcut, you will need to use ‘control-v’. Paste the URL into the browser, hit enter, and watch your video!

Did you get a download request? If you did, that is because you are trying to play an m3u8 file. From within your sandbox, please navigate to the Alef video player https://player.stg-alefedge.com/edge, enter your url and press the ‘submit query’ button. 

Still didn’t work? Confirm that you have added https://player.stg-alefedge.com to your whitelist domain list before trying again. 

Your sandbox will be available for a minimum of three hours. You will receive an email warning you when your time is expiring soon and another when your sandbox has been deleted. Once the sandbox is deleted, you will be able to request another one through the same process described above. 

Outcome 

Congrats! You have successfully completed our video streaming tutorial. Now you have your own Private Edge account and have added a video to the Edge. Pat yourself on the back, you did it!  Welcome to the Edge.  

Next Steps 

We would love to hear your thoughts on this tutorial or on our API in general. We would love to hear from you on our forum

 

How useful was this post?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?