The Problem
Developers need a ready‑to‑run pipeline for face‑swap, enhancement, and related video/audio processing. Existing scripts are scattered across many modules, making it hard to trace execution, manage dependencies, and ensure security.
What This Does
facefusion/ implements the full stack: UI components (facefusion/uis/*), processing modules (facefusion/processors/modules/*), and job orchestration (facefusion/jobs/*). The top‑level script facefusion.py simply forwards CLI arguments to the core entry point in facefusion/core.py. Core functions such as create_job, run, render, and pre_check drive the workflow, while helper modules (common_helper.py, filesystem.py, state_manager.py) provide cross‑cutting utilities.
How It Is Wired
| Entry point | File & line | Reach |
|---|---|---|
| cli | facefusion/core.py:33 | 401 functions |
| run | facefusion/benchmarker.py:34 | 399 functions |
| start | facefusion/process_manager.py:36 | 67 functions |
The CLI (cli) parses arguments and calls run (the benchmark runner) which in turn:
- Calls
pre_check→create_static_model_set→resolve_relative_path(172 calls) andresolve_download_url(168 calls). - Uses
get_item(called from 117 locations) to fetch UI components, job definitions, and model files. - Invokes
ffmpeg.run_ffmpeg(viafacefusion/ffmpeg.py) which spawns a subprocess (subprocess.Popen). - Generates a hash with
hashlib.sha1().hexdigestinsuggest_output_path(cryptographic operation).
The hub module facefusion/__init__.py is imported by 91 other modules, making it the highest‑impact change point. State is stored in facefusion/state_manager.py (7 functions, referenced by 67 files) and persisted via facefusion/filesystem.py (27 functions, 35 callers). Job lifecycle (create_job, submit_job, run_job) lives in facefusion/jobs/job_manager.py (27 functions, 15 callers).
External effects:
- Subprocess execution (
ffmpeg.run_ffmpeg,subprocess.call) – 42 functions. - File I/O – 4 functions (
open_stream,open_ffmpeg, etc.). - Cryptographic hash – 1 function (
suggest_output_path).
No circular imports were detected; the import graph is a clean DAG of 167 modules and 712 edges.
How To Use It
# Clone the repo
git clone https://github.com/moses-y/faceswap.git
cd faceswap
# Install Python dependencies (no lockfile, so use a virtualenv)
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
The primary command line is documented in the README:
python facefusion.py run # normal run
python facefusion.py headless-run # headless mode
python facefusion.py benchmark # benchmark suite
Configuration files such as facefusion.ini and facefusion.ico are read by facefusion/config.py. No additional environment variables are required for a basic run.
Real‑World Use
A media‑production pipeline can invoke the CLI from a CI step to generate a swapped‑face video:
- name: Generate swap
run: |
source .venv/bin/activate
python facefusion.py run --input source.mp4 --output out.mp4 --job face_swapper
The job manager records the job in the internal state store, and ffmpeg streams the processed frames to out.mp4.
Code Health & Issues
- Critical –
gradio==5.42.0andonnx==1.19.0have known CVEs (CVE‑2026‑27167, CVE‑2026‑28500). Upgrade to fixed versions and add a lockfile. - High – GitHub Actions reference tags (
AnimMouse/setup-ffmpeg@v1). Pin to commit SHA to prevent supply‑chain drift. - Medium – No explicit
permissionsforGITHUB_TOKEN; addpermissions: contents: read. - Medium – No Dependabot/Renovate config; add
.github/dependabot.yml. - Medium – No dependency‑vulnerability scan in CI; integrate
dependency-review-actionorosv-scanner. - Medium –
actions/checkoutleaves the token persisted; setpersist-credentials: false. - Low – Workflow jobs lack
timeout-minutes; define reasonable limits.
Additional static findings (selected):
- Hub module (
facefusion/__init__.py) is imported by 91 modules – high change impact. - Resource safety –
facefusion/uis/core.pyopens files without a context manager. - Deep nesting – up to 6 levels in
facefusion/download.py,facefusion/face_analyser.py,facefusion/program_helper.py. - Duplicated code – 137 six‑line blocks repeated across 44 files (e.g., benchmark UI and core logic).
The Bottom Line
The repository provides a complete, test‑covered face‑manipulation pipeline but suffers from a few high‑impact security and maintainability risks: outdated pinned dependencies, unpinned CI actions, and a large central module that should be stabilized. It is suitable for teams comfortable with Python and willing to address the critical advisories and refactor the hub module before production deployment.