Skip to content

MichaelHochriegl/MediaLens

Repository files navigation

MediaLens

.NET NuGet License CI

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

Features

  • async InspectAsync API
  • strongly typed metadata models
  • dependency injection support
  • native MediaInfo integration

Installation

dotnet add package MediaLens

If you want DI support:

dotnet add package MediaLens.DependencyInjection

Quick start

using 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}");
}

Dependency injection

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);

Returned metadata

InspectAsync() returns a MediaInfo object with:

  • general file metadata
  • video track metadata
  • audio track metadata
  • text/subtitle track metadata

Error handling

Common exceptions include:

  • MediaLensException
  • MediaLensOpenException
  • MediaLensHandleException
  • MediaLensNativeDependencyException

Example

A minimal example is available under examples/.

License

  • Repository code: MIT (LICENSE)
  • MediaInfoLib: BSD-2-Clause (LICENSE.MediaInfo)

MediaInfo is used through the bundled native binaries from MediaLens.Native.

About

A managed dotnet wrapper around MediaLens.Native, which internally provides the OS-specific versions of MediaInfo.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.MediaInfo

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages