Object-oriented FFmpeg API wrappers (powered by FFmpeg.AutoGen).
Using the ffmpeg API tends to be tedious and error prone, mainly due to the extensive need for struct setup and manual error checking.
This library aims to abstract away most of such code while still exposing pointers in order to allow for lower-level control.
Executable code samples are available in the samples directory.
- Thumbnail Extractor (video decoding, seeking)
- Encoding procedurally generated audio and video
- Encoding SkiaSharp bitmaps (swscaler color conversion)
- Hardware decoding and toy OpenGL player
- Hardware encoding
- Audio and video transcoding
Note ffmpeg binaries must be manually copied to the build directory, or specified though ffmpeg.RootPath
as explained here.
using var muxer = new MediaMuxer("output.mp4");
using var frame = new VideoFrame(1280, 720, PixelFormats.YUV420P);
using var encoder = new VideoEncoder(CodecIds.H264, frame.Format, frameRate: 24.0, bitrate: 900_000);
encoder.SetOption("preset", "faster"); //libx264 specific
var stream = muxer.AddStream(encoder);
muxer.Open();
for (int i = 0; i < 24 * 10; i++) { //Encode 10s of video
frame.PresentationTimestamp = encoder.GetFramePts(frameNumber: i); //Based on framerate. Alt overload takes TimeSpan.
// ... fill `frame` with something interesting ...
muxer.EncodeAndWrite(stream, encoder, frame); //all-in-one: send_frame(), receive_packet(), rescale_ts(), write_interleaved()
}
muxer.EncodeAndWrite(stream, encoder, null); //flush delayed frames in the encoder