FFMpegCore

v5.1.1·Updated 2024-06-27

NuGet FFMpegCore package re-bundled for convenient consumption and dependency management.

About this mod Author’s original text

FFMpegCore

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));

You can also capture GIF snapshots from a video file:

FFMpeg.GifSnapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10));

// or async

await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10));

// you can also supply -1 to either one of Width/Height Size properties if you'd like FFMPEG to resize while maintaining the aspect ratio

await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(480, -1), TimeSpan.FromSeconds(10));

Join video parts into one single file:

FFMpeg.Join(@"..\joined_video.mp4",

@"..\part1.mp4",

@"..\part2.mp4",

@"..\part3.mp4"

);

Create a sub video

csharp

FFMpeg.SubVideo(inputPath,

outputPath,

TimeSpan.FromSeconds(0)

TimeSpan.FromSeconds(30)

);

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 CreateFrames(int count)

{

for(int i = 0; i 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

Install & use Install: BepInEx plugin

  1. The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
  2. Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
  3. Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
  4. Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.

Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.

Dependencies

Install these first, or the mod will not work:

dotnet_content_warning-Instancesdotnet_content_warning-System_Text_Json

File & checksum

Filename
FFMpegCore-5.1.1.zip
File size
67.4 KiB