Tutorial: Encode a remote file based on URL and stream the video - Node.js

This tutorial shows you how easy it is to encode and start streaming videos on a wide variety of browsers and devices using Azure Media Services. An input content can be specified using HTTPS URLs, SAS URLs, or paths to files located in Azure Blob storage.

The sample in this article encodes content that you make accessible via an HTTPS URL. Note that currently, AMS v3 does not support chunked transfer encoding over HTTPS URLs.

By the end of the tutorial you will be able to stream a video.

Play the video

If you don't have an Azure subscription, create a free account before you begin.

Prerequisites

Download and configure the sample

Clone a GitHub repository that contains the streaming Node.js sample to your machine using the following command:

git clone https://github.com/Azure-Samples/media-services-v3-node-tutorials.git

The sample is located in the StreamFilesSample folder.

Open index.js in you downloaded project. Replace the endpoint config values with credentials that you got from accessing APIs.

The sample performs the following actions:

  1. Creates a Transform (first, checks if the specified Transform exists).
  2. Creates an output Asset that is used as the encoding Job's output.
  3. Creates the Job's input that is based on an HTTPS URL.
  4. Submits the encoding Job using the input and output that was created earlier.
  5. Checks the Job's status.
  6. Creates a Streaming Locator.
  7. Builds streaming URLs.

Run the sample app

  1. The app downloads encoded files. Create a folder where you want for the output files to go and update the value of the outputFolder variable in the index.js file.

  2. Open command prompt, browse to the sample's directory, and execute the following commands.

    npm install 
    node index.js
    

After it is done running, you should see similar output:

Run

Test with Azure Media Player

To test the stream, this article uses Azure Media Player.

Note

If a player is hosted on an https site, make sure to update the URL to "https".

  1. Open a web browser and navigate to https://aka.ms/azuremediaplayer/.

  2. In the URL: box, paste one of the streaming URL values you got when you ran the application.

    You can paste the URL in HLS, Dash, or Smooth format and Azure Media Player will switch to an appropriate streaming protocol for playback on your device automatically.

  3. Press Update Player.

Azure Media Player can be used for testing but should not be used in a production environment.

Clean up resources

If you no longer need any of the resources in your resource group, including the Media Services and storage accounts you created for this tutorial, delete the resource group.

Execute the following CLI command:

az group delete --name amsResourceGroup

See also

Job error codes.

Next steps