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 Storage.Helper library provides three services:
BlobCopyAsync, BlobUploadAsync, GetSasUrlAsync, ContainerCreateIfNotExistsAsync, BlobExistsAsync, GetBlobContentLengthAsync
- Read Byte-Range Operations:
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.
Azure Function application settings
On your deployed function app instance, set:
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).
To quickly deploy the Sample.MediaInfo.FxnApp to Azure, hit the button below:
You will be presented with a screen similar to the image below:
Do the following:
- Create or Select a Resource Group
- Enter a Site Name
- Enter a Hosting Plan Name
- Hit the Review + Create button to validate & deploy the application.
You can use the simple CURL scripts provided at the end of MediaInfoFunction.cs to test the local (or remote) function app.
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.