MediaLens is a small .NET wrapper around the native MediaInfo library. It comes with the bundled native binaries for (by using MediaLens.Native):
- Windows x64
- Linux x64
- macOS x64
- macOS arm64
- async
InspectAsyncAPI - strongly typed metadata models
- dependency injection support
- native MediaInfo integration
dotnet add package MediaLensIf you want DI support:
dotnet add package MediaLens.DependencyInjectionusing MediaLens;
var mediaLens = new MediaLens.MediaLens();
var mediaInfo = await mediaLens.InspectAsync("media.mp4");
Console.WriteLine($"File: {mediaInfo.General.FileName}");
Console.WriteLine($"Format: {mediaInfo.General.Format}");
Console.WriteLine($"Duration: {mediaInfo.General.Duration}");
foreach (var video in mediaInfo.VideoTracks)
{
Console.WriteLine($"Video: {video.Format} {video.Width}x{video.Height} {video.FrameRate}");
}
foreach (var audio in mediaInfo.AudioTracks)
{
Console.WriteLine($"Audio: {audio.Format} {audio.Channels}ch {audio.Language}");
}
foreach (var text in mediaInfo.TextTracks)
{
Console.WriteLine($"Subtitle: {text.Format} {text.Language}");
}using MediaLens.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediaLens();AddMediaLens() registers IMediaLens as a singleton by default.
You can also choose a different lifetime:
using MediaLens.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediaLens(ServiceLifetime.Scoped);InspectAsync() returns a MediaInfo object with:
- general file metadata
- video track metadata
- audio track metadata
- text/subtitle track metadata
Common exceptions include:
MediaLensExceptionMediaLensOpenExceptionMediaLensHandleExceptionMediaLensNativeDependencyException
A minimal example is available under examples/.
- Repository code: MIT (
LICENSE) - MediaInfoLib: BSD-2-Clause (
LICENSE.MediaInfo)
MediaInfo is used through the bundled native binaries from MediaLens.Native.