FFmpeg.Loader 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FFmpeg.Loader --version 2.1.0
NuGet\Install-Package FFmpeg.Loader -Version 2.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FFmpeg.Loader" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FFmpeg.Loader --version 2.1.0
#r "nuget: FFmpeg.Loader, 2.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FFmpeg.Loader as a Cake Addin
#addin nuget:?package=FFmpeg.Loader&version=2.1.0

// Install FFmpeg.Loader as a Cake Tool
#tool nuget:?package=FFmpeg.Loader&version=2.1.0

FFmpeg.Loader

GitHub license NuGet Stats Build & Publish

FFmpegLoader will find and load FFmpeg libaries with the FFmpeg.AutoGen bindings. It provides a simple and customizable way of doing this, cross-platform.

This library was designed for use with FFmpeg.Native as a more flexible alternative to FFmpeg.Native's tooling for finding FFmpeg libs. However please note, FFmpeg.Native is unnecessary if FFmpeg libraries have been installed elsewhere (it's just a convenient method of distributing the binaries with your application): just point this project's FFmpegLoader at the appropriate directory if it can't find the binaries on its own.

Features

  • Searches for appropriate FFmpeg libraries in any number of customizable locations.
  • Registers the located binaries for use with FFmpeg.AutoGen.
  • Works around a restriction on some Windows systems which prevents DLL libraries being loaded from non-default locations.

Setup

Install the FFmpeg.Loader package from NuGet.org into your project using the following dotnet CLI:

dotnet add package FFmpeg.Loader

Or using the Package Manager Console with the following command:

PM> Install-Package FFmpeg.Loader

FFmpeg libraries are not included in this package. You will need to either also include a distribution package like FFmpeg.Native, or install them externally. For example to install externally:

  • On Ubuntu or Debian: sudo apt install ffmpeg
  • On Mac OS-X: brew install ffmpeg
  • On Windows, download and extract a Windows build from the official FFmpeg site

Usage

See the code samples below for basic usage of FFmpegLoader. If the libraries cannot be located, then a DllNotFoundException is thrown.

The default paths that FFmpegLoader searches for FFmpeg libraries are the assembly's directory in your executing application, and also several specific subdirectories relative to that, dependent on the current OS and architecture. Aside from the assembly directory, the subdirectories searched match the location that FFmpeg.Native installs to, i.e.:

  • .\runtimes\win7-x64\native{name}-{version}.dll
  • .\runtimes\win7-x86\native{name}-{version}.dll
  • ./runtimes/linux-x64/native/lib{name}.so.{version}
  • ./runtimes/osx-x64/native/lib{name}.{version}.dylib
using FFmpeg.Loader;
//Search a set of default paths for FFmpeg libraries, relative to the FFmpeg.Loader assembly and then set FFmpeg.AutoGen to load the first matching FFmpeg binaries.
FFmpegLoader.SearchDefaults().Load();

//Search the system's environment PATH for FFmpeg libraries.
FFmpegLoader.SearchEnvironmentPaths().Load();

//Search a set of paths for FFmpeg libraries, and then set FFmpeg.AutoGen to load the first matching FFmpeg binaries.
FFmpegLoader.SearchPaths("/usr/lib/x86_64-linux-gnu", "/usr/bin/ffmpeg").Load();

//Calls can be chained.
FFmpegLoader
	.SearchDefaults()
	.ThenSearchEnvironmentPaths()
	.ThenSearchPaths("/usr/bin/ffmpeg")
	.Load();

//The following two examples are functionally identical and combines both of the approaches above.
//They first search a default set of paths relative to the FFmpeg.Loader assembly, and then search a list of manually specified paths.
//Finally they set FFmpeg.AutoGen to load the first matching FFmpeg binaries.
FFmpegLoader.SearchDefaults().ThenSearchPaths("/usr/lib/x86_64-linux-gnu", "/usr/bin/ffmpeg").Load();
FFmpegLoader.SearchDefaults().ThenSearchPaths("/usr/lib/x86_64-linux-gnu").ThenSearchPaths("/usr/bin/ffmpeg").Load();

//The following two examples are functionally identical and search the same paths as above, but search the manually specified paths first
//and then fall back on searching a set of default paths.
//As above, they finally set FFmpeg.AutoGen to load the first matching FFmpeg binaries.
FFmpegLoader.SearchPaths("/usr/lib/x86_64-linux-gnu", "/usr/bin/ffmpeg").ThenSearchDefaults().Load();
FFmpegLoader.SearchPaths("/usr/lib/x86_64-linux-gnu").ThenSearchPaths("/usr/bin/ffmpeg").ThenSearchDefaults().Load();

After defining the initial search paths, there are several more methods and overloads you may find useful:

//Returns an instance with additional search-locations. This method can be chained as many times as necessary.
//Additional locations are a predefined set of defaults relative to the specified rootDir parameter.
//If rootDir is null then the FFmpegLoader assembly folder is used for resolving relative paths.
FFmpegLoaderSearch ThenSearchDefaults(string rootDir = null);

//Returns an instance with additional search-locations. This method can be chained as many times as necessary.
//Values provided in searchPaths are expected to be either absolute or relative to the directory containing the FFmpegLoader assembly.
FFmpegLoaderSearch ThenSearchPaths(params string[] searchPaths);

//Returns an instance with additional search-locations. This method can be chained as many times as necessary.
//Paths are read from the specified envVar; the appropriate PATH separator for each OS is recognized and handled (":" on Linux & OSX, ";" on Windows)
FFmpegLoaderSearch ThenSearchEnvironmentPaths(string envVar = "PATH");

//Locates a specific FFmpeg library with a specific version. Returns null if no matching library is found.
IFileInfo Find(string name, int version);

//Locates a specific FFmpeg library with a version number provided by FFmpeg.AutoGen. Returns null if no matching library is found.
IFileInfo Find(string name);

//Search the defined search-locations for an FFmpeg library with a specific name and version and set FFmpeg.AutoGen to load from there.
//Throws DllNotFoundException if no matching library is found.
string Load(string name, int version);

//Search the defined search-locations for an FFmpeg library with a specific name (version provided by FFmpeg.AutoGen) and set FFmpeg.AutoGen to load from there.
//Throws DllNotFoundException if no matching library is found.
string Load(string name = "avutil");

FFmpeg versions

This library searches for specific FFmpeg library versions. If your FFmpeg DLLs have different version numbers than expected, then they won't be found. The versions it looks for are pulled from the FFmpeg.AutoGen project's ffmpeg.LibraryVersionMap[] dictionary.

At the time of writing this, FFmpeg.AutoGen 4.x currently specifies: Library |Version --- |--- avcodec |58 avdevice |58 avfilter |7 avformat |58 avutil |56 postproc |55 swresample|3 swscale |5

If any of your FFmpeg binaries are of a different version, you may need to explicitly install a newer/older version of FFmpeg.AutoGen into your project.

Attribution

This project contains some C# code that was originally based on, and modified, from the LGPL-3.0 licensed FFmpeg.Native project.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.2 1,886 8/10/2023
3.0.2-ci0007 81 8/10/2023
3.0.1 151 8/2/2023
3.0.1-ci0005 93 8/2/2023
3.0.1-ci0003 94 8/2/2023
3.0.0 13,533 7/25/2022
2.1.1 469 7/12/2022
2.1.0 415 7/12/2022
2.0.0 411 7/11/2022
1.0.1 745 5/7/2021
1.0.0 344 5/7/2021