ffmpeg_tool is a Clang LibTooling pass that walks C and C++ translation units, records FFmpeg API usages, and emits a JSON report grouped by file and client function. It relies on the single-header nlohmann/json library for serialization and works with any compilation database (compile_commands.json).
- Ensure LLVM/Clang 18.1+ and CMake 3.21+ are installed. On Windows this repo is wired to the prebuilt toolchain in
toolchain/clang+llvm-18.1.8-x86_64-pc-windows-msvc. - Configure with either Visual Studio or Ninja:
- powershell
cmake -S ffmpeg-tool -B ffmpeg-tool/build
-G "Visual Studio 17 2022"-DLLVM_ROOT="F:/Project/Test task/Dominic-test/toolchain/clang+llvm-18.1.8-x86_64-pc-windows-msvc"
cmake --build ffmpeg-tool/build --config Release
or
- powershell
cmake -S ffmpeg-tool -B ffmpeg-tool/build-ninja
-G Ninja-DLLVM_ROOT="F:/Project/Test task/Dominic-test/toolchain/clang+llvm-18.1.8-x86_64-pc-windows-msvc" ` -DCMAKE_BUILD_TYPE=Release
cmake --build ffmpeg-tool/build-ninja
Both builds generate ffmpeg_tool.exe; the Ninja variant additionally writes a compile_commands.json that can be reused by the tool itself.
The binary consumes the same flags as clang-tool. Provide a compilation database via -p (or rely on compile_commands.json in the current directory) and list the source files you want to analyze:
- powershell
ffmpeg_tool.exe -p build path/to/source.cpp
ffmpeg_tool.exe -p build path/to/source.cpp -- -Ithird_party/includes -DUSE_STUBS
The optional --output <file> flag writes the JSON report to disk instead of stdout.
Running against the bundled minimal sample (examples/example_ffmpeg_test.c) produces:
json
[
{
"F:\\Project\\Test task\\Dominic-test\\ffmpeg-tool\\examples\\example_ffmpeg_test.c": {
"main": [
"av_register_all",
"open_media"
],
"open_media": [
"avformat_open_input",
"avformat_find_stream_info",
"avformat_close_input"
]
}
}
]
- Build the tool with Ninja to get a compile database.
- Run:
- powershell
ffmpeg-tool\build-ninja\ffmpeg_tool.exe
-p ffmpeg-tool/build-ninjaffmpeg-tool/examples/example_ffmpeg_test.c
Because rpan-studio depends on FFmpeg development headers that are not present in this environment, a lightweight translation unit tests/ffmpeg_probe.c was added under rpan-studio/ to mirror the project’s FFmpeg usage patterns. The accompanying compile_commands.json drives the LibTooling pass without requiring the full OBS build.
- powershell
ffmpeg-tool\build-ninja\ffmpeg_tool.exe
-p rpan-studiorpan-studio/tests/ffmpeg_probe.c ` --output rpan-studio/ffmpeg-report.json
The resulting JSON lists FFmpeg APIs invoked by open_and_dump, remux_stream, and main inside the repository. For a full build of rpan-studio, regenerate compile_commands.json via its own CMake configuration and point -p to that directory.
- Header stubs. To keep the repository self-contained the tool uses minimal FFmpeg stubs located in
ffmpeg-tool/stubs. They cover the APIs needed for analysis but are not drop-in replacements for the actual SDK. - Direct call matching only. Calls invoked through function pointers, dynamic libraries, or inline assembly are currently ignored.
- Heuristics. Detection is based on symbol prefixes (
av,avio,swr, etc.) and header paths. Additional configuration (YAML/JSON whitelist) would make the scanner more flexible. - No parallelism. The tool iterates serially over translation units. Integrating
ClangTool::runwith a task pool would speed up large projects. - Testing. Unit tests for the visitor/matchers are not yet included. Adding GoogleTest + mocked ASTs would harden the pass.