FFMediaToolkit 4.8.1
dotnet add package FFMediaToolkit --version 4.8.1
NuGet\Install-Package FFMediaToolkit -Version 4.8.1
<PackageReference Include="FFMediaToolkit" Version="4.8.1" />
<PackageVersion Include="FFMediaToolkit" Version="4.8.1" />
<PackageReference Include="FFMediaToolkit" />
paket add FFMediaToolkit --version 4.8.1
#r "nuget: FFMediaToolkit, 4.8.1"
#:package FFMediaToolkit@4.8.1
#addin nuget:?package=FFMediaToolkit&version=4.8.1
#tool nuget:?package=FFMediaToolkit&version=4.8.1
FFMediaToolkit
FFMediaToolkit is a .NET library for creating and reading multimedia files. It uses native FFmpeg libraries by the FFmpeg.Autogen bindings.
Features
- Decoding/encoding audio-video files in many formats supported by FFmpeg.
- Extracting audio data as floating point arrays.
- Access to any video frame by timestamp.
- Creating videos from images with metadata, pixel format, bitrate, CRF, FPS, GoP, dimensions and other codec settings.
- Supports reading multimedia chapters and metadata.
Code samples
Extract all video frames as PNG files
// Open video file using var file = MediaFile.Open(@"D:\example\movie.mp4", new MediaOptions() { VideoPixelFormat = ImagePixelFormat.Rgba32 }); // Get pixel buffer from SkiaSharp bitmap using var bitmap = new SKBitmap(file.Video.Info.FrameSize.Width, file.Video.Info.FrameSize.Height, SKColorType.Rgba8888, SKAlphaType.Unpremul); var pixelBuffer = bitmap.GetPixelSpan(); int i = 0; // Iterate over all frames in the video - decoded frame will be written to the buffer while (file.Video.TryGetNextFrame(pixelBuffer)) { // Save image as PNG file using var fs = File.OpenWrite($@"D:\example\frame_{i++}.png"); bitmap.Encode(fs, SKEncodedImageFormat.Png, 100); }This example uses SkiaSharp to save decoded frames. See Usage details section for examples with other graphics libraries.
Video decoding
// Open a multimedia file // You can use the MediaOptions properties to set decoder options var file = MediaFile.Open(@"C:\videos\movie.mp4"); // Get the frame at 5th second of the video var frame = file.Video.GetFrame(TimeSpan.FromSeconds(5)); // ... // Frame should be disposed when no longer needed frame.Dispose(); // Print information about the video stream Console.WriteLine($"Bitrate: {file.Info.Bitrate / 1000.0} kb/s"); var info = file.Video.Info; Console.WriteLine($"Duration: {info.Duration}"); Console.WriteLine($"Frames count: {info.NumberOfFrames ?? "N/A"}"); var frameRateInfo = info.IsVariableFrameRate ? "average" : "constant"; Console.WriteLine($"Frame rate: {info.AvgFrameRate} fps ({frameRateInfo})"); Console.WriteLine($"Frame size: {info.FrameSize}"); Console.WriteLine($"Pixel format: {info.PixelFormat}"); Console.WriteLine($"Codec: {info.CodecName}"); Console.WriteLine($"Is interlaced: {info.IsInterlaced}");Encode video from images.
// You can set codec, bitrate, frame rate and many other options here var settings = new VideoEncoderSettings(width: 1920, height: 1080, framerate: 30, codec: VideoCodec.H264) { EncoderPreset = EncoderPreset.Fast, CRF = 17, }; // Create output file using var file = MediaBuilder.CreateContainer(@"D:\example\video.mp4").WithVideo(settings).Create(); for(int i = 0; i < 300; i++) { // Load image using SkiaSharp (other libraries are also supported if provide access to pixel buffer) using var bmp = SKBitmap.Decode($@"D:\example\frame_{i}.png"); // Encode the video frame file.Video.AddFrame(new ImageData(bmp.GetPixelSpan(), ImagePixelFormat.Rgba32, bmp.Width, bmp.Height)); }
Setup
Install the FFMediaToolkit package from NuGet.
dotnet add package FFMediaToolkit
FFmpeg libraries are not included in the package. To use FFMediaToolkit, you need the FFmpeg shared build binaries: avcodec (v61), avformat (v61), avutil (v59), swresample (v5), swscale (v8).
Supported FFmpeg version: 7.x (shared build)
- Windows - You can download it from the BtbN/FFmpeg-Builds or gyan.dev. You only need
*.dllfiles from the.\bindirectory (not.\lib) of the ZIP package. Place the binaries in.\runtimes\win-[x64\arm64]\native\in the application output directory or setFFmpegLoader.FFmpegPath. - Linux - Download FFmpeg using your package manager. Default path is
/usr/lib/*-linux-gnu - macOS, iOS, Android - Not supported.
You need to set FFmpegLoader.FFmpegPath with a full path to FFmpeg libraries.
In .NET Framework projects you have to disable the Build → Prefer 32-bit option in Visual Studio project properties.
Usage details
FFMediaToolkit supports decoding video frames into pixel buffers which can be Span<byte>, byte[] or unmanaged memory. You can specify target pixel format by setting the MediaOptions.VideoPixelFormat property. The default format is Bgr24.
If you want to process or save the decoded frame, you can pass it to another graphics library, as shown in the examples below.
For SkiaSharp library:
- Video decoding
using var file = MediaFile.Open(@"D:\example\video.mp4", new MediaOptions() { StreamsToLoad = MediaMode.Video, VideoPixelFormat = ImagePixelFormat.Rgba32 }); using var bitmap = new SKBitmap(file.Video.Info.FrameSize.Width, file.Video.Info.FrameSize.Height, SKColorType.Rgba8888, SKAlphaType.Unpremul); var buffer = bitmap.GetPixelSpan(); while(file.Video.TryGetNextFrame(buffer)) { // do something } - Video encoding
using var bmp = SKBitmap.Decode($@"D:\example\frame.png"); mediaFile.Video.AddFrame(new ImageData(bmp.GetPixelSpan(), ImagePixelFormat.Rgba32, bmp.Width, bmp.Height));
- Video decoding
For ImageSharp library:
- Video decoding
var buffer = new byte[file.Video.FrameByteCount]; var bmp = Image.WrapMemory<Bgr24>(buffer, file.Video.Info.FrameSize.Width, file.Video.Info.FrameSize.Height); while(file.Video.TryGetNextFrame(buffer)) { // do something }
- Video decoding
For GDI+
System.Drawing.Bitmap(Windows only):- Video decoding
// Create bitmap once var rect = new Rectangle(Point.Empty, file.Video.Info.FrameSize); var bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb); // ... // Read next frame var bitLock = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); file.Video.TryGetNextFrame(bitLock.Scan0, bitLock.Stride); bitmap.UnlockBits(bitLock); - Video encoding
var rect = new Rectangle(Point.Empty, bitmap.Size); var bitLock = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); var bitmapData = ImageData.FromPointer(bitLock.Scan0, ImagePixelFormat.Bgr24, bitmap.Size); mediaFile.Video.AddFrame(bitmapData); // Encode the frame bitmap.UnlockBits(bitLock); // UnlockBits() must be called after encoding the frame
- Video decoding
For desktop apps with WPF UI (Windows only):
Video decoding
using System.Windows.Media.Imaging; // Create bitmap once var bmp = new WriteableBitmap(media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height, 96, 96, PixelFormats.Bgr24, null); // ... // Read next frame bmp.Lock(); var success = media.Video.TryGetNextFrame(bmp.BackBuffer, bmp.BackBufferStride); if(success) { bmp.AddDirtyRect(new Int32Rect(0, 0, media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height)); } bmp.Unlock();Video encoding
var bitmapSource = new BitmapImage(new Uri(@"D:\example\image.png")); var wb = new WriteableBitmap(bitmap); mediaFile.Video.AddFrame(ImageData.FromPointer(wb.BackBuffer, ImagePixelFormat.Bgra32, wb.PixelWidth, wb.PixelHeight));
Visual Basic usage
Writing decoded bitmap directly to the WPF WriteableBitmap buffer:
Dim file As FileStream = New FileStream("path to the video file", FileMode.Open, FileAccess.Read)
Dim media As MediaFile = MediaFile.Load(file)
Dim bmp As WriteableBimap = New WriteableBitmap(media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height, 96, 96, PixelFormats.Bgr24, Nothing)
bmp.Lock()
Dim decoded As Boolean = media.Video.TryGetFrame(TimeSpan.FromMinutes(1), bmp.BackBuffer, bmp.BackBufferStride)
If decoded Then
bmp.AddDirtyRect(New Int32Rect(0, 0, media.Video.Info.FrameSize.Width, media.Video.Info.FrameSize.Height))
End If
bmp.Unlock()
imageBox.Source = bmp
Converting ImageData to a byte array:
Dim data() As Byte = media.Video.GetNextFrame().Data.ToArray()
Licensing
This project is licensed under the MIT license.
| 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
- FFmpeg.AutoGen (>= 7.1.1)
- System.Memory (>= 4.5.5)
-
.NETStandard 2.1
- FFmpeg.AutoGen (>= 7.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FFMediaToolkit:
| Package | Downloads |
|---|---|
|
ITBees.FFMpegWrapper
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on FFMediaToolkit:
| Repository | Stars |
|---|---|
|
hcmlab/nova
NOVA is a tool for annotating and analyzing behaviours in social interactions. It supports Annotators using Machine Learning already during the coding process. Further it features both, discrete labels and continuous scores and a visuzalization of streams recorded with the SSI Framework.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.8.1 | 3,664 | 9/9/2025 |
| 4.8.0 | 1,496 | 8/13/2025 |
| 4.7.0 | 561 | 8/2/2025 |
| 4.6.0 | 2,728 | 5/22/2025 |
| 4.5.1 | 56,826 | 8/6/2023 |
| 4.5.0 | 14,562 | 5/7/2023 |
| 4.4.1 | 51,035 | 4/25/2022 |
| 4.4.0 | 722 | 4/25/2022 |
| 4.3.2 | 6,468 | 4/14/2022 |
| 4.3.1 | 676 | 4/9/2022 |
| 4.3.0 | 1,315 | 4/5/2022 |
| 4.2.0 | 3,742 | 2/17/2022 |
| 4.1.2 | 55,709 | 10/3/2021 |
| 4.1.1 | 11,799 | 6/12/2021 |
| 4.1.0 | 15,243 | 4/2/2021 |
| 4.0.1 | 4,017 | 2/18/2021 |
| 4.0.0 | 1,043 | 2/10/2021 |
| 3.4.0 | 2,103 | 1/15/2021 |
| 3.3.0 | 1,563 | 12/29/2020 |
| 3.2.0 | 658 | 12/21/2020 |
| 3.1.1 | 879 | 11/19/2020 |
| 3.1.0 | 1,727 | 9/12/2020 |
| 3.0.0 | 1,319 | 8/3/2020 |
| 2.2.1 | 2,203 | 12/18/2019 |
| 2.2.0 | 859 | 12/13/2019 |
| 2.1.1 | 735 | 12/11/2019 |
| 2.1.0 | 903 | 11/10/2019 |
| 2.0.0 | 877 | 7/13/2019 |
| 1.1.0 | 848 | 6/20/2019 |