Skip to content

Commit

Permalink
Merge pull request #13 from Azure-Samples/xpouyat-nov2020
Browse files Browse the repository at this point in the history
Package update, migration to Functions v3 and .Net Core.
  • Loading branch information
xpouyat committed Nov 18, 2020
2 parents 5d0dae0 + 3ae8ef7 commit f8785b2
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 65 deletions.
10 changes: 5 additions & 5 deletions Encoding/Encoding/Encoding.csproj
Expand Up @@ -20,11 +20,11 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.7" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.12.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.8" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
6 changes: 0 additions & 6 deletions Encoding/Encoding/VodFunctions/ffmpeg-encoding.cs
Expand Up @@ -17,20 +17,14 @@
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Encoding.Helpers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Management.Media;
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
Expand Down
7 changes: 7 additions & 0 deletions Encoding/Encoding/local.settings.json
@@ -0,0 +1,7 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
15 changes: 10 additions & 5 deletions Encoding/README.md
Expand Up @@ -5,24 +5,29 @@ author: xpouyat
---

# Ffmpeg encoding with an Azure function
This Visual Studio 2017 Solution exposes an Azure Function that encodes an Azure Storage blob with ffmpeg. [Azure Functions Premium plan](https://docs.microsoft.com/en-us/azure/azure-functions/functions-premium-plan

This Visual Studio 2019 Solution exposes an Azure Function that encodes an Azure Storage blob with ffmpeg. [Azure Functions Premium plan](https://docs.microsoft.com/en-us/azure/azure-functions/functions-premium-plan
) is recommended.

This Functions code is based on Azure Functions v2.
This Functions code is based on Azure Functions v3.

## Fork and download a copy

### Fork and download a copy
If not already done : fork the repo, download a local copy.

### Ffmpeg
## Ffmpeg

Download ffmpeg from the Internet and copy ffmpeg.exe in \Encoding\Encoding\ffmpeg folder.
In Visual Studio, open the file properties, "Build action" should be "Content", with "Copy to Output Direcotry" set to "Copy if newer".

### Publish the function to Azure
## Publish the function to Azure

Open the solution with Visual Studio and publish the functions to Azure.
It is recommended to use a **premium plan** to avoid functions timeout (Premium gives you 30 min and a more powerfull host).
It is possible to [unbound run duration](https://docs.microsoft.com/en-us/azure/azure-functions/functions-premium-plan#longer-run-duration).

JSON input body of the function :

```json
{
"sasInputUrl":"https://mysasurlofthesourceblob",
Expand Down
Expand Up @@ -39,7 +39,7 @@ internal partial class GenerateInfoHelpers
{
LiveEventName = liveEvent.Name,
ResourceState = liveEvent.ResourceState.ToString(),
VanityUrl = liveEvent.VanityUrl,
VanityUrl = liveEvent.UseStaticHostname,
Input = liveEvent.Input.Endpoints
.Select(endPoint => new UrlEntry { Protocol = endPoint.Protocol, Url = endPoint.Url }).ToList(),
InputACL = liveEvent.Input.AccessControl?.Ip.Allow
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<Version>1.0.0</Version>
</PropertyGroup>
Expand All @@ -16,13 +16,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.10.1" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="2.0.4" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.12.0" />
<PackageReference Include="Microsoft.Azure.Management.Media" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.8" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.6" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
Expand Up @@ -377,7 +377,7 @@ public static class CreateChannel
name: liveEventName,
location: config.Region,
description: "",
vanityUrl: eventInfoFromCosmos.VanityUrl,
useStaticHostname: eventInfoFromCosmos.VanityUrl,
encoding: new LiveEventEncoding { EncodingType = LiveEventEncodingType.None },
input: liveEventInput,
preview: liveEventPreview,
Expand Down
9 changes: 9 additions & 0 deletions LiveAndVodDRMOperationsV3/LiveAndVodDRMOperationsV3/host.json
@@ -1,2 +1,11 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
@@ -0,0 +1,38 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"AadClientId": "value",
"AadEndpoint": "https://login.microsoftonline.com",
"AadSecret": "value",
"AadTenantId": "value",
"AccountName": "value",
"ArmAadAudience": "https://management.core.windows.net/",
"ArmEndpoint": "https://management.azure.com/",
"Region": "value",
"AzureRegion": "euwe",
"ResourceGroup": "value",
"ResourceGroupFinalName": "true",
"SubscriptionId": "value",
"IrdetoUserName": "value",
"IrdetoPassword": "value",
"IrdetoAccountId": "value",
"IrdetoSoapService": "https://test.ott.irdeto.com/LiveDRMService/livedrmservice.asmx",
"IrdetoPlayReadyLAURL": "https://test.ott.irdeto.com/licenseServer/playready/v1/customer/license?contentId={AlternativeMediaId}",
"IrdetoWidevineLAURL": "https://test.ott.irdeto.com/licenseServer/widevine/v1/customer/license?contentId={AlternativeMediaId}",
"IrdetoFairPlayLAURL": "skd://test.ott.irdeto.com/licenseServer/streaming/v1/customer/getckc?contentId={AlternativeMediaId}&keyId={ContentKeyId}",
"IrdetoFairPlayCertificateUrl": "https://test.ott.irdeto.com/licenseServer/streaming/v1/customer/getcertificate?applicationId=stage",
"LiveIngestAccessToken": "value",
"CosmosDBAccountEndpoint": "value",
"CosmosDBAccountKey": "value",
"CosmosDB": "liveDRMStreaming",
"CosmosCollectionSettings": "liveEventSettings",
"CosmosCollectionOutputs": "liveEventOutputInfo",
"CosmosCollectionVODAssets": "vodAssets",
"CosmosCollectionStreamingPolicies": "streamingPolicies",
"CosmosCollectionVODResources": "vodResources",
"AllowClearStream": "true"
}
}
21 changes: 13 additions & 8 deletions LiveAndVodDRMOperationsV3/README.md
Expand Up @@ -5,11 +5,13 @@ author: xpouyat
---

# Media Services v3 Dynamic Encryption with Irdeto license delivery service (Live and VOD)
This Visual Studio 2017 Solution exposes several Azure functions that can be used to manage live streaming and VOD with DRM, using Irdeto back-end to deliver the licenses. The functions communicate with Irdeto backend using SOAP. Optionaly, a Cosmos database can be used to store the result of the functions, and to specify the settings of the live event(s) to be created : ArchiveWindow, baseStorageName, ACLs, autostart, Vanity URL mode.

This Visual Studio 2019 Solution exposes several Azure functions that can be used to manage live streaming and VOD with DRM, using Irdeto back-end to deliver the licenses. The functions communicate with Irdeto backend using SOAP. Optionaly, a Cosmos database can be used to store the result of the functions, and to specify the settings of the live event(s) to be created : ArchiveWindow, baseStorageName, ACLs, autostart, Vanity URL mode.

Here are the list of functions available:

Live

- check-all-live-event-output
- create-clear-streaming-locator
- create-live-event-output
Expand All @@ -23,6 +25,7 @@ Live
- update-settings

VOD

- check-blob-copy-to-asset-status
- create-empty-asset
- create-vtt-to-asset
Expand All @@ -38,14 +41,15 @@ VOD
As an option, two AMS accounts and two Azure functions deployments can be created in two different Azure regions. An Azure function deployment could manage either AMS account. For this to work, it is needed that the AMS account names ended with 2 or 4 letters which defines the region (euwe/euno OR we/no). Resource group names could have the same convention name, or a single resource group name can be used (in that case, use ResourceGroupFinalName proporty set to a non empty string).

For Live, it is also possible to execute all operations in two regions at the same time. For example, the creation of a live event can be executed by the function into two different accounts simultaneously. In that case, the same live event name, ingest path, output locator name, output locator GUID, streaming policy name and DRM keys will be used ; all URLS will be similar (except the hostname, of course). To use this mode, pass the two regions to the create-live-event-output function. Example :

```json
{
"liveEventName": "Channel1",
"azureRegion" : "euwe,euno"
}
```

This Media Services Functions code is based on AMS REST API v3 using Azure Functions v2.
This Media Services Functions code is based on AMS REST API v3 using Azure Functions v3.

Overall architecture :

Expand All @@ -55,22 +59,22 @@ Overall architecture :

### 1. Create an Azure Media Services account

Create a Media Services account in your subscription if don't have it already ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-portal-create-account)).
Create a Media Services account in your subscription if don't have it already ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/latest/create-account-howto?tabs=portal)).

### 2. Create a Service Principal

Create a Service Principal and save the password. It will be needed in step #4. To do so, go to the API tab in the account ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/media-services-portal-get-started-with-aad#service-principal-authentication)).
Create a Service Principal and save the password. It will be needed in step #4. To do so, go to the API tab in the account ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/latest/access-api-howto?tabs=portal)).

### 3. Make sure the AMS streaming endpoint is started

To enable streaming, go to the Azure portal, select the Azure Media Services account which has been created, and start the default streaming endpoint ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-portal-vod-get-started#start-the-streaming-endpoint)).
To enable streaming, go to the Azure portal, select the Azure Media Services account which has been created, and start the default streaming endpoint.

### 4. Deploy the Azure functions

If not already done : fork the repo, download a local copy. Open the solution with Visual Studio and publish the functions to Azure.
It is recommended to use a **dedicated plan** to avoid functions timeout.
The redirector function (with anonymous access), if used, should be deployed on a separate plan as a **consumption plan** to get better scalability if this function is called by end-users.


These functions have been designed to work with Irdeto back-end. It requires credentials and urls to be set in application settings. If you run the functions locally, you need to specify the values in the local settings file.

local.settings.json will look like (please replace 'value' with the correct data):
Expand All @@ -80,6 +84,7 @@ local.settings.json will look like (please replace 'value' with the correct data
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"AadClientId": "value",
"AadEndpoint": "https://login.microsoftonline.com",
Expand Down Expand Up @@ -109,7 +114,6 @@ local.settings.json will look like (please replace 'value' with the correct data
"CosmosCollectionOutputs": "liveEventOutputInfo", // optional but needed for storing the output to Cosmos
"CosmosCollectionVODAssets": "vodAssets", // optional but needed for storing the asset info to Cosmos
"CosmosCollectionStreamingPolicies": "streamingPolicies", // optional but needed for storing the streaming policy to Cosmos
"CosmosCollectionVODAssets": "vodAssets",
"CosmosCollectionVODResources": "vodResources",
"AllowClearStream" : "true" // optional, use only by redirector
}
Expand All @@ -121,6 +125,7 @@ This database is used to read the settings when creating a live event. It is als
Database and collections are automatically created by the code if Cosmos fields are set in app settings. Collections use a partition key named "/partitionKey" and value is always "live".

Example of settings in Cosmos for a live event :

```json
{
"liveEventName": "TESTLIVEEVENT",
Expand Down Expand Up @@ -149,6 +154,7 @@ Example of settings in Cosmos for a live event :
```

Example of information in Cosmos for a live event :

```json
{
"liveEventName": "CH1",
Expand Down Expand Up @@ -277,4 +283,3 @@ Example of information in Cosmos for a live event :
]
}
```

11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -11,25 +11,26 @@ description: "Projects that show how to integrate Azure Media Services with Azur
azureDeploy: https://raw.githubusercontent.com/Azure-Samples/media-services-v3-dotnet-core-functions-integration/master/azuredeploy.json
---

# Azure Media Services v3 - Serverless Workflows with Azure Functions & Logic Apps
# Azure Media Services v3 - Serverless Workflows with Azure Functions & Logic Apps

This repository contains projects that show how to integrate Azure Media Services with Azure Functions & Azure Logic Apps.
These Media Services Functions examples are based on AMS REST API v3 on Azure Functions v2. Most of the functions can also be used from Logic Apps.
These Media Services Functions examples are based on AMS REST API v3 on Azure Functions v3. Most of the functions can also be used from Logic Apps.

This repository can be accessed directly using https://aka.ms/ams3functions.

## Prerequisites for a sample Logic Apps deployments

### 1. Create an Azure Media Services account

Create a Media Services account in your subscription if don't have it already ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-portal-create-account)).
Create a Media Services account in your subscription if don't have it already ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/latest/create-account-howto?tabs=portal)).

### 2. Create a Service Principal

Create a Service Principal and save the password. It will be needed in step #4. To do so, go to the API tab in the account ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/media-services-portal-get-started-with-aad#service-principal-authentication)).
Create a Service Principal and save the password. It will be needed in step #4. To do so, go to the API tab in the account ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/latest/access-api-howto?tabs=portal)).

### 3. Make sure the AMS streaming endpoint is started

To enable streaming, go to the Azure portal, select the Azure Media Services account which has been created, and start the default streaming endpoint ([follow this article](https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-portal-vod-get-started#start-the-streaming-endpoint)).
To enable streaming, go to the Azure portal, select the Azure Media Services account which has been created, and start the default streaming endpoint.

### 4. Deploy the Azure functions

Expand Down
Expand Up @@ -53,17 +53,11 @@
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

using Microsoft.Extensions.Logging;

using Microsoft.WindowsAzure.Storage.Blob;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using advanced_vod_functions_v3.SharedLibs;

using Microsoft.WindowsAzure.Storage.Blob;

namespace advanced_vod_functions_v3
{
Expand Down
Expand Up @@ -42,25 +42,17 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using Microsoft.Azure.Management.Media;
using Microsoft.Azure.Management.Media.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

using Microsoft.Extensions.Logging;

using Microsoft.WindowsAzure.Storage.Blob;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using advanced_vod_functions_v3.SharedLibs;

using Microsoft.WindowsAzure.Storage.Blob;

namespace advanced_vod_functions
{
Expand Down

0 comments on commit f8785b2

Please sign in to comment.