Skip to content

lex0127316/ffmpeg-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FFmpeg Call Scanner

Overview

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).

Build Instructions

  1. 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.
  2. 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.

Usage

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

analyze a TU using a compile database in ./build

ffmpeg_tool.exe -p build path/to/source.cpp

forward extra arguments to Clang

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.

Example Output

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" ] } } ]

Testing

Minimal C sample

  1. Build the tool with Ninja to get a compile database.
  2. Run:
  • powershell ffmpeg-tool\build-ninja\ffmpeg_tool.exe -p ffmpeg-tool/build-ninja ffmpeg-tool/examples/example_ffmpeg_test.c

rpan-studio integration

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-studio rpan-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.

Limitations & Future Work

  • 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::run with 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors