Raveler/ffmpeg-cpp

A clean, easy-to-use C++ wrapper around the ffmpeg libraries

What it is

ffmpeg-cpp is a C++ library that wraps the FFmpeg libraries, giving you a clean, easy-to-use interface for common video/audio tasks (like reading, filtering, encoding, and writing media files). Instead of running the FFmpeg command-line tool, you call C++ functions directly. It also includes a simplified interface that can be called from C# projects via DllImport.

What it does

With just a few lines of C++ you can, for example, load a video file, apply a filter (like scaling or rotation), and save it to a new file. The README shows a full pipeline: demuxing (reading the container), decoding, filtering, encoding, and muxing (writing out).

How you get it

  • Platform: Only Windows with Visual Studio is officially supported right now. The author says the code is platform‑independent but they lack CMake/Linux experience, so no Linux build is available yet.
  • Install: Clone the repo, download the appropriate FFmpeg dev (for headers and import libs) and shared (for DLLs) builds from Zeranoe (tested with FFmpeg 4.1), extract them into the ffmpeg folder, then open the Visual Studio solution and build. That produces a .lib and an include folder to use in your own projects.

How you use it

In C++

You create objects like Muxer, VideoCodec, VideoEncoder, Filter, and Demuxer to build a processing pipeline. The README shows a complete example where you:

  1. Create a muxer for the output file.
  2. Create a codec (e.g., MPEG‑2) and an encoder.
  3. Create a filter (e.g., scale=640:150,transpose=cclock,vignette) and attach the encoder.
  4. Load an input file with a demuxer and send its best video stream to the filter.
  5. Prepare the pipeline, then step through frames until done, and close the muxer to finalize.

There’s also a simplified interface that lowers complexity – you just create a handle, add video/audio streams and filters, and call ffmpegCppGenerate. This interface is what makes C# interop easy.

In C#

The simple interface is exposed as a DLL (simple_interface.dll) with C‑style functions. The README provides a full C# example using [DllImport] to call functions like ffmpegCppCreate, ffmpegCppAddVideoStream, ffmpegCppAddVideoFilter, ffmpegCppGenerate, etc. Error checking is done via ffmpegCppIsError and ffmpegCppGetError.

Why it exists

The author needed to integrate FFmpeg into a program without launching the FFmpeg executable as a separate process. That’s because starting an external executable can be blocked by antivirus software and can cause other issues. By linking the FFmpeg libraries directly, the functionality is embedded in your app.

Limitations & future plans

  • Platform support: Currently Windows only. The roadmap mentions adding Linux/Mac build support.
  • Testing: The project is tested for common functionality, but proper unit tests are not yet in place.
  • Codec/container coverage: It has been tested with some, but the roadmap calls for testing with more codecs and containers.

License

This library is licensed under the LGPL. However, FFmpeg itself is either LGPL or GPL depending on how you build it. If you use the GPL version of FFmpeg, your project using ffmpeg-cpp must also be GPL.


All information above is taken directly from the project’s README. Nothing else is added or inferred.

Related

  • Project
  • Project
  • Project
  • Project