FFMpegCore 4.6.0

Install-Package FFMpegCore -Version 4.6.0
dotnet add package FFMpegCore --version 4.6.0
<PackageReference Include="FFMpegCore" Version="4.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FFMpegCore --version 4.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FFMpegCore, 4.6.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install FFMpegCore as a Cake Addin
#addin nuget:?package=FFMpegCore&version=4.6.0

// Install FFMpegCore as a Cake Tool
#tool nuget:?package=FFMpegCore&version=4.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

FFMpegCore

NuGet Badge GitHub issues GitHub stars GitHub CI

A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications. Supports both synchronous and asynchronous calls

API

FFProbe

Use FFProbe to analyze media files:

var mediaInfo = await FFProbe.AnalyseAsync(inputPath);

or

var mediaInfo = FFProbe.Analyse(inputPath);

FFMpeg

Use FFMpeg to convert your media files. Easily build your FFMpeg arguments using the fluent argument builder:

Convert input file to h264/aac scaled to 720p w/ faststart, for web playback

FFMpegArguments
    .FromFileInput(inputPath)
    .OutputToFile(outputPath, false, options => options
        .WithVideoCodec(VideoCodec.LibX264)
        .WithConstantRateFactor(21)
        .WithAudioCodec(AudioCodec.Aac)
        .WithVariableBitrate(4)
        .WithVideoFilters(filterOptions => filterOptions
            .Scale(VideoSize.Hd))
        .WithFastStart())
    .ProcessSynchronously();

Convert to and/or from streams

await FFMpegArguments
    .FromPipeInput(new StreamPipeSource(inputStream))
    .OutputToPipe(new StreamPipeSink(outputStream), options => options
        .WithVideoCodec("vp9")
        .ForceFormat("webm"))
    .ProcessAsynchronously();

Helper methods

The provided helper methods makes it simple to perform common operations.

Easily capture snapshots from a video file:

// process the snapshot in-memory and use the Bitmap directly
var bitmap = FFMpeg.Snapshot(inputPath, new Size(200, 400), TimeSpan.FromMinutes(1));

// or persists the image on the drive
FFMpeg.Snapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromMinutes(1));

Join video parts into one single file:

FFMpeg.Join(@"..\joined_video.mp4",
    @"..\part1.mp4",
    @"..\part2.mp4",
    @"..\part3.mp4"
);

Join images into a video:

FFMpeg.JoinImageSequence(@"..\joined_video.mp4", frameRate: 1,
    ImageInfo.FromPath(@"..\1.png"),
    ImageInfo.FromPath(@"..\2.png"),
    ImageInfo.FromPath(@"..\3.png")
);

Mute the audio of a video file:

FFMpeg.Mute(inputPath, outputPath);

Extract the audio track from a video file:

FFMpeg.ExtractAudio(inputPath, outputPath);

Add or replace the audio track of a video file:

FFMpeg.ReplaceAudio(inputPath, inputAudioPath, outputPath);

Combine an image with audio file, for youtube or similar platforms

FFMpeg.PosterWithAudio(inputPath, inputAudioPath, outputPath);
// or
var image = Image.FromFile(inputImagePath);
image.AddAudio(inputAudioPath, outputPath);

Other available arguments could be found in FFMpegCore.Arguments namespace.

Input piping

With input piping it is possible to write video frames directly from program memory without saving them to jpeg or png and then passing path to input of ffmpeg. This feature also allows for converting video on-the-fly while frames are being generated or received.

An object implementing the IPipeSource interface is used as the source of data. Currently, the IPipeSource interface has two implementations; StreamPipeSource for streams, and RawVideoPipeSource for raw video frames.

Working with raw video frames

Method for generating bitmap frames:

IEnumerable<IVideoFrame> CreateFrames(int count)
{
    for(int i = 0; i < count; i++)
    {
        yield return GetNextFrame(); //method that generates of receives the next frame
    }
}

Then create a RawVideoPipeSource that utilises your video frame source

var videoFramesSource = new RawVideoPipeSource(CreateFrames(64))
{
    FrameRate = 30 //set source frame rate
};
await FFMpegArguments
    .FromPipeInput(videoFramesSource)
    .OutputToFile(outputPath, false, options => options
        .WithVideoCodec(VideoCodec.LibVpx))
    .ProcessAsynchronously();

If you want to use System.Drawing.Bitmaps as IVideoFrames, a BitmapVideoFrameWrapper wrapper class is provided.

Binaries

Installation

If you prefer to manually download them, visit ffbinaries or zeranoe Windows builds.

Windows (using choco)

command: choco install ffmpeg -y

location: C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin

Mac OSX

command: brew install ffmpeg mono-libgdiplus

location: /usr/local/bin

Ubuntu

command: sudo apt-get install -y ffmpeg libgdiplus

location: /usr/bin

Path Configuration

Option 1

The default value of an empty string (expecting ffmpeg to be found through PATH) can be overwritten via the FFOptions class:

// setting global options
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });

// or
GlobalFFOptions.Configure(options => options.BinaryFolder = "./bin");

// on some systems the absolute path may be required, in which case 
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = Server.MapPath("./bin"), TemporaryFilesFolder = Server.MapPath("/tmp") });

// or individual, per-run options
await FFMpegArguments
    .FromFileInput(inputPath)
    .OutputToFile(outputPath)
    .ProcessAsynchronously(true, new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });

Option 2

The root and temp directory for the ffmpeg binaries can be configured via the ffmpeg.config.json file, which will be read on first use only.

{
  "BinaryFolder": "./bin",
  "TemporaryFilesFolder": "/tmp"
}

Supporting both 32 and 64 bit processes

If you wish to support multiple client processor architectures, you can do so by creating two folders, x64 and x86, in the BinaryFolder directory. Both folders should contain the binaries (ffmpeg.exe and ffprobe.exe) built for the respective architectures.

By doing so, the library will attempt to use either /{BinaryFolder}/{ARCH}/(ffmpeg|ffprobe).exe.

If these folders are not defined, it will try to find the binaries in /{BinaryFolder}/(ffmpeg|ffprobe.exe).

(.exe is only appended on Windows)

Compatibility

Older versions of ffmpeg might not support all ffmpeg arguments available through this library. The library has been tested with version 3.3 to 4.2

Code contributors

<a href="https://github.com/rosenbjerg/ffmpegcore/graphs/contributors"> <img src="https://contrib.rocks/image?repo=rosenbjerg/ffmpegcore" /> </a>

Other contributors

<a href="https://github.com/tiesont"><img src="https://avatars3.githubusercontent.com/u/420293?v=4" title="tiesont" width="80" height="80"></a>

License

Copyright © 2021

Released under MIT license

NuGet packages (3)

Showing the top 3 NuGet packages that depend on FFMpegCore:

Package Downloads
Shiw.Core.FFmpeg

基于FFMpegCore库调用ffmpeg实现以下功能: 1.图片合成视频 2.视频转HLS

14All

Package Description

OpenpilotSdk

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on FFMpegCore:

Repository Stars
Radarr/Radarr
A fork of Sonarr to work with movies à la Couchpotato.
ncatlin/rgat
An instruction trace visualisation tool for dynamic program analysis
Version Downloads Last updated
4.6.0 2,891 11/1/2021
4.5.0 11,133 8/12/2021
4.4.0 8,110 7/15/2021
4.3.0 11,771 6/8/2021
4.2.0 4,116 5/14/2021
4.1.0 12,647 3/15/2021
4.0.0 2,656 3/6/2021
3.4.0 4,412 2/3/2021
3.3.0 5,499 12/19/2020
3.2.4 17,323 12/9/2020
3.2.3 246 12/9/2020
3.2.2 366 12/7/2020
3.2.1 427 12/5/2020
3.2.0 6,266 11/25/2020
3.1.0 4,734 10/28/2020
3.0.0 2,014 10/24/2020
2.2.6 10,712 8/10/2020
2.2.5 2,453 8/8/2020
2.2.4 1,514 7/26/2020
2.2.3 372 7/25/2020
2.2.2 838 7/13/2020
2.2.1 5,489 6/23/2020
2.2.0 701 6/20/2020
2.1.1 297 6/19/2020
2.1.0 259 6/18/2020
2.0.1 1,747 6/6/2020
2.0.0 623 5/24/2020
1.4.0 1,834 5/6/2020
1.3.3 1,939 4/15/2020
1.3.2 281 4/14/2020
1.3.1 3,616 3/1/2020
1.3.0 295 3/1/2020
1.2.0 321 2/25/2020
1.1.0 362 2/21/2020
1.0.12 1,536 1/29/2020
1.0.11 12,748 9/30/2019
1.0.10 6,219 5/20/2019
1.0.9 436 5/11/2019
1.0.8 484 5/3/2019
1.0.7 2,753 4/1/2019
1.0.6 475 3/27/2019
1.0.5 1,706 3/4/2019
1.0.4 447 3/2/2019
1.0.2 430 2/26/2019
1.0.1 437 2/26/2019
1.0.0 701 2/8/2019

- Support for reading Disposition metadata on streams in FFProbe output (thanks alex6dj)
- Fix for stream index in Snapshot(Async) (thanks stasokrosh)
- Add support for frame analysis through FFProbe,GetFrames(Async) (thanks andyjmorgan)
- Fix for subtitle burning error, when subtitle path contains special characters (thanks alex6dj)
- Support for Audio filters (thanks alex6dj)
- Fix FFProbe.AnalyseAsync not throwing if non-zero exit-code (thanks samburovkv)
- Change bit_rate from int to long to support analysis of high bit-rate files (thanks zhuker)
- Support for specifying working directory for ffmpeg and ffprobe processes through FFOptions
- Ensure Image instances in JoinImageSequence are disposed
- Added ConfigureAwait(false) to prevent hanging with certain frameworks