必须同时存在 ffmpeg 和 ffprobe 两个可执行文件,否则抛 FFmpegNotFoundException;下载器只能取最新版本,无法固定任意 FFmpeg 版本;封装库为 CC BY-NC-SA 3.0 非商用许可,商用需单独购买 Xabe 授权。
Xabe.FFmpeg
tomaszzmuda活跃维护面向 .NET Standard 的 FFmpeg 封装库,让 C# 开发者不用了解 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.
dotnet add package Xabe.FFmpegREADME 未说明显存或 CPU 要求;硬件加速能力取决于所安装的 FFmpeg 构建和宿主硬件,可用 ffmpeg -hwaccels 查看。
C# 里调用 FFmpeg 的 .NET 封装库,不用记命令行也能转码、探测和推流
面向 .NET Standard 的 FFmpeg 封装库,让 C# 开发者不用了解 FFmpeg 命令行细节就能处理音视频,也支持传入自定义参数。
核心能力
- 拼接 ffmpeg/ffprobe 命令行并启动本机可执行文件
- 提供 FromSnippet 现成操作,覆盖转 MP4、抽音轨、截图、拼接
- 用流构建器逐条选择或改写视频、音频、字幕流参数
- AddParameter 配合 ParameterPosition 精确控制参数位置
- 支持 NVENC、QuickSync、VideoToolbox、VAAPI 硬件加速透传
容易踩的坑
- v6.1.1最新正式版2026-09-23 · 2026-09-23 22:13 UTC
v6.1.1
- Embed README in packages (#506)
- v6.1.02026-09-23 · 2026-09-23 19:18 UTC
查看更新说明
v6.1.0
- Use NuGet trusted publishing (#505)
- Fix PreInput Placement (#504)
- Stabilize rtsp framerate assertion (#503)
- Add channel layout to IAudioStream (#502)
- Fix Osx executable check formatting (#501)
- add check for 64 bit ffmpeg (#488)
- XAB-1377: Migrate RTSP integration tests to Testcontainers (#497)
- XAB-1373: Remove obsolete samples project and changelog (#499)
- XAB-1371: Updated readme (#495)
- XAB-1374: replace license link with website license agreement (#498)
- Move CI to GitHub Actions (#494)
- Fix concat issue and PipeOutput issue (#489)
- Use stable aler9 RTSP server docker image (#490)
- Add https to get ffbinaries API call (#487)
- Update azure-pipelines.yml for Azure Pipelines (#486)
- Use system text json (#485)
- Update tests to .NET 8 (#484)
- Eol Repair (#467)
- More options for FindAndValidateExecutables + check if the file is executable
- Default to Windows32 and Windows64 for Arm and Arm64 Respectively on Windows Systems (#450)
- Fix of date time offset that was using the local time zone of the computer (#443)
- Use async/await instead of GetAwaiter everywhere (#441)
- Update changelog (#440)
- Solve problems with chineese dates (#439)
- Remove obsolete tasks (#438)
- Fix downloader problems (rethrow exception instead of silently continue) (#436)
- Fix exception when only file name was given as a path (#433)
- Auth to production nuget in pipeline (#420)
- Add Pad ability to VideoStream. (#430)
- Extend timeout for downloader tests
- executablesZeranoe FFmpeg builds2020-09-06 · 2020-09-06 17:06 UTC
这个版本没有写更新说明。
- 3.1.82019-04-27 · 2019-04-27 20:10 UTC
这个版本没有写更新说明。
- 3.1.6'Seek' parameter order2019-04-10 · 2019-04-10 21:36 UTC
这个版本没有写更新说明。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Xabe.FFmpeg
A cross-platform .NET wrapper that runs FFmpeg and FFprobe for you from C#: convert, probe, resize, subtitle, and stream media without memorizing the command line.
How it works. Xabe.FFmpeg does not bind to the native libav* libraries. It builds an FFmpeg argument string and starts the ffmpeg / ffprobe executables that exist on your machine (or that you tell it about). Everything the FFmpeg CLI can do stays available — you are never limited to what the wrapper models.
Contents:
- Install
- Quick start
- Packages and capabilities
- Choosing the right API level
- Finding FFmpeg and FFprobe
- Compatibility and limitations
- Troubleshooting and support
- Documentation and project resources
Install
Xabe.FFmpeg is distributed on NuGet:
dotnet add package Xabe.FFmpeg
or in the NuGet Package Manager console:
PM> Install-Package Xabe.FFmpeg
Prerequisite: both the ffmpeg and ffprobe executables must be available. If you do not have them, either install them from your platform's package manager, or use the separate Xabe.FFmpeg.Downloader package, which fetches a build for you.
When you create a conversion, the library locates the executables in this order:
- The directory you pointed it at with
FFmpeg.SetExecutablesPath(...). - The directory containing your application's entry assembly.
- The directories listed in the
PATHenvironment variable.
Lookup is by executable name (ffmpeg, ffprobe, plus .exe on Windows) and is case-insensitive. If neither executable is found, an FFmpegNotFoundException is thrown with a message pointing at the locations it searched (the configured directory, if any, and PATH).
Quick start
One complete local-file conversion. This compiles and runs in any console project that references the package, as long as ffmpeg/ffprobe are discoverable:
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);
The snippet probes the input, selects the first video and audio streams, and retargets them to H.264/AAC in an MP4 container. Against a two-stream MKV input the emitted command has the shape:
-i "movie.mkv" -c:v h264 -c:a aac -map 0:0 -map 0:1 -n "movie.mp4"
Note the -n: the snippet does not overwrite an existing output file, so running the snippet twice fails with a ConversionException until you delete or rename movie.mp4.
Packages and capabilities
| Package | Purpose |
|---|---|
| Xabe.FFmpeg | Builds FFmpeg/FFprobe command lines, runs the executables, and surfaces results and progress. |
| Xabe.FFmpeg.Downloader | Separate, optional package that downloads an ffmpeg/ffprobe build for the current OS into a directory you choose. |
What the core package offers today:
- Common conversion snippets (to MP4/TS/WebM/OGV/GIF, extract/add audio, snapshots, split, concatenate, watermarks, M3U8 capture, 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 with
FFmpeg.GetMediaInfo(...)(ffprobe-backed) and rawProbeaccess for custom ffprobe arguments. - Progress and raw-output events:
OnProgress,OnDataReceived, andOnVideoDataReceived(withPipeOutput). - RTSP/web streams: send files or the desktop to an RTSP server, capture HLS playlists.
- Hardware acceleration pass-through:
cuvid/NVENC, QuickSync, VideoToolbox, VAAPI and friends, viaUseHardwareAcceleration(...). - Arbitrary custom FFmpeg parameters with explicit placement (
ParameterPosition).
Public entry points worth knowing: FFmpeg (the static facade), FFmpeg.Conversions (new conversions), FFmpeg.Conversions.FromSnippet (ready-made operations), FFmpeg.GetMediaInfo (probing), IConversion (fluent conversion builder), IConversionResult (outcome incl. the emitted Arguments), and the stream interfaces IVideoStream, IAudioStream, ISubtitleStream.
Choosing the right API level
All three levels return or build the same IConversion; pick the lowest level that expresses your operation.
1. Start with a snippet for the common operations:
IConversion conversion = await FFmpeg.Conversions.FromSnippet.ExtractAudio(input, output);
await conversion.Start();
2. Use the stream builder when you need to select or change streams and codecs:
using System.Linq;
using Xabe.FFmpeg;
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. Use raw parameters for options the API does not model. FFmpeg options are position-sensitive, so AddParameter takes a ParameterPosition: PreInput places the option before the input definition (-i), PostInput (the default) places it after.
using Xabe.FFmpeg;
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();
Full detail on all three approaches lives in the online guide (see its Snippets, Streams, and Own arguments chapters).
Finding FFmpeg and FFprobe
Point the library at a directory that contains both executables:
using Xabe.FFmpeg;
FFmpeg.SetExecutablesPath(@"C:\Tools\ffmpeg");
Or let the optional Xabe.FFmpeg.Downloader package fetch a build into a directory, then point the library at it:
using Xabe.FFmpeg;
using Xabe.FFmpeg.Downloader;
string executableDirectory = "./ffmpeg";
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, executableDirectory);
FFmpeg.SetExecutablesPath(executableDirectory);
Downloader providers available today:
FFmpegVersion | Source | Platforms |
|---|---|---|
Official | ffbinaries builds, queried through their API (recommended) | Windows (32/64-bit), macOS, Linux (incl. 32-bit and ARM) |
Full / Shared | Static (Full) and shared (Shared) Zenaroe builds served from xabe.net; Full reached end of life and is no longer updated | Windows, macOS |
Android | Android builds (Mobile-FFmpeg family) served from xabe.net | Android (ARM/ARM64/x86/x86_64) |
The downloader always fetches the provider's latest build; there is no API to pin an arbitrary FFmpeg version.
Heads-up: which encoders, decoders, filters, and hardware accelerations actually work depends on the FFmpeg build you install and on your host hardware (ffmpeg -encoders, ffmpeg -decoders, ffmpeg -hwaccels show what your build ships).
Compatibility and limitations
- Targeting: both packages target .NET Standard 2.0, which is consumable by any modern .NET workload (current .NET, .NET Framework 4.6.1 and later, and other NS2.0-compatible runtimes such as Unity) — see Microsoft's targeting and platform-support documentation for the full matrix.
- Operating systems: conversion works on Windows, macOS, and Linux wherever the executables can be discovered (configured directory, application directory, or
PATH). The downloader covers the platforms listed above; the site notes that Tizen and Raspberry Pi are not supported by the downloader. - Tested FFmpeg build: CI runs the entire test suite against a SHA-256-pinned FFmpeg — BtbN build
n7.1.1-57-g1b48158a23(GPL, linux64, autobuild 2025-08-31). That is tested evidence, not a support promise for other versions; any reasonably recent, completeffmpeg/ffprobepair works in practice. - Licenses, separately. The wrapper is released under CC BY-NC-SA 3.0 for non-commercial use; commercial use requires a Xabe license — see the license page and pricing. The FFmpeg/FFprobe executables are licensed independently of this package — commonly GPL or LGPL depending on the build you obtain — and their terms apply to you as the installer.
- Limitations: conversions operate on files and stream URIs, not in-memory buffers; there is no arbitrary FFmpeg version pinning; and because this is a CLI wrapper, exotic setups (e.g. unusual process management) are yours to configure.
Troubleshooting and support
- "Cannot find FFmpeg" (
FFmpegNotFoundException): make sure bothffmpegandffprobeexist, are executable, and match your architecture; then check the discovery order above — configured directory first, then the application directory, thenPATH. - A conversion fails: when you have a result, inspect
IConversionResult.Argumentsto see exactly what was run; attach the conversion's raw output (captured through theOnDataReceivedevent) or the exception details to any report. The API does not retain the full FFmpeg log afterStart()completes. - Unexpected custom-option behaviour: re-check
ParameterPositionand the string returned byBuild()— the library does not validate option placement, so a misplaced option surfaces as a baffling FFmpeg error. - Codec or hardware-acceleration errors: your build may simply lack it — inspect the installed FFmpeg with
ffmpeg -encoders,ffmpeg -decoders, andffmpeg -hwaccelsbefore suspecting the wrapper.
Where to go:
- Usage questions and reproducible defects: GitHub Issues (include the output of
ffmpeg -versionandIConversionResult.Arguments). - Security reports: SECURITY.md.
- Contributions: CONTRIBUTING.md.
- Licensing and commercial questions: license page / pricing.
Documentation and project resources
- Online documentation guide — snippets, streams, raw arguments, RTSP, hardware acceleration.
- First-conversion tutorial — a worked end-to-end example.
- FAQ
- GitHub Releases — version history and release notes
- Issue tracker · Contributing · Security policy
- NuGet: Xabe.FFmpeg · NuGet: Xabe.FFmpeg.Downloader