克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

drawing FFmpeg.NET

FFmpeg.NET provides a straightforward interface for handling media data, making tasks such as converting, slicing and editing both audio and video completely effortless.

Under the hood, FFmpeg.NET is a .NET wrapper for FFmpeg; a free (LGPLv2.1) multimedia framework containing multiple audio and video codecs, supporting muxing, demuxing and transcoding tasks on many media formats.

Some major parts are taken from https://github.com/AydinAdn/MediaToolkit. Many features have been refactored. The library has been ported to Netstandard and made threadsafe.

You need to provide the ffmpeg executable path to the Engine constructor.

Project Health

Service Status
AppVeyor Build status

Packages

Package NuGet
xFFmpeg.NET NuGet

Contents

  1. Features
  2. Get started!
  3. Samples
  4. Licensing

Features

  • Resolving metadata
  • Generating thumbnails from videos
  • Transcode audio & video into other formats using parameters such as:
    • Bit rate
    • Frame rate
    • Resolution
    • Aspect ratio
    • Seek position
    • Duration
    • Sample rate
    • Media format
  • Convert media to physical formats and standards such as:
    • Standards include: FILM, PAL & NTSC
    • Mediums include: DVD, DV, DV50, VCD & SVCD
  • Supports custom FFmpeg command line arguments (NEW in v2.1.0)
  • Raising progress events

Get started!

Install FFmpeg.NET from nuget.org Package Source using the Package Manager Console with the following command

PM> Install-Package xFFmpeg.NET

Samples

Grab thumbnail from a video

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_Image.jpg");

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
// Saves the frame located on the 15th second of the video.
var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(15) };
await ffmpeg.GetThumbnailAsync(inputFile, outputFile, options);

Retrieve metadata

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
var metadata = await ffmpeg.GetMetadataAsync(inputFile);

Console.WriteLine(metadata.Duration);

Basic conversion

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_New_Video.mp4");

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
await ffmpeg.ConvertAsync(inputFile, outputFile);

Convert Flash video to DVD

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_New_DVD.vob");

var conversionOptions = new ConversionOptions
{
    Target = Target.DVD,
    TargetStandard = TargetStandard.PAL
};

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions);

Transcoding options FLV to MP4

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_New_Video.mp4");

var conversionOptions = new ConversionOptions
{
    MaxVideoDuration = TimeSpan.FromSeconds(30),
    VideoAspectRatio = VideoAspectRatio.R16_9,
    VideoSize = VideoSize.Hd1080,
    AudioSampleRate = AudioSampleRate.Hz44100
};

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions);

Cut video down to smaller length

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_ExtractedVideo.flv");

var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
var options = new ConversionOptions();

// This example will create a 25 second video, starting from the 
// 30th second of the original video.
//// First parameter requests the starting frame to cut the media from.
//// Second parameter requests how long to cut the video.
options.CutMedia(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(25));
await ffmpeg.ConvertAsync(inputFile, outputFile, options);

Subscribe to events

public async Task StartConverting()
{
    var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
    var outputFile = new MediaFile (@"C:\Path\To_Save_New_Video.mp4");

    var ffmpeg = new Engine("C:\\ffmpeg\\ffmpeg.exe");
    ffmpeg.Progress += OnProgress;
    ffmpeg.Data += OnData;
    ffmpeg.Error += OnError;
    ffmpeg.Complete += OnComplete;
    await ffmpeg.ConvertAsync(inputFile, outputFile);
}

private void OnProgress(object sender, ConversionProgressEventArgs e)
{
    Console.WriteLine("[{0} => {1}]", e.Input.FileInfo.Name, e.Output.FileInfo.Name);
    Console.WriteLine("Bitrate: {0}", e.Bitrate);
    Console.WriteLine("Fps: {0}", e.Fps);
    Console.WriteLine("Frame: {0}", e.Frame);
    Console.WriteLine("ProcessedDuration: {0}", e.ProcessedDuration);
    Console.WriteLine("Size: {0} kb", e.SizeKb);
    Console.WriteLine("TotalDuration: {0}\n", e.TotalDuration);
}

private void OnData(object sender, ConversionDataEventArgs e)
{
    Console.WriteLine("[{0} => {1}]: {2}", e.Input.FileInfo.Name, e.Output.FileInfo.Name, e.Data);
}

private void OnComplete(object sender, ConversionCompleteEventArgs e)
{
    Console.WriteLine("Completed conversion from {0} to {1}", e.Input.FileInfo.FullName, e.Output.FileInfo.FullName);
}

private void OnError(object sender, ConversionErrorEventArgs e)
{
    Console.WriteLine("[{0} => {1}]: Error: {2}\n{3}", e.Input.FileInfo.Name, e.Output.FileInfo.Name, e.Exception.ExitCode, e.Exception.InnerException);
}

Licensing


The MIT License (MIT) Copyright (c) [2018] [Tobias Haimerl (cmxl)] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化