Giter Club home page Giter Club logo

functions-dotnet-core-mediainfo's Introduction

page_type languages products description
sample
csharp
azure
azure-functions
Using MediaInfo to analyze files in Azure Storage

Reading metadata from videos with MediaInfo library and Azure Functions

It is common in the media space to want to determine the characteristics of a media file. In a local environment, a commonly used tool is MediaInfoLib in the form of the executable program MediaInfo.

MediaInfo(Lib) is a convenient unified display of the most relevant technical and tag data for video and audio files.

It becomes a bit more difficult to get this metadata from files in cloud storage. This project provides both an Azure Function and a Console App, both using the cross-platform .NetCore, to retrieve a report on a file stored in Azure Blob Storage. The console app also demonstrates how to upload a provided test file.

About the Software Components

The project has two simple libraries, both of which attempt to use SOLID design principles and Clean Architecture in general. For brevity and simplicity, these are not canonical examples of either.

Software Component Diagram

Storage Interactions

The Storage.Helper library provides three services:

  1. Management: GetAccountKey
  2. Operations: BlobCopyAsync, BlobUploadAsync, GetSasUrlAsync, ContainerCreateIfNotExistsAsync, BlobExistsAsync, GetBlobContentLengthAsync
  3. Read Byte-Range Operations: DownloadHttpRangeAsync, GetOrDownloadContentAsync

It is this latter service which is used in IMediaInfoReportService, to only read those bytes required by the MediaInfo library to extract the metadata.

Authentication and Authorization

The ServiceCollectionExtensions.cs in Storage.Helper include both Azure Fluent Management and Azure TokenCredential to set up the auth for the project's services.

When deployed to Azure as a Function App, with system assigned managed identity enabled, the web-host will provide the required credentials for both IAzure and TokenCredential objects; which are injected into the service container and used in the implementations. This managed service principal must have appropriate role based access control to the storage accounts it needs to access via the code sample, and access to the media services resource.

The following are needed to access storage:

  • Storage Blob Data Contributor
  • Reader and Data Access

Run commands from a shell.azure.com instance, or a bash shell with the Azure CLI tooling, to permit the application.

Follow this detailed example on how to add these roles.

Azure Function application settings

On your deployed function app instance, set:

  • AZURE_TENANT_ID
  • AZURE_SUBSCRIPTION_ID

Create a local.settings.json file (for Azure Functions) or a appsettings.json file (for the console app) and set the above to test locally. Template files for the FunctionApp and ConsoleApp have been provided. These settings will allow the local user to log in interactively and use their identity for Azure operations, ensure they have sufficient privilege (same as the managed identity).

Quick Deployment

To quickly deploy the Sample.MediaInfo.FxnApp to Azure, hit the button below:

Deploy to Azure

You will be presented with a screen similar to the image below:

Deploy to Azure

Do the following:

  1. Create or Select a Resource Group
  2. Enter a Site Name
  3. Enter a Hosting Plan Name
  4. Hit the Review + Create button to validate & deploy the application.

Testing

FunctionApp

You can use the simple CURL scripts provided at the end of MediaInfoFunction.cs to test the local (or remote) function app.

ConsoleApp

Once the appsettings.json is created, simply run the console app to test it.
As a fall-back if UploadAndAnalyze.cs does not find a local file, it will attempt to analyze an existing file in Azure Storage.

functions-dotnet-core-mediainfo's People

Contributors

microsoftopensource avatar asanjabi avatar nickdrouin avatar drakiula avatar microsoft-github-operations[bot] avatar

Watchers

James Cloos avatar

Forkers

drakiula

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.