FFmpeg as C++ modules for mcpp — built entirely from source, API unchanged.
import std;
import ffmpeg.av; // the whole FFmpeg surface, Python `import av` style
int main() {
AVFormatContext* fmt { nullptr };
avformat_open_input(&fmt, "video.mp4", nullptr, nullptr);
// ... the exact same C API you already know — just no #include
}- Source build, no CMake/configure at build time. The
compat.ffmpegindex package carries the frozen configure snapshot + exact source list; mcpp compiles all of FFmpeg 8.1.2 (2124.c+ 157 NASM.asm, x86 SIMD included) directly — cold build ≈ 21 s on 32 cores. This repo is only the thin module layer. - API and habits unchanged. Every public function, type, enum, and enum
constant is re-exported under its upstream global name (
avcodec_open2,AVFrame,AV_CODEC_ID_H264, …). - Full-feature profile. All internal components are on: 600+ decoders, 350+ demuxers, encoders, muxers, filters, swscale/swresample — hermetic (no host libraries probed), LGPL-2.1+ clean.
| import | contents |
|---|---|
ffmpeg.av |
everything below (recommended default) |
ffmpeg.avutil / ffmpeg.avcodec / ffmpeg.avformat / ffmpeg.avfilter / ffmpeg.avdevice / ffmpeg.swscale / ffmpeg.swresample |
one library each; dependencies are re-exported (import ffmpeg.avformat; brings avcodec + avutil) |
ffmpeg |
lib-root alias of ffmpeg.av |
Named modules cannot export macros or static inline helpers. Everything
with linkage comes from the import; for the macro spellings (AVERROR,
AV_NOPTS_VALUE, AVIO_FLAG_WRITE, MKTAG, …) and inline utilities
(av_q2d, av_clip, …) add the optional side header before the import:
#include <ffmpeg-m/macros.h>
import ffmpeg.av;C-only compound-literal macros get C++ replacements exported from the
module: av_err2str → av_err2string(err).c_str(), av_ts2str →
av_ts2string, av_ts2timestr → av_ts2timestring, av_fourcc2str →
av_fourcc2string.
[dependencies]
ffmpeg = "0.0.1"Or start from the template: mcpp new myplayer --template ffmpeg (decode
skeleton). Examples: examples/probe (no input needed),
examples/decode_frames.
Validate the package: mcpp build && mcpp test (self-contained
encode→decode roundtrip + API-surface tests).
src/*.cppm module layer (GMF include + export using)
src/gen_exports/ generated export lists + skip reports
include/ffmpeg-m/ optional macros side header
tools/ fetch_upstream.sh (pinned official tarball),
gen_exports.py (headers → export lists)
templates/ examples/ project template + runnable consumers
Upstream sources are NOT vendored: they reach consumers through the
compat.ffmpeg mcpp-index package (official ffmpeg.org tarball, GLOBAL + CN
mirror, sha256-pinned). Its descriptor — config snapshot inlined as
generated_files plus the make -n source list — is maintained in
mcpp-index (tools/compat-ffmpeg/). FFmpeg bump: bump compat.ffmpeg
there first, then update the pin in tools/fetch_upstream.sh, run
python3 tools/gen_exports.py, and review the export-list diffs.
- Hardware-acceleration headers that need external SDKs
(
libavutil/hwcontext_cuda.h, VAAPI, …) are not part of the module export surface; with the SDK present, include them textually next to the import. - Optional variants (external codecs, GPL components, slim profiles) are planned as mcpp features backed by per-profile config snapshots.
- License: this wrapper repo is MIT; the upstream sources arrive via
compat.ffmpegunder LGPL-2.1-or-later (no--enable-gpl/nonfreecomponents); source distribution satisfies LGPL relinking by construction.