ImageSharp.AVCodecFormats
4.6.0
dotnet add package ImageSharp.AVCodecFormats --version 4.6.0
NuGet\Install-Package ImageSharp.AVCodecFormats -Version 4.6.0
<PackageReference Include="ImageSharp.AVCodecFormats" Version="4.6.0" />
paket add ImageSharp.AVCodecFormats --version 4.6.0
#r "nuget: ImageSharp.AVCodecFormats, 4.6.0"
// Install ImageSharp.AVCodecFormats as a Cake Addin #addin nuget:?package=ImageSharp.AVCodecFormats&version=4.6.0 // Install ImageSharp.AVCodecFormats as a Cake Tool #tool nuget:?package=ImageSharp.AVCodecFormats&version=4.6.0
ImageSharp.AVCodecFormats
FFmpeg decoders for ImageSharp
Install
via NuGet:
PM> Install-Package ImageSharp.AVCodecFormats
Native libs for x64 Linux and Windows:
PM> Install-Package ImageSharp.AVCodecFormats.Native
also, we can install separate native packages:
PM> Install-Package ImageSharp.AVCodecFormats.Native.win-x64
PM> Install-Package ImageSharp.AVCodecFormats.Native.linux-x64
Without native packages you should provide your own shared FFmpeg build and set path:
FFmpegBinaries.Path = "/path/to/native/binaries"
On Linux you have another way to get native libs. Just install ffmpeg from your package manager, but I have no guarantees that it will work as expected.
Usage
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Processing;
using HeyRed.ImageSharp.AVCodecFormats;
// Create custom configuration with all available decoders
var configuration = new Configuration().WithAVDecoders();
// Or only required decoders
var configuration = new Configuration(
new AviConfigurationModule(),
new MkvConfigurationModule(),
new MovConfigurationModule(),
new Mp4ConfigurationModule(),
new WebmConfigurationModule(),
new WmvConfigurationModule(),
new MpegTsConfigurationModule(),
new Mp3ConfigurationModule());
// NOTE: Don't forget to set max frames.
// Without this limit you can run into huge memory usage.
var decoderOptions = new DecoderOptions
{
MaxFrames = 50,
Configuration = configuration,
// The TargetSize option is also supported.
// This will reduce memory usage in result image.
};
using var inputStream = File.OpenRead("/path/to/video.mp4");
using var image = Image.Load(decoderOptions, inputStream);
// Resize
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
// Save all frames using png encoder
for (int i = 0; i < image.Frames.Count; i++)
{
image.Frames
.CloneFrame(i)
.SaveAsPng($"frame{i}.png");
}
More info https://docs.sixlabors.com/articles/imagesharp/configuration.html
Frame filter
Frame filter is a delegate that provides the way to skip frames based on their content.
It can be useful for various scenarios like black/white frames filter, skip every n frame or something else.
var decoderOptions = new AVDecoderOptions
{
GeneralOptions = new DecoderOptions
{
MaxFrames = 100,
},
FrameFilter = (imageFrame, frameNum) =>
{
var frame = (ImageFrame<Rgba32>)frame; // Pix format should match with Load/Decode methods
// Do something with frame
// Return true when frame should be not present in result image
return false;
},
};
using var inputStream = File.OpenRead(/path/to/video.mp4);
using var image = Mp4Decoder.Instance.Decode(decoderOptions, inputStream);
// do something
See tests for basic implementation of black frames filter.
Additional tips
If you want preserve aspect ratio when TargetSize is set:
var decoderOptions = new AVDecoderOptions
{
PreserveAspectRatio = true,
GeneralOptions = new DecoderOptions
{
TargetSize = new Size(500),
},
};
An additional format specific information about the file:
// Get infogmation about webm file
AVMetadata metadata = Image.Identify(decoderOptions, inputStream).Metadata.GetWebmMetadata();
Supported formats
mp4, webm, avi, mkv, mov, ts, wmv, mp3(cover image).
Supported codecs
Native package provides codecs listed below:
H263, H264, H.265(HEVC), VP8, VP9, AV1, MPEG-4, MJPEG, PNG, MS MPEG4(v1,v2,v3), WMV(v1,v2,v3), VC-1, MPEG-1 Audio Layer 3.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- FFmpeg.AutoGen (>= 6.1.0)
- SixLabors.ImageSharp (>= 3.1.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ImageSharp.AVCodecFormats:
Package | Downloads |
---|---|
elfinder.Net8
An elFinder backend connector with less magic code and more compatibility. This enables .NET 8 projects to easily integrate elFinder functionalities. See the example project on Github for usage detail. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.6.0 | 2,843 | 1/23/2024 |
4.4.0 | 400 | 12/6/2023 |
4.3.0 | 196 | 11/19/2023 |
4.2.0 | 207 | 10/11/2023 |
4.1.1 | 1,072 | 4/2/2023 |
4.1.0 | 262 | 3/21/2023 |
4.0.0 | 256 | 3/18/2023 |
3.0.8 | 6,263 | 4/25/2022 |
3.0.7 | 448 | 4/24/2022 |
3.0.6 | 448 | 4/14/2022 |
3.0.5 | 465 | 3/29/2022 |
3.0.3 | 459 | 3/23/2022 |
3.0.2 | 426 | 3/16/2022 |
3.0.1 | 462 | 3/8/2022 |
3.0.0 | 467 | 3/2/2022 |
2.2.5 | 425 | 1/10/2022 |
2.2.4 | 5,737 | 12/9/2021 |
2.2.3 | 361 | 10/11/2021 |
2.2.2 | 317 | 10/3/2021 |
2.2.1 | 657 | 4/13/2021 |
2.2.0 | 368 | 4/9/2021 |
2.1.1 | 398 | 1/15/2021 |
2.1.0 | 374 | 1/3/2021 |
2.0.0 | 422 | 1/2/2021 |
1.2.4 | 530 | 12/5/2020 |
1.2.3 | 453 | 10/18/2020 |
1.2.2 | 453 | 10/5/2020 |
1.2.1 | 475 | 10/4/2020 |
1.2.0 | 426 | 10/2/2020 |
1.1.1 | 421 | 10/1/2020 |
1.1.0 | 445 | 9/30/2020 |
1.0.0 | 429 | 9/28/2020 |