xFFmpeg.NET
7.4.0
dotnet add package xFFmpeg.NET --version 7.4.0
NuGet\Install-Package xFFmpeg.NET -Version 7.4.0
<PackageReference Include="xFFmpeg.NET" Version="7.4.0" />
<PackageVersion Include="xFFmpeg.NET" Version="7.4.0" />
<PackageReference Include="xFFmpeg.NET" />
paket add xFFmpeg.NET --version 7.4.0
#r "nuget: xFFmpeg.NET, 7.4.0"
#:package xFFmpeg.NET@7.4.0
#addin nuget:?package=xFFmpeg.NET&version=7.4.0
#tool nuget:?package=xFFmpeg.NET&version=7.4.0
<img src="lib/ffmpeg/v4/icon.png" alt="drawing" width="24" height="24" /> FFmpeg.NET
FFmpeg.NET provides a straightforward interface for handling media data, making tasks such as converting, slicing and editing both audio and video completely effortless.
Under the hood, FFmpeg.NET is a .NET wrapper for FFmpeg; a free (LGPLv2.1) multimedia framework containing multiple audio and video codecs, supporting muxing, demuxing and transcoding tasks on many media formats.
The library targets netstandard2.1, is fully async, thread-safe, and works cross-platform (Windows, Linux, macOS).
Packages
| Package | NuGet |
|---|---|
| xFFmpeg.NET |
Contents
Features
- Transcode audio & video into other formats using parameters such as:
Bit rateFrame rateResolution(predefined sizes or custom width/height)Aspect ratioSeek positionDurationSample rateMedia formatCodec presets & profiles(ultrafast to veryslow, baseline to high444)Pixel format
- Resolving metadata (duration, codecs, resolution, bitrate, fps)
- Generating thumbnails from videos
- Hardware-accelerated encoding/decoding (CUDA, QSV, DXVA2, D3D11VA)
- Stream and pipe-based I/O (no intermediate files required)
- Video cropping, speed control, and audio removal
- Custom FFmpeg command line arguments via
ExecuteAsync - Full
CancellationTokensupport on all async operations - Progress, error, completion, and raw data events
- Playlist generation (M3U, XSPF)
- Convert media to physical formats and standards such as:
- Standards include:
FILM,PAL&NTSC - Mediums include:
DVD,DV,DV50,VCD&SVCD
- Standards include:
Get started
You need to provide the FFmpeg executable path to the Engine constructor, or ensure ffmpeg is available in your system PATH.
dotnet add package xFFmpeg.NET
Or via the Package Manager Console:
PM> Install-Package xFFmpeg.NET
Samples
- Grab thumbnail from a video
- Retrieve metadata
- Basic conversion
- H.264 encoding with presets and profiles
- Extract audio from video
- Hardware-accelerated conversion
- Cut / split video
- Crop video
- Change video speed
- Convert using streams
- Custom FFmpeg arguments
- CancellationToken support
- Subscribe to events
Grab thumbnail from a video
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("thumbnail.jpg");
var ffmpeg = new Engine("/usr/bin/ffmpeg");
// Saves the frame located on the 15th second of the video.
var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(15) };
await ffmpeg.GetThumbnailAsync(inputFile, outputFile, options, CancellationToken.None);
Retrieve metadata
var inputFile = new InputFile("video.mp4");
var ffmpeg = new Engine("/usr/bin/ffmpeg");
var metadata = await ffmpeg.GetMetaDataAsync(inputFile, CancellationToken.None);
Console.WriteLine($"Duration: {metadata.Duration}");
Console.WriteLine($"Video: {metadata.VideoData?.Format} {metadata.VideoData?.FrameSize} @ {metadata.VideoData?.Fps} fps");
Console.WriteLine($"Audio: {metadata.AudioData?.Format} {metadata.AudioData?.SampleRate} {metadata.AudioData?.ChannelOutput}");
Basic conversion
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video.mkv");
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, CancellationToken.None);
H.264 encoding with presets and profiles
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video_h264.mp4");
var options = new ConversionOptions
{
VideoCodec = VideoCodec.libx264,
VideoCodecPreset = VideoCodecPreset.fast,
VideoCodecProfile = VideoCodecProfile.main,
VideoBitRate = 4000,
VideoFps = 30,
VideoSize = VideoSize.Hd1080,
VideoAspectRatio = VideoAspectRatio.R16_9,
AudioSampleRate = AudioSampleRate.Hz48000,
AudioBitRate = 192,
ExtraArguments = "-movflags +faststart"
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Extract audio from video
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("audio.mp3");
var options = new ConversionOptions
{
AudioBitRate = 320,
AudioSampleRate = AudioSampleRate.Hz44100
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Hardware-accelerated conversion
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video_gpu.mp4");
// NVIDIA CUDA acceleration
var options = new ConversionOptions
{
HWAccel = HWAccel.cuda,
VideoCodec = VideoCodec.h264_nvenc,
VideoBitRate = 5000,
VideoSize = VideoSize.Hd1080
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Cut video down to smaller length
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("clip.mp4");
var options = new ConversionOptions();
// Creates a 25 second clip, starting from the 30th second of the original video.
options.CutMedia(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(25));
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Crop video
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video_cropped.mp4");
var options = new ConversionOptions
{
SourceCrop = new CropRectangle { X = 100, Y = 50, Width = 1280, Height = 720 }
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Change video speed
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video_fast.mp4");
var options = new ConversionOptions
{
// 0.5 = 2x speed, 2.0 = half speed
VideoTimeScale = 0.5
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
await ffmpeg.ConvertAsync(inputFile, outputFile, options, CancellationToken.None);
Convert using streams
// Convert to a MemoryStream (no output file needed)
var inputFile = new InputFile("video.mp4");
var options = new ConversionOptions
{
VideoCodec = VideoCodec.libx264,
VideoSize = VideoSize.Hd720
};
var ffmpeg = new Engine("/usr/bin/ffmpeg");
using var outputStream = await ffmpeg.ConvertAsync(inputFile, options, CancellationToken.None);
// Or pipe a .NET Stream into FFmpeg as input
await using var fileStream = File.OpenRead("video.mp4");
await using var streamInput = new StreamInput(fileStream);
var output = new OutputFile("converted.mkv");
await ffmpeg.ConvertAsync(streamInput, output, CancellationToken.None);
Custom FFmpeg arguments
var ffmpeg = new Engine("/usr/bin/ffmpeg");
// Run any FFmpeg command directly
await ffmpeg.ExecuteAsync("-i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3", CancellationToken.None);
// With a working directory
await ffmpeg.ExecuteAsync("-i input.mp4 -c copy output.mkv", "/path/to/media", CancellationToken.None);
CancellationToken support
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video.mkv");
var ffmpeg = new Engine("/usr/bin/ffmpeg");
try
{
await ffmpeg.ConvertAsync(inputFile, outputFile, cts.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine("Conversion was cancelled or timed out.");
}
Subscribe to events
public async Task StartConverting()
{
var inputFile = new InputFile("video.mp4");
var outputFile = new OutputFile("video.mkv");
var ffmpeg = new Engine("/usr/bin/ffmpeg");
ffmpeg.Progress += OnProgress;
ffmpeg.Data += OnData;
ffmpeg.Error += OnError;
ffmpeg.Complete += OnComplete;
await ffmpeg.ConvertAsync(inputFile, outputFile, CancellationToken.None);
}
private void OnProgress(object sender, ConversionProgressEventArgs e)
{
Console.WriteLine("[{0} => {1}]", e.Input.Name, e.Output.Name);
Console.WriteLine("Bitrate: {0}", e.Bitrate);
Console.WriteLine("Fps: {0}", e.Fps);
Console.WriteLine("Frame: {0}", e.Frame);
Console.WriteLine("ProcessedDuration: {0}", e.ProcessedDuration);
Console.WriteLine("Size: {0} kb", e.SizeKb);
Console.WriteLine("TotalDuration: {0}\n", e.TotalDuration);
}
private void OnData(object sender, ConversionDataEventArgs e)
{
Console.WriteLine("[{0} => {1}]: {2}", e.Input.Name, e.Output.Name, e.Data);
}
private void OnComplete(object sender, ConversionCompleteEventArgs e)
{
Console.WriteLine("Completed conversion from {0} to {1} (ffmpeg {2})", e.Input.Name, e.Output.Name, e.FFmpegVersion);
}
private void OnError(object sender, ConversionErrorEventArgs e)
{
Console.WriteLine("[{0} => {1}]: Error: {2} (ffmpeg {3})\n{4}", e.Input.Name, e.Output.Name, e.Exception.ExitCode, e.FFmpegVersion, e.Exception.InnerException);
}
Licensing
- FFmpeg.NET is licensed under the MIT license
- FFmpeg.NET uses FFmpeg, a multimedia framework which is licensed under the LGPLv2.1 license
- Originally based on MediaToolkit (license), substantially refactored and ported to netstandard2.1
| Product | Versions 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. net9.0 was computed. 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 was computed. 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 | 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 is compatible. |
| .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. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on xFFmpeg.NET:
| Package | Downloads |
|---|---|
|
CandyKingdom.Marcy
Package Description |
|
|
IntralismManiaConverter
A tool that can convert mania maps to intralist and intralism maps to mania. |
|
|
Kingsmartech.Smop.Com
Package Description |
|
|
Aspose.MeetingNotes
SDK for converting meeting audio into structured text notes and actionable tasks |
|
|
ModelingEvolution.VideoStreaming
Package Description |
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on xFFmpeg.NET:
| Repository | Stars |
|---|---|
|
yangzhongke/NETBookMaterials
|
|
|
bartekmotyl/simple-video-cutter
Windows-based tool for efficient browsing and cutting video footage
|
|
|
onionware-github/OnionMedia
Open-Source Mediaconverter and -downloader
|
|
|
CnGal/CnGalWebSite
CnGal是一个非营利性的,立志于收集整理国内制作组创作的中文Galgame/AVG的介绍、攻略、评测、感想等内容的资料性质的网站。
|
| Version | Downloads | Last Updated |
|---|---|---|
| 7.4.0 | 354 | 3/28/2026 |
| 7.3.0 | 121 | 3/26/2026 |
| 7.2.0 | 114,429 | 10/26/2023 |
| 7.1.3 | 87,727 | 4/3/2022 |
| 7.1.2 | 1,265 | 4/3/2022 |
| 7.0.1 | 7,308 | 11/27/2021 |
| 6.0.0 | 27,354 | 6/27/2021 |
| 5.0.2 | 11,409 | 6/27/2021 |
| 5.0.1 | 5,635 | 3/12/2021 |
| 5.0.0 | 1,609 | 3/12/2021 |
| 3.4.0 | 94,300 | 11/15/2019 |
| 3.3.3 | 21,023 | 5/1/2019 |
| 3.3.2 | 1,463 | 4/30/2019 |
| 3.3.1 | 1,478 | 4/28/2019 |
| 3.3.0 | 1,582 | 4/26/2019 |
| 3.2.0 | 1,449 | 4/26/2019 |
| 3.1.0 | 20,263 | 11/20/2018 |
| 3.0.0 | 1,716 | 11/20/2018 |
| 2.1.0 | 1,833 | 11/19/2018 |