AngryCarrot789 / FFmpegWrapper

Object-oriented FFmpeg API wrappers (powered by FFmpeg.AutoGen).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FFmpegWrapper

Object-oriented FFmpeg API wrappers (powered by FFmpeg.AutoGen).

GitHub Nuget


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.

Examples

Executable code samples are available in the samples directory.

Note ffmpeg binaries must be manually copied to the build directory, or specified though ffmpeg.RootPath as explained here.

Showcase: Basic video encoding

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

About

Object-oriented FFmpeg API wrappers (powered by FFmpeg.AutoGen).

License:MIT License


Languages

Language:C# 100.0%