FFmpegDotNet 9.9.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package FFmpegDotNet --version 9.9.0.2
                    
NuGet\Install-Package FFmpegDotNet -Version 9.9.0.2
                    
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="FFmpegDotNet" Version="9.9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FFmpegDotNet" Version="9.9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="FFmpegDotNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FFmpegDotNet --version 9.9.0.2
                    
#r "nuget: FFmpegDotNet, 9.9.0.2"
                    
#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.
#:package FFmpegDotNet@9.9.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FFmpegDotNet&version=9.9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=FFmpegDotNet&version=9.9.0.2
                    
Install as a Cake Tool

FFmpeg (.NET Wrapper)

NuGet License

A .NET wrapper library for FFmpeg, built on top of FFmpeg.AutoGen. It provides a managed, object-oriented interface to FFmpeg's C API, making it easier and safer to use FFmpeg from .NET applications, without giving up direct access to the underlying API when you need it.

📚 API Documentation 🧪 Sample Projects


Table of Contents


Overview

FFmpeg is a powerful open-source multimedia framework for handling video, audio, and streams. FFmpeg.AutoGen exposes FFmpeg's native C API to .NET, but using it directly means working with raw pointers and unsafe memory operations.

FFmpeg (.NET Wrapper) builds a high-level, managed abstraction on top of FFmpeg.AutoGen, so you can access FFmpeg's encoding, decoding, transcoding, and streaming capabilities safely from C#, with automatic resource cleanup and idiomatic .NET types.


Getting Started

Prerequisites

Supported FFmpeg Versions

FFmpeg 9.0+ ("Lei")

Library Version
avcodec 63
avdevice 63
avfilter 12
avformat 63
avutil 61
swresample 7
swscale 10

Installation

Install the wrapper from NuGet:

dotnet add package FFmpegDotNet

If you don't already have FFmpeg installed on your system, the NuGet FFmpegDotNet.bin.winx64 package bundles the LGPL FFmpeg binaries for Windows x64:

dotnet add package FFmpegDotNet.bin.winx64

Loading FFmpeg Libraries

The FFmpeg namespace includes a static helper class, FFmpegLoader, responsible for locating and initializing the native FFmpeg libraries before use. If Initialize() is not called manually, the library automatically attempts to locate the FFmpeg binaries using the default search order below.

Default search order:

  1. Current directory (./)
  2. ./ffmpeg/
  3. Platform-specific subdirectories (e.g. ./ffmpeg/win-x64, ./ffmpeg/linux-arm64)
  4. The system PATH environment variable

If no suitable library is found, initialization fails and FFmpeg functions become unavailable. You can also point Initialize() at a specific directory if your binaries live somewhere non-standard:

FFmpegLoader.Initialize(@"C:\tools\ffmpeg\bin");

Quick Start

A minimal example using the high-level API to remux a file (copy streams into a new container without re-encoding):

using FFmpeg;
using FFmpeg.Formats;
using FFmpeg.Utils;

FFmpegLoader.Initialize();

using MediaSource src = MediaSource.Open("input.mp4");
using MediaSink dst = MediaSink.Create("output.mkv")!;

// Copy all streams as-is (no decoding/encoding involved).
foreach (var stream in src.Streams)
    dst.AddStream(stream);

using AVPacket packet = AVPacket.Allocate();
AVResult32 result;
while (!(result = src.ReadPacket(packet)).IsError)
{
    dst.WritePacket(packet).ThrowIfError();
}
if (result != AVResult32.EndOfFile)
    result.ThrowIfError();

dst.WriteTrailer().ThrowIfError();

Note: Real transcoding — decoding, re-encoding with a specific codec, and optionally running frames through a FilterGraph — is significantly more involved than a stream copy, since you're responsible for driving the decode/filter/encode loop yourself (see the Filters example for a full walkthrough using CodecContext, FilterGraph, and MediaSink). If you just need a straightforward file-to-file transcode with no custom filtering or frame-level access, it's often simpler and more robust to shell out to ffmpeg.exe directly (e.g. via System.Diagnostics.Process) and reserve MediaSource/MediaSink for scenarios where you need in-process control.

For finer control over decoding, filtering, or encoding, see the high-level abstractions below or browse the example projects.


Important Classes

The FFmpeg namespace provides managed wrapper classes around FFmpeg's core C structs and APIs. These classes simplify interacting with FFmpeg by handling resource management, initialization, and data conversion automatically.

Core Low-Level Wrappers

These classes map directly to FFmpeg's internal structures and are typically used when building advanced or custom media pipelines.

Class Description
FFmpeg.Formats.FormatContext Wraps AVFormatContext. Handles input/output container formats, stream information, and demuxing/muxing.
FFmpeg.Codecs.CodecContext Wraps AVCodecContext. Manages codecs for encoding and decoding audio/video streams.
FFmpeg.Utils.AVPacket Wraps AVPacket. Represents encoded data (compressed frames or packets).
FFmpeg.Utils.AVFrame Wraps AVFrame. Represents decoded, uncompressed media frames in memory.
FFmpeg.Filters.FilterGraph Wraps AVFilterGraph. Provides access to FFmpeg's filter system (resizing, color correction, etc.).
FFmpeg.Images.SwsContext Wraps SwsContext. Handles image scaling and pixel format conversion via libswscale.
FFmpeg.Audio.SwrContext Wraps SwrContext. Handles audio resampling, format conversion, and channel layout adjustments via libswresample.

Note: These classes closely follow FFmpeg's internal lifecycle patterns and implement IDisposable. Always dispose them (or wrap them in a using statement) when no longer needed to avoid leaking native resources.

High-Level Abstractions

If your goal is simply to read, decode, encode, or transcode media, use these instead of managing FormatContext and CodecContext directly.

Class Description
MediaSource Simplifies reading and decoding frames from a file or stream. Handles demuxing and decoding internally.
MediaSink Simplifies encoding and writing frames to a file or stream. Handles muxing and encoding internally.
Transcoder Reads from one source and writes to another, performing full media transcoding in a few lines of code. For simple file-to-file transcodes, consider calling ffmpeg.exe directly instead — see the note in Quick Start.

These abstractions are ideal for typical scenarios such as:

  • Extracting frames from a video
  • Re-encoding media to a different format
  • Streaming or piping decoded frames to other components

Examples

Complete sample applications are available in the FFmpeg.Examples repository, ranging from low-level API usage to the higher-level abstractions provided by FFmpegDotNet. Each project is intentionally small and focused, demonstrating a single feature or workflow:

  • Opening media files with DemuxerContext
  • Decoding audio and video streams
  • Reading and writing media containers
  • Audio resampling with SwrContext
  • Image scaling and pixel format conversion with SwsContext
  • Using MediaSource for simplified decoding
  • Encoding
  • Filters
  • A simple video player

Contributing

Contributions, bug reports, and feature requests are welcome. Please open an issue or pull request on GitHub.

License

This project is licensed under the LGPL-2.1 License. FFmpeg itself is licensed separately under the LGPL/GPL — see the FFmpeg legal page for details on which license applies to your build.

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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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 (1)

Showing the top 1 NuGet packages that depend on FFmpegDotNet:

Package Downloads
FFmpegDotNet.Skia

Provides SkiaSharp integration for the FFmpeg .NET wrapper (FFmpegDotNet). Converts FFmpeg AVFrames to SKImage or SKBitmap and back, with crop, color space (YUV matrix, range, HDR) and alpha handling, and includes high-level classes (FFCodec2Skia, SKVideo, SKAnimatedImage) for decoding and rendering videos and animated images with Skia. The package version starts with the FFmpeg major version: 8.x for FFmpegDotNet 8 (FFmpeg 8.1), 9.x for FFmpegDotNet 9 (FFmpeg 9.0).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.9.4 153 11/19/2026
9.9.3.1 92 11/19/2026
9.9.3 89 11/19/2026
9.9.2 87 11/19/2026
9.9.1 89 11/19/2026
9.9.0.2 92 11/18/2026
9.9.0.1 234 9/3/2026
9.9.0 145 9/2/2026
8.1.2.15 135 11/19/2026
8.1.2.14 86 11/18/2026
8.1.2.13 153 9/2/2026
8.1.2.12 138 9/1/2026
8.1.2.11 199 8/16/2026
8.1.2.10 134 8/16/2026
8.1.2.9 143 8/15/2026
8.1.2.8 176 8/14/2026
8.1.2.6 163 7/30/2026
8.1.2.5 144 7/28/2026
8.1.2.4 148 7/26/2026
8.1.2.3 154 7/25/2026
Loading failed

FFmpeg 9.0.1 - "Lei"
Version numbering scheme changed: FFMpegMajor.Major.Minor.Patch

--- 9.9.0.2 ---
Many BugFixes found in a code review (also released for FFmpeg 8 as 8.1.2.14):
IO: custom IOContext callbacks are rooted and no longer let exceptions escape into native code; IOContext/CodecContext can be finalized; use-after-free when opening custom IO failed; IOStreamContext no longer throws on construction; seeking works for seekable IOContexts.
Formats/Codecs: MuxerContext double dispose, NoFile check and time base rescaling; FormatContext.Seekable returns None without an I/O context again; extradata is padded as FFmpeg requires; SendFrame no longer changes an open encoder's time base; encoded subtitle packets use a correct time base; MediaSource keeps its decoders, drains all of them at end of file and SeekExactly ends only for the requested stream; seeks past ~35 minutes and timestamp setters past ~6.6 hours no longer overflow.
Utils: Rational +, - and int * Rational overflow; TimeSpan / Rational saturated; AVPacket leak and Size overrun; AVFrame.GetData/Copy/Size/Clone for bottom-up and audio frames; AVBuffer.ReplaceWith use-after-free; Move/Clone/Reference onto itself emptied the packet; AVResult64.ToString named wrong errors.
Audio: AudioFifo layout conversion and peeks beyond one chunk, pinning of channel spans; SwrContext wrote past the buffer when converting at an offset; AudioBuffer Copy/MakeWriteable shared data through stale plane pointers, planar-to-packed copies were wrong; AudioClock counted time twice after Pause; ChannelLayout.Init kept a freed map after a failure.
Collections: CircularArray.IndexOf/Clear, AVChapter removal keeps its order, SubtitleRect text setters crashed, hardware device/frames context references crashed when empty.
Options: binary options were read from the wrong address; bool in SetOption(name, object); dictionary overloads use av_opt_set_dict2 and remove the entries that were set.
MediaPlayer: VideoBuffer/AudioBuffer lost writes and CanSeek was reversed, AudioBuffer binary search could loop forever, SetBufferSize estimate, Stop state.
Misc: SVTAV1.CreateAvif encoded the wrong frame; Transcoder decoded a packet twice; Logger kept no prefix state across av_log calls; FormatContext.Url is read as UTF-8; SwsContext throws if it cannot be created.
Behaviour changes:
TryGetOption(Option, out object): Color options are returned as string ("0xRRGGBBAA"), Duration as long (microseconds), array options as the string FFmpeg produces.
SetOption(name, IDictionary) applies every entry as its own option (av_opt_set_dict2); `name` is not used.
AudioBuffer.CopyTo/CopyToPacked throw ArgumentOutOfRangeException for a start index outside the buffer. SetBufferSize throws for a non-positive size or when no data rate can be determined.
ChannelLayout custom channel names must be shorter than 16 bytes (UTF-8).
PlaybackEngine: a decoding error now moves the player to Faulted and raises Faulted, it was only logged before.

--- 9.9.0.1 ---
BugFix: - Fixed a bug concerning the incorrect size of CLong/CULong on Windows or 32bit and netstandard.
See AutoGen (v9.0.1.1) release notes for more details.