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.
- Install Node.js
- Create a Media Services account.
Make sure to remember the values that you used for the resource group name and Media Services account name.
- Follow the steps in Access Azure Media Services API with the Azure CLI and save the credentials. You will need to use them to access the API.
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.
The sample performs the following actions:
- Creates a Transform (first, checks if the specified Transform exists).
- Creates an output Asset that is used as the encoding Job's output.
- Creates the Job's input that is based on an HTTPS URL.
- Submits the encoding Job using the input and output that was created earlier.
- Checks the Job's status.
- Creates a Streaming Locator.
- Builds streaming URLs.
Run the sample app
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.
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:
Test with Azure Media Player
To test the stream, this article uses Azure Media Player.
If a player is hosted on an https site, make sure to update the URL to "https".
Open a web browser and navigate to https://aka.ms/azuremediaplayer/.
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.
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