tomaszzmuda/Xabe.FFmpeg

.NET Standard wrapper for FFmpeg. It allows to process media without know how FFmpeg works, and can be used to pass customized arguments to FFmpeg from dotnet core application.

Xabe.FFmpeg is a C# library that lets you control the FFmpeg and FFprobe media tools without typing command-line arguments yourself. You write C# code like "convert this MKV to MP4" or "read this file's info," and the library builds the right command, runs the tools, and hands you the result.

How it works

Xabe.FFmpeg does not embed or link against FFmpeg's internal code. Instead, it:

  1. Builds a command-line argument string for the ffmpeg / ffprobe executables.
  2. Starts those executables on your machine.
  3. Reports back progress, output, and the final result.

Because it's just a wrapper around the real command-line tools, anything FFmpeg can do remains possible — you're never limited to what the library models.

Installation

Install from NuGet:

dotnet add package Xabe.FFmpeg

Prerequisite: both the ffmpeg and ffprobe executables must be installed on your system. You can install them yourself, or use the separate optional package Xabe.FFmpeg.Downloader to fetch a build automatically.

The library finds the executables in this order:

  1. A directory you explicitly set with FFmpeg.SetExecutablesPath(...).
  2. The directory containing your application's main assembly.
  3. Directories in your PATH environment variable.

If neither executable is found, it throws an FFmpegNotFoundException that tells you where it searched.

Quick start

A complete, working example — converts movie.mkv to movie.mp4:

using System;
using Xabe.FFmpeg;

string input = "movie.mkv";
string output = "movie.mp4";

IConversion conversion = await FFmpeg.Conversions.FromSnippet.ToMp4(input, output);
IConversionResult result = await conversion.Start();

Console.WriteLine(result.Arguments);

This probes the input, picks the first video and audio streams, and re-encodes them to H.264/AAC in an MP4 container. The emitted command looks like:

-i "movie.mkv" -c:v h264 -c:a aac -map 0:0 -map 0:1 -n "movie.mp4"

Note the -n flag: it will not overwrite an existing output file, so running the snippet twice fails until you delete or rename movie.mp4.

Two packages

Package Purpose
Xabe.FFmpeg The core library: builds command lines, runs the executables, surfaces results and progress.
Xabe.FFmpeg.Downloader Optional helper that downloads an ffmpeg/ffprobe build for your OS into a directory you choose.

What the core package offers

  • Ready-made snippets for common operations: convert to MP4/TS/WebM/OGV/GIF, extract or add audio, take snapshots, split, concatenate, add watermarks, capture M3U8 playlists, send files to an RTSP server.
  • Stream-level control: select, copy, or reconfigure individual video, audio, and subtitle streams (codec, bitrate, size, rotation, filters).
  • Probing: FFmpeg.GetMediaInfo(...) reads file metadata via ffprobe; raw Probe access lets you pass custom ffprobe arguments.
  • Events: OnProgress, OnDataReceived, and OnVideoDataReceived for progress and raw output.
  • RTSP/web streams: send files or your desktop to an RTSP server, capture HLS playlists.
  • Hardware acceleration: pass-through support for cuvid/NVENC, QuickSync, VideoToolbox, VAAPI, etc., via UseHardwareAcceleration(...).
  • Arbitrary custom parameters with explicit placement (ParameterPosition) for options the API doesn't model.

Three levels of API

All three build the same IConversion object; pick the simplest that expresses your operation.

1. Snippets — for common operations:

IConversion conversion = await FFmpeg.Conversions.FromSnippet.ExtractAudio(input, output);
await conversion.Start();

2. Stream builder — when you need to select or change streams and codecs:

IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(input);
IVideoStream videoStream = mediaInfo.VideoStreams
    .First()
    .SetCodec(VideoCodec.h264)
    .SetSize(VideoSize.Hd480);

IConversion conversion = FFmpeg.Conversions.New()
    .AddStream(videoStream)
    .SetOutput(output)
    .SetOverwriteOutput(true);

await conversion.Start();

3. Raw parameters — for options the API doesn't model. FFmpeg options are position-sensitive, so AddParameter takes a ParameterPosition: PreInput places the option before the -i input definition, PostInput (the default) after it.

IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(input);

IConversion conversion = FFmpeg.Conversions.New()
    .AddStream(mediaInfo.Streams)
    .AddParameter("-re", ParameterPosition.PreInput)
    .AddParameter("-ss 00:00:01 -t 00:00:05")
    .SetOutput(output)
    .SetOverwriteOutput(true);

string arguments = conversion.Build(); // inspect before running
await conversion.Start();

Downloading FFmpeg/FFprobe

Point the library at a directory containing both executables:

FFmpeg.SetExecutablesPath(@"C:\Tools\ffmpeg");

Or use the downloader package to fetch a build automatically:

string executableDirectory = "./ffmpeg";
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, executableDirectory);
FFmpeg.SetExecutablesPath(executableDirectory);

Downloader providers:

FFmpegVersion Source Platforms
Official ffbinaries builds (recommended) Windows (32/64-bit), macOS, Linux (incl. 32-bit and ARM)
Full / Shared Static/shared Zenaroe builds from xabe.net (Full is end-of-life) Windows, macOS
Android Mobile-FFmpeg family builds from xabe.net Android (ARM/ARM64/x86/x86_64)

The downloader always fetches the provider's latest build; there's no way to pin a specific FFmpeg version.

Important: which encoders, decoders, filters, and hardware accelerations actually work depends on the FFmpeg build you install and your hardware. Check with ffmpeg -encoders, ffmpeg -decoders, and ffmpeg -hwaccels.

Compatibility and limitations

  • Targeting: both packages target .NET Standard 2.0, usable by modern .NET, .NET Framework 4.6.1+, and other NS2.0-compatible runtimes (e.g., Unity).
  • Operating systems: conversion works on Windows, macOS, and Linux wherever the executables can be found. The downloader covers the platforms listed above; Tizen and Raspberry Pi are not supported by the downloader.
  • Tested build: CI runs the full test suite against a specific pinned FFmpeg build (BtbN n7.1.1-57-g1b48158a23, GPL, linux64). That's tested evidence, not a promise for other versions — any reasonably recent, complete ffmpeg/ffprobe pair works in practice.
  • Licenses: the wrapper itself is released under CC BY-NC-SA 3.0 — non-commercial use only; commercial use requires a separate Xabe license. The FFmpeg/FFprobe executables are licensed independently (commonly GPL or LGPL depending on the build).
  • Limitations: conversions operate on files and stream URIs, not in-memory buffers; there's no arbitrary FFmpeg version pinning; and because it's a CLI wrapper, exotic setups (e.g., unusual process management) are your responsibility.

Troubleshooting

  • "Cannot find FFmpeg" (FFmpegNotFoundException): ensure both ffmpeg and ffprobe exist, are executable, and match your architecture; check the discovery order (configured directory → application directory → PATH).
  • A conversion fails: inspect IConversionResult.Arguments to see exactly what was run; attach raw output captured via OnDataReceived or exception details. The API does not retain the full FFmpeg log after Start() completes.
  • Unexpected custom-option behaviour: re-check ParameterPosition and the string from Build() — the library does not validate option placement.
  • Codec or hardware-acceleration errors: your build may simply lack the feature — inspect with ffmpeg -encoders, ffmpeg -decoders, ffmpeg -hwaccels before suspecting the wrapper.

Resources

Related

  • Project
  • Project
  • Project
  • Project