Work with raw video frames via Input Piping
mainInput piping allows you to write video frames directly from program memory (e.g., from a generator or a System.Drawing.Bitmap) without saving them to disk first. This is useful for real-time video generation or on-the-fly conversion.
Using RawVideoPipeSource
To use raw frames, implement an IEnumerable<IVideoFrame> and pass it to a RawVideoPipeSource.
- Create a frame generator:
IEnumerable<IVideoFrame> CreateFrames(int count)
{
for(int i = 0; i < count; i++)
{
yield return GetNextFrame();
}
}- Pipe the frames to FFMpeg:
var videoFramesSource = new RawVideoPipeSource(CreateFrames(64))
{
FrameRate = 30
};
await FFMpegArguments
.FromPipeInput(videoFramesSource)
.OutputToFile(outputPath, false, options => options
.WithVideoCodec(VideoCodec.LibVpx))
.ProcessAsynchronously();Note: If you are using System.Drawing.Bitmap, you can wrap them using the BitmapVideoFrameWrapper class.
var videoFramesSource = new RawVideoPipeSource(CreateFrames(64))
{
FrameRate = 30
};
await FFMpegArguments
.FromPipeInput(videoFramesSource)
.OutputToFile(outputPath, false, options => options
.WithVideoCodec(VideoCodec.LibVpx))
.ProcessAsynchronously();