Merge branch 'feature/piping' of https://github.com/max619/FFMpegCore into feature/piping

Former-commit-id: 5af9aeb926
This commit is contained in:
Максим Багрянцев 2020-04-27 21:22:19 +03:00
commit 6626823ef7

View file

@ -381,6 +381,42 @@ public class OverrideArgument : Argument
}
}
```
### 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 beeing generated/created/processed.
`IPipeSource` interface is used as source of data. It could be represented as encoded video stream or raw frames stream. Currently `IPipeSource` interface has single implementation, `RawVideoPipeSource` that is used for raw stream encoding.
For example:
Method that is generate bitmap frames:
```csharp
IEnumerable<IVideoFrame> CreateFrames(int count)
{
for(int i = 0; i < count; i++)
{
yield return GetNextFrame(); //method of generating new frames
}
}
```
Then create `ArgumentsContainer` with `InputPipeArgument`
```csharp
var videoFramesSource = new RawVideoPipeSource(CreateFrames(64)) //pass IEnumerable<IVideoFrame> or IEnumerator<IVideoFrame> to constructor of RawVideoPipeSource
{
FrameRate = 30 //set source frame rate
};
var container = new ArgumentsContainer
{
new InputPipeArgument(videoFramesSource),
... //Other encoding arguments
new OutputArgument("temporary.mp4")
};
var ffmpeg = new FFMpeg();
var result = ffmpeg.Convert(arguments);
```
if you want to use `System.Drawing.Bitmap` as `IVideoFrame`, there is `BitmapVideoFrameWrapper` wrapper class.
## Contributors
<a href="https://github.com/vladjerca"><img src="https://avatars.githubusercontent.com/u/6339681?v=4" title="vladjerca" width="80" height="80"></a>