# devfullcycle/video-converter architecture

> Architecture diagram of the GitHub repository devfullcycle/video-converter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devfullcycle/video-converter
- Repository: https://github.com/devfullcycle/video-converter

## Overview

1. **Project shape**
   - This is a **Go command-line tool**, not a service or library.
   - Its job is to batch-convert videos from an input tree to an output tree by orchestrating **`ffmpeg`** subprocesses.

2. **Startup and configuration boundary**
   - `main.go` is the entrypoint.
   - `internal/config` merges configuration from three sources, in this precedence order: **flags > `.env` > defaults**.
   - The config layer controls input/output paths, encoder choice, codec, quality, FPS, scaling, overwrite behavior, and other operational knobs.

3. **File discovery**
   - `internal/discover` walks `INPUT_DIR` recursively and identifies convertible media files.
   - This subsystem defines the boundary between “filesystem scanning” and “conversion work.”
   - It is responsible for producing the list of inputs that become conversion jobs.

4. **Job planning and path mapping**
   - `internal/convert/job.go` represents the per-file conversion unit.
   - The converter maps each source file to a destination under `<OUTPUT_DIR>/<input-folder>_CONV/`, while preserving subfolder structure.
   - This layer also enforces the “skip already converted files unless overwrite is enabled” behavior.

5. **Execution engine**
   - `internal/convert/runner.go` is the orchestration layer for actually processing jobs.
   - It uses a **worker pool** with `errgroup` and `context` for bounded concurrency and cancellation.
   - This is the main dataflow fan-out/fan-in point: discovered files become jobs, jobs run in parallel, results are collected into a report.

6. **Encoder subsystem**
   - `internal/encoder` is a self-contained backend abstraction around `ffmpeg` video encoders.
   - It includes hardware backends for **NVIDIA NVENC, Intel QSV, AMD AMF, VAAPI, and Apple VideoToolbox**, plus a **CPU fallback**.
   - The abstraction is centered on a backend interface and backend registry, so new encoders can be added without changing the runner.

7. **Automatic backend selection and probe**
   - The repo does not just “pick a backend by config”; it first performs a **real functional probe**.
   - `internal/encoder/probe.go` and `select.go` try the preferred or auto-detected backend, encode a test frame, and fall back if the GPU/driver path fails.
   - The architecture guarantees a final fallback to CPU encoders such as **libx264 / libx265 / SVT-AV1**.

8. **Codec and quality policy**
   - `internal/encoder/profile.go`, `quality.go`, and `filters.go` translate high-level settings into concrete `ffmpeg` arguments.
   - This layer is where the tool decides how to apply FPS limiting, scaling, codec selection (`h264`, `hevc`, `av1`), and quality targets.
   - Audio is intentionally kept out of the re-encode path: it is always copied with `-c:a copy`.

9. **Conversion boundary to external tooling**
   - All actual media processing happens outside the Go process, via **`ffmpeg`**.
   - The Go code is responsible for choosing the backend, building the command line, launching the process, and handling success/failure.
   - The requirement that `ffmpeg` be installed and on `PATH` is therefore a hard runtime dependency.

10. **Reporting**
   - `internal/report/report.go` collects and presents the outcome of discovery and conversion.
   - This is the final fan-in point for progress/status information: what was chosen, what converted successfully, what was skipped, and what failed.

11. **Fallback and safety model**
   - The architecture is designed to be resilient: if a hardware backend is unavailable, it automatically degrades to a working backend.
   - `context` cancellation and the overwrite/skip logic help avoid corrupt partial outputs and unnecessary reruns.

12. **Testing and CI**
   - The repo includes unit tests around config, discovery, encoder selection, and runner behavior.
   - There is also CI under `.github/workflows/ci.yml`, so the codebase is intended to be validated automatically, not just run locally.

13. **How to draw the main diagram**
   - The core flow is: **config → encoder detection/probe → file discovery → job creation → concurrent ffmpeg execution → report**.
   - The main architectural boundaries are:
     - **configuration vs execution**
     - **filesystem discovery vs conversion planning**
     - **encoder selection vs conversion runtime**
     - **Go orchestration vs external `ffmpeg` processing**

Main entry points: [`internal/encoder/backend.go`](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/backend.go) (Backend API), [`internal/encoder/select.go`](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/select.go) (Backend select), [`internal/config/config.go`](https://github.com/devfullcycle/video-converter/blob/main/internal/config/config.go) (Config), [`internal/convert/runner.go`](https://github.com/devfullcycle/video-converter/blob/main/internal/convert/runner.go) (Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Startup & config"]
  node_n1["main<br/>CLI entrypoint<br/>[main.go]"]
  node_n2["Config<br/>settings merge<br/>[config.go]"]
end

subgraph group_g2["Discovery & planning"]
  node_n3["Discover<br/>file scan<br/>[discover.go]"]
  node_n4["Job map<br/>path planner<br/>[job.go]"]
end

subgraph group_g3["Conversion runtime"]
  node_n5["Runner<br/>worker pool<br/>[runner.go]"]
end

subgraph group_g4["Encoder backend"]
  node_n7["Backend select<br/>encoder chooser<br/>[select.go]"]
  node_n8["Probe<br/>ffmpeg test<br/>[probe.go]"]
  node_n9["Detect<br/>[detect.go]"]
  node_n10["Profile<br/>codec policy<br/>[profile.go]"]
  node_n11["Quality<br/>rate control<br/>[quality.go]"]
  node_n12["Filters<br/>ffmpeg args<br/>[filters.go]"]
  node_n13["Backend API<br/>backend interface<br/>[backend.go]"]
  node_n14["NVENC<br/>gpu backend<br/>[nvenc.go]"]
  node_n15["QSV<br/>gpu backend<br/>[qsv.go]"]
  node_n16["AMF<br/>gpu backend<br/>[amf.go]"]
  node_n17["VAAPI<br/>gpu backend<br/>[vaapi.go]"]
  node_n18["VideoToolbox<br/>gpu backend<br/>[videotoolbox.go]"]
  node_n19["CPU fallback<br/>software backend<br/>[cpu.go]"]
end

subgraph group_g5["Reporting"]
  node_n6["Report<br/>result summary<br/>[report.go]"]
end

subgraph group_g6["External tools"]
  node_n20["ffmpeg<br/>external binary"]
end

node_n1 -->|"loads config"| node_n2
node_n1 -->|"initializes encoder"| node_n7
node_n1 -->|"starts scan"| node_n3
node_n3 -->|"emits paths"| node_n4
node_n2 -->|"input/output roots"| node_n3
node_n2 -->|"overwrite policy"| node_n4
node_n2 -->|"runtime knobs"| node_n5
node_n2 -->|"codec settings"| node_n7
node_n4 -->|"job stream"| node_n5
node_n5 -->|"selects backend"| node_n7
node_n5 -->|"spawns process"| node_n20
node_n7 -->|"probes candidate"| node_n8
node_n7 -->|"detects hardware"| node_n9
node_n7 -->|"applies profile"| node_n10
node_n10 -->|"sets quality"| node_n11
node_n10 -->|"builds filters"| node_n12
node_n13 -->|"registers"| node_n14
node_n13 -->|"registers"| node_n15
node_n13 -->|"registers"| node_n16
node_n13 -->|"registers"| node_n17
node_n13 -->|"registers"| node_n18
node_n13 -->|"registers"| node_n19
node_n8 -->|"tests encode"| node_n20
node_n5 -->|"reports results"| node_n6
node_n3 -->|"discovery summary"| node_n6

click node_n1 "https://github.com/devfullcycle/video-converter/blob/main/main.go"
click node_n2 "https://github.com/devfullcycle/video-converter/blob/main/internal/config/config.go"
click node_n3 "https://github.com/devfullcycle/video-converter/blob/main/internal/discover/discover.go"
click node_n4 "https://github.com/devfullcycle/video-converter/blob/main/internal/convert/job.go"
click node_n5 "https://github.com/devfullcycle/video-converter/blob/main/internal/convert/runner.go"
click node_n6 "https://github.com/devfullcycle/video-converter/blob/main/internal/report/report.go"
click node_n7 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/select.go"
click node_n8 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/probe.go"
click node_n9 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/detect.go"
click node_n10 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/profile.go"
click node_n11 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/quality.go"
click node_n12 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/filters.go"
click node_n13 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/backend.go"
click node_n14 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/nvenc.go"
click node_n15 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/qsv.go"
click node_n16 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/amf.go"
click node_n17 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/vaapi.go"
click node_n18 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/videotoolbox.go"
click node_n19 "https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/cpu.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2 toneBlue
class node_n3,node_n4 toneAmber
class node_n5 toneMint
class node_n7,node_n8,node_n9,node_n10,node_n11,node_n12,node_n13,node_n14,node_n15,node_n16,node_n17,node_n18,node_n19 toneRose
class node_n6 toneIndigo
class node_n20 toneTeal
```

## Components

### Startup & config

Entry and operational settings

- [main](https://github.com/devfullcycle/video-converter/blob/main/main.go): CLI entrypoint · Starts the tool and wires the top-level workflow · `main.go`
- [Config](https://github.com/devfullcycle/video-converter/blob/main/internal/config/config.go): settings merge · Combines defaults, .env, and flags into runtime settings · `internal/config/config.go`

### Discovery & planning

Filesystem scanning and job mapping

- [Discover](https://github.com/devfullcycle/video-converter/blob/main/internal/discover/discover.go): file scan · Recursively finds convertible media files under the input tree · `internal/discover/discover.go`
- [Job map](https://github.com/devfullcycle/video-converter/blob/main/internal/convert/job.go): path planner · Maps each source file to its output destination and skip rules · `internal/convert/job.go`

### Conversion runtime

Concurrent execution of conversion jobs

- [Runner](https://github.com/devfullcycle/video-converter/blob/main/internal/convert/runner.go): worker pool · Runs conversion jobs with bounded concurrency and cancellation · `internal/convert/runner.go`

### Encoder backend

Backend selection, probing, and ffmpeg argument synthesis

- [Backend select](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/select.go): encoder chooser · Chooses the preferred or fallback encoder backend · `internal/encoder/select.go`
- [Probe](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/probe.go): ffmpeg test · Functionally probes candidate backends before use · `internal/encoder/probe.go`
- [Detect](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/detect.go): backend detection · Detects available hardware acceleration paths · `internal/encoder/detect.go`
- [Profile](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/profile.go): codec policy · Translates high-level encoding mode into concrete backend choices · `internal/encoder/profile.go`
- [Quality](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/quality.go): rate control · Derives quality targets and encoder-specific options · `internal/encoder/quality.go`
- [Filters](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/filters.go): ffmpeg args · Builds FPS and scaling filter arguments · `internal/encoder/filters.go`
- [Backend API](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/backend.go): backend interface · Defines the encoder backend contract and registry boundary · `internal/encoder/backend.go`
- [NVENC](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/nvenc.go): gpu backend · NVIDIA hardware encoding backend · `internal/encoder/nvenc.go`
- [QSV](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/qsv.go): gpu backend · Intel hardware encoding backend · `internal/encoder/qsv.go`
- [AMF](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/amf.go): gpu backend · AMD hardware encoding backend · `internal/encoder/amf.go`
- [VAAPI](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/vaapi.go): gpu backend · Linux VAAPI hardware encoding backend · `internal/encoder/vaapi.go`
- [VideoToolbox](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/videotoolbox.go): gpu backend · Apple hardware encoding backend · `internal/encoder/videotoolbox.go`
- [CPU fallback](https://github.com/devfullcycle/video-converter/blob/main/internal/encoder/cpu.go): software backend · CPU encoder fallback such as libx264, libx265, or SVT-AV1 · `internal/encoder/cpu.go`

### Reporting

Outcome aggregation and presentation

- [Report](https://github.com/devfullcycle/video-converter/blob/main/internal/report/report.go): result summary · Collects successes, skips, failures, and final status · `internal/report/report.go`

### External tools

Native subprocess dependency

- **ffmpeg**: external binary · Actual media processing engine launched as a subprocess

## Connections

- main → Config: loads config · Startup resolves runtime settings before work begins
- main → Backend select: initializes encoder · Main workflow prepares backend selection and probing
- main → Discover: starts scan · Begins filesystem discovery of convertible files
- Discover → Job map: emits paths · Discovered files become planned conversion jobs
- Config → Discover: input/output roots · Discovery uses configured input tree
- Config → Job map: overwrite policy · Planning honors destination mapping and skip rules
- Config → Runner: runtime knobs · Concurrency and conversion behavior come from config
- Config → Backend select: codec settings · Selected codec, quality, fps, and scale influence backend choice
- Job map → Runner: job stream · Planned jobs are handed to the execution engine
- Runner → Backend select: selects backend · Runner delegates encoder choice per job
- Runner → ffmpeg: spawns process · Runner invokes ffmpeg for each conversion
- Backend select → Probe: probes candidate · Selection validates a backend with a real encode test
- Backend select → Detect: detects hardware · Selection uses detection signals to prioritize backends
- Backend select → Profile: applies profile · Backend choice is shaped by codec profile
- Profile → Quality: sets quality · Profiles feed rate-control policy
- Profile → Filters: builds filters · Profiles also determine filter construction
- Backend API → NVENC: registers · Backend interface is implemented by NVENC
- Backend API → QSV: registers · Backend interface is implemented by QSV
- Backend API → AMF: registers · Backend interface is implemented by AMF
- Backend API → VAAPI: registers · Backend interface is implemented by VAAPI
- Backend API → VideoToolbox: registers · Backend interface is implemented by VideoToolbox
- Backend API → CPU fallback: registers · Backend interface includes CPU fallback implementations
- Probe → ffmpeg: tests encode · Probe verifies a backend by running ffmpeg
- Runner → Report: reports results · Final job outcomes are aggregated for presentation
- Discover → Report: discovery summary · Report includes scan outcomes and skipped inputs
