How devfullcycle/video-converter works
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: backend.go Backend API · select.go Backend select · config.go Config · runner.go Runner
Components 20
Startup & config
Entry and operational settings
Discovery & planning
Filesystem scanning and job mapping
Conversion runtime
Concurrent execution of conversion jobs
- Runner · Runs conversion jobs with bounded concurrency and cancellation
internal/convert/runner.go
Encoder backend
Backend selection, probing, and ffmpeg argument synthesis
- Backend select · Chooses the preferred or fallback encoder backend
internal/encoder/select.go - Probe · Functionally probes candidate backends before use
internal/encoder/probe.go - Detect · Detects available hardware acceleration paths
internal/encoder/detect.go - Profile · Translates high-level encoding mode into concrete backend choices
internal/encoder/profile.go - Quality · Derives quality targets and encoder-specific options
internal/encoder/quality.go - Filters · Builds FPS and scaling filter arguments
internal/encoder/filters.go - Backend API · Defines the encoder backend contract and registry boundary
internal/encoder/backend.go - NVENC · NVIDIA hardware encoding backend
internal/encoder/nvenc.go - QSV · Intel hardware encoding backend
internal/encoder/qsv.go - AMF · AMD hardware encoding backend
internal/encoder/amf.go - VAAPI · Linux VAAPI hardware encoding backend
internal/encoder/vaapi.go - VideoToolbox · Apple hardware encoding backend
internal/encoder/videotoolbox.go - CPU fallback · CPU encoder fallback such as libx264, libx265, or SVT-AV1
internal/encoder/cpu.go
Reporting
Outcome aggregation and presentation
- Report · Collects successes, skips, failures, and final status
internal/report/report.go
External tools
Native subprocess dependency
- ffmpeg · Actual media processing engine launched as a subprocess
Connections 25
- 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