GithubHelp home page GithubHelp logo

isabella232 / media-services-node-vod Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/media-services-node-vod

0.0 0.0 0.0 709 KB

This sample demonstrates an example about video on demand in Azure Media Services with AngularJS and NodeJS

License: MIT License

JavaScript 99.44% HTML 0.33% CSS 0.23%

media-services-node-vod's Introduction

services platforms author
media-services
node
msonecode

Video on Demand in Azure Media Services with AngularJS and NodeJS

Introduction:

When using Azure Media Services to deliver videos on demand, you have to first upload the content to the Azure Storage associated with the Media Services account. This includes several requests to Azure Media Services to create an asset, an asset file, a write permission access policy and a locator. The locator contains a SAS URL with write access which the client can use to upload the video to storage. If you're running a VOD website, the "client" to Azure Media Services is usually your web server, in which case when the user of your website publishes a video, the video is sent from his/her device to the web server first, then the web server passes it on to the storage.

It would be more efficient though, to upload video from the end device to storage directly without the web server acting as an intermediate. An approach is to send the SAS URL to the device then use javascript to put the video to storage. This example demonstrates this flow and implements it with AngularJS, NodeJS and MongoDB. It has very basic CRUD operations and simple playback with Azure Media Player as well.

Prerequisites:

1. Azure Media Services account

Get the Account Name and Primary Key from portal.azure.com > Media Services > Account Keys. They will be used as Client ID and Client Secret.

2. Streaming Endpoint.

Ensure you have a streaming endpoint enabled in portal.azure.com > Media Services > Streaming endpoints.

3. MongoDB

This sample application uses MongoDB to store asset ID, streaming URL, thumbnail and other information. If you don't have one yet, you may get a free one from mlab.

4. Enable CORS for the Storage Account associated with Media Services

The easiest way is to use Azure CLI.

azure storage cors set -a "{YOUR-STORAGE-ACCOUNT}" -k "{STORAGE-ACCOUNT-KEY}" --blob --cors "[{\"AllowedOrigins\":\"*\",\"AllowedMethods\":\"GET,POST,PUT,OPTIONS\",\"MaxAgeInSeconds\":\"86400\",\"AllowedHeaders\":\"*\",\"ExposedHeaders\":\"*\"}]" --verbose

Application Flow:

AngularJS ------------------ NodeJS ------------------ Azure Media Services

  |---- upload request ---->|

              |---------- create asset --------->|

              |------- create asset file -------->|

              |-- create write access policy --->|

              |-------- create locator --------->|

              |<----------- SAS URL ------------|

  |<------- SAS URL -------|

  |---------------------------------------------- video ----------------------------------> Azure Blob Storage

  |---- encode request --->|

              |------- update asset file ------->|

              |-- delete write access policy --->|

              |--------- delete locator -------->|

              |--------- encode video -------->|

              |------ check encode status ---->|

              |<------- encode finished --------|

              |-- create read access policy --->|

              |--------- create locator -------->|

              |<-------- streaming url ----------|

  |<----- streaming url -----|

  |------------------------- playback ------------------------>|

Run the sample:

1. Set up config.js.

  • db: MongoDB connection string
  • client_id: Azure Media Services Account Name
  • client_secret: Azure Media Services Account Key

2. Start the application.

  • npm install
  • bower install
  • node bin/www

Notes:

This sample doesn't implement a layer of access control or user session.

The maximum size of upload file is set to 100 MBytes. The download locator is set to expire after 43200 minutes (30 days).

References:

media-services-node-vod's People

Contributors

microsoftopensource avatar msftgits avatar vaanpan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.