mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
Merge branch 'master' of https://github.com/rosenbjerg/FFMpegCore
This commit is contained in:
commit
292841e40d
1 changed files with 65 additions and 62 deletions
127
README.md
127
README.md
|
@ -1,37 +1,29 @@
|
||||||
# FFMpegCore
|
# [FFMpegCore](https://www.nuget.org/packages/FFMpegCore/)
|
||||||
[![CI](https://github.com/rosenbjerg/FFMpegCore/workflows/CI/badge.svg)](https://github.com/rosenbjerg/FFMpegCore/actions?query=workflow%3ACI)
|
|
||||||
[![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/)
|
[![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/)
|
||||||
[![GitHub issues](https://img.shields.io/github/issues/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/issues)
|
[![GitHub issues](https://img.shields.io/github/issues/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/issues)
|
||||||
[![GitHub stars](https://img.shields.io/github/stars/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/stargazers)
|
[![GitHub stars](https://img.shields.io/github/stars/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/stargazers)
|
||||||
[![GitHub](https://img.shields.io/github/license/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/blob/master/LICENSE)
|
[![GitHub](https://img.shields.io/github/license/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/blob/master/LICENSE)
|
||||||
|
[![CI](https://github.com/rosenbjerg/FFMpegCore/workflows/CI/badge.svg)](https://github.com/rosenbjerg/FFMpegCore/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
# Setup
|
A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications. Supports both synchronous and asynchronous calls
|
||||||
|
|
||||||
#### NuGet:
|
|
||||||
|
|
||||||
```
|
|
||||||
Install-Package FFMpegCore
|
|
||||||
```
|
|
||||||
|
|
||||||
A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your C# applications. Support both synchronous and asynchronous use
|
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
||||||
## FFProbe
|
## FFProbe
|
||||||
|
|
||||||
FFProbe is used to gather media information:
|
Use FFProbe to analyze media files:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var mediaInfo = FFProbe.Analyse(inputPath);
|
var mediaInfo = await FFProbe.AnalyseAsync(inputPath);
|
||||||
```
|
```
|
||||||
or
|
or
|
||||||
```csharp
|
```csharp
|
||||||
var mediaInfo = await FFProbe.AnalyseAsync(inputPath);
|
var mediaInfo = FFProbe.Analyse(inputPath);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## FFMpeg
|
## FFMpeg
|
||||||
FFMpeg is used for converting your media files to web ready formats.
|
Use FFMpeg to convert your media files.
|
||||||
Easily build your FFMpeg arguments using the fluent argument builder:
|
Easily build your FFMpeg arguments using the fluent argument builder:
|
||||||
|
|
||||||
Convert input file to h264/aac scaled to 720p w/ faststart, for web playback
|
Convert input file to h264/aac scaled to 720p w/ faststart, for web playback
|
||||||
|
@ -49,15 +41,6 @@ FFMpegArguments
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
```
|
```
|
||||||
|
|
||||||
Easily capture screens from your videos:
|
|
||||||
```csharp
|
|
||||||
// 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));
|
|
||||||
```
|
|
||||||
|
|
||||||
Convert to and/or from streams
|
Convert to and/or from streams
|
||||||
```csharp
|
```csharp
|
||||||
await FFMpegArguments
|
await FFMpegArguments
|
||||||
|
@ -68,7 +51,19 @@ await FFMpegArguments
|
||||||
.ProcessAsynchronously();
|
.ProcessAsynchronously();
|
||||||
```
|
```
|
||||||
|
|
||||||
Join video parts into one single file:
|
## Helper methods
|
||||||
|
The provided helper methods makes it simple to perform common operations.
|
||||||
|
|
||||||
|
### Easily capture snapshots from a video file:
|
||||||
|
```csharp
|
||||||
|
// 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:
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.Join(@"..\joined_video.mp4",
|
FFMpeg.Join(@"..\joined_video.mp4",
|
||||||
@"..\part1.mp4",
|
@"..\part1.mp4",
|
||||||
|
@ -77,7 +72,7 @@ FFMpeg.Join(@"..\joined_video.mp4",
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
Join images into a video:
|
### Join images into a video:
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.JoinImageSequence(@"..\joined_video.mp4", frameRate: 1,
|
FFMpeg.JoinImageSequence(@"..\joined_video.mp4", frameRate: 1,
|
||||||
ImageInfo.FromPath(@"..\1.png"),
|
ImageInfo.FromPath(@"..\1.png"),
|
||||||
|
@ -86,22 +81,22 @@ FFMpeg.JoinImageSequence(@"..\joined_video.mp4", frameRate: 1,
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
Mute videos:
|
### Mute the audio of a video file:
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.Mute(inputPath, outputPath);
|
FFMpeg.Mute(inputPath, outputPath);
|
||||||
```
|
```
|
||||||
|
|
||||||
Save audio track from video:
|
### Extract the audio track from a video file:
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.ExtractAudio(inputPath, outputPath);
|
FFMpeg.ExtractAudio(inputPath, outputPath);
|
||||||
```
|
```
|
||||||
|
|
||||||
Add or replace audio track on video:
|
### Add or replace the audio track of a video file:
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.ReplaceAudio(inputPath, inputAudioPath, outputPath);
|
FFMpeg.ReplaceAudio(inputPath, inputAudioPath, outputPath);
|
||||||
```
|
```
|
||||||
|
|
||||||
Add poster image to audio file (good for youtube videos):
|
### Combine an image with audio file, for youtube or similar platforms
|
||||||
```csharp
|
```csharp
|
||||||
FFMpeg.PosterWithAudio(inputPath, inputAudioPath, outputPath);
|
FFMpeg.PosterWithAudio(inputPath, inputAudioPath, outputPath);
|
||||||
// or
|
// or
|
||||||
|
@ -111,26 +106,27 @@ image.AddAudio(inputAudioPath, outputPath);
|
||||||
|
|
||||||
Other available arguments could be found in `FFMpegCore.Arguments` namespace.
|
Other available arguments could be found in `FFMpegCore.Arguments` namespace.
|
||||||
|
|
||||||
### Input piping
|
## 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 us to convert video on-the-fly while frames are being generated or received.
|
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.
|
||||||
|
|
||||||
The `IPipeSource` interface is used as the source of data. It could be represented as encoded video stream or raw frames stream. Currently, the `IPipeSource` interface has single implementation, `RawVideoPipeSource` that is used for raw stream encoding.
|
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.
|
||||||
|
|
||||||
For example:
|
### Working with raw video frames
|
||||||
|
|
||||||
Method that is generating bitmap frames:
|
Method for generating bitmap frames:
|
||||||
```csharp
|
```csharp
|
||||||
IEnumerable<IVideoFrame> CreateFrames(int count)
|
IEnumerable<IVideoFrame> CreateFrames(int count)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < count; i++)
|
for(int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
yield return GetNextFrame(); //method of generating new frames
|
yield return GetNextFrame(); //method that generates of receives the next frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Then create `ArgumentsContainer` with `InputPipeArgument`
|
|
||||||
|
Then create a `RawVideoPipeSource` that utilises your video frame source
|
||||||
```csharp
|
```csharp
|
||||||
var videoFramesSource = new RawVideoPipeSource(CreateFrames(64)) //pass IEnumerable<IVideoFrame> or IEnumerator<IVideoFrame> to constructor of RawVideoPipeSource
|
var videoFramesSource = new RawVideoPipeSource(CreateFrames(64))
|
||||||
{
|
{
|
||||||
FrameRate = 30 //set source frame rate
|
FrameRate = 30 //set source frame rate
|
||||||
};
|
};
|
||||||
|
@ -141,51 +137,43 @@ await FFMpegArguments
|
||||||
.ProcessAsynchronously();
|
.ProcessAsynchronously();
|
||||||
```
|
```
|
||||||
|
|
||||||
if you want to use `System.Drawing.Bitmap` as `IVideoFrame`, there is a `BitmapVideoFrameWrapper` wrapper class.
|
If you want to use `System.Drawing.Bitmap`s as `IVideoFrame`s, a `BitmapVideoFrameWrapper` wrapper class is provided.
|
||||||
|
|
||||||
|
|
||||||
## Binaries
|
# Binaries
|
||||||
|
|
||||||
|
## Installation
|
||||||
If you prefer to manually download them, visit [ffbinaries](https://ffbinaries.com/downloads) or [zeranoe Windows builds](https://ffmpeg.zeranoe.com/builds/).
|
If you prefer to manually download them, visit [ffbinaries](https://ffbinaries.com/downloads) or [zeranoe Windows builds](https://ffmpeg.zeranoe.com/builds/).
|
||||||
|
|
||||||
#### Windows
|
### Windows (using choco)
|
||||||
|
command: `choco install ffmpeg -y`
|
||||||
command: `choco install ffmpeg -Y`
|
|
||||||
|
|
||||||
location: `C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin`
|
location: `C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin`
|
||||||
|
|
||||||
#### Mac OSX
|
### Mac OSX
|
||||||
|
|
||||||
command: `brew install ffmpeg mono-libgdiplus`
|
command: `brew install ffmpeg mono-libgdiplus`
|
||||||
|
|
||||||
location: `/usr/local/bin`
|
location: `/usr/local/bin`
|
||||||
|
|
||||||
#### Ubuntu
|
### Ubuntu
|
||||||
|
|
||||||
command: `sudo apt-get install -y ffmpeg libgdiplus`
|
command: `sudo apt-get install -y ffmpeg libgdiplus`
|
||||||
|
|
||||||
location: `/usr/bin`
|
location: `/usr/bin`
|
||||||
|
|
||||||
|
|
||||||
## Path Configuration
|
## Path Configuration
|
||||||
|
|
||||||
#### Behavior
|
### Option 1
|
||||||
|
|
||||||
If you wish to support multiple client processor architectures, you can do so by creating a folder `x64` and `x86` in the `root` directory.
|
|
||||||
Both folders should contain the binaries (`ffmpeg.exe` and `ffprobe.exe`) for build for the respective architectures.
|
|
||||||
|
|
||||||
By doing so, the library will attempt to use either `/root/{ARCH}/(ffmpeg|ffprobe).exe`.
|
|
||||||
|
|
||||||
If these folders are not defined, it will try to find the binaries in `/root/(ffmpeg|ffprobe.exe)`
|
|
||||||
|
|
||||||
#### Option 1
|
|
||||||
|
|
||||||
The default value of an empty string (expecting ffmpeg to be found through PATH) can be overwritten via the `FFOptions` class:
|
The default value of an empty string (expecting ffmpeg to be found through PATH) can be overwritten via the `FFOptions` class:
|
||||||
|
|
||||||
```c#
|
```csharp
|
||||||
// setting global options
|
// setting global options
|
||||||
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });
|
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });
|
||||||
|
|
||||||
// or
|
// or
|
||||||
GlobalFFOptions.Configure(options => options.BinaryFolder = "./bin");
|
GlobalFFOptions.Configure(options => options.BinaryFolder = "./bin");
|
||||||
|
|
||||||
// on some systems the absolute path may be required, in which case
|
// on some systems the absolute path may be required, in which case
|
||||||
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = Server.MapPath("./bin"), TemporaryFilesFolder = Server.MapPath("/tmp") });
|
GlobalFFOptions.Configure(new FFOptions { BinaryFolder = Server.MapPath("./bin"), TemporaryFilesFolder = Server.MapPath("/tmp") });
|
||||||
|
|
||||||
|
@ -196,9 +184,9 @@ await FFMpegArguments
|
||||||
.ProcessAsynchronously(true, new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });
|
.ProcessAsynchronously(true, new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" });
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Option 2
|
### Option 2
|
||||||
|
|
||||||
The root and temp directory for the ffmpeg binaries can be configured via the `ffmpeg.config.json` file.
|
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.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
@ -207,15 +195,30 @@ The root and temp directory for the ffmpeg binaries can be configured via the `f
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Supporting both 32 and 64 bit processes
|
||||||
|
If you wish to support multiple client processor architectures, you can do so by creating a folder `x64` and `x86` in the `root` directory.
|
||||||
|
Both folders should contain the binaries (`ffmpeg.exe` and `ffprobe.exe`) for build for the respective architectures.
|
||||||
|
|
||||||
|
By doing so, the library will attempt to use either `/root/{ARCH}/(ffmpeg|ffprobe).exe`.
|
||||||
|
|
||||||
|
If these folders are not defined, it will try to find the binaries in `/root/(ffmpeg|ffprobe.exe)`.
|
||||||
|
|
||||||
|
(`.exe` is only appended on Windows)
|
||||||
|
|
||||||
|
|
||||||
# Compatibility
|
# Compatibility
|
||||||
Some versions of FFMPEG might not have the same argument schema. The lib has been tested with version `3.3` to `4.2`
|
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`
|
||||||
|
|
||||||
|
|
||||||
## Contributors
|
## Code contributors
|
||||||
<a href="https://github.com/rosenbjerg/ffmpegcore/graphs/contributors">
|
<a href="https://github.com/rosenbjerg/ffmpegcore/graphs/contributors">
|
||||||
<img src="https://contrib.rocks/image?repo=rosenbjerg/ffmpegcore" />
|
<img src="https://contrib.rocks/image?repo=rosenbjerg/ffmpegcore" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
## Non-code 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
|
### License
|
||||||
|
|
||||||
Copyright © 2021
|
Copyright © 2021
|
||||||
|
|
Loading…
Reference in a new issue