This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make build- Build the binary to./build/media-convertermake build-local- Build for local development as./media-convertermake dev- Quick development build (clean, deps, build-local)make cross-compile- Build for multiple platforms (macOS, Linux, Windows)
make test- Run all testsmake test-coverage- Run tests with coverage reportmake check- Run formatting, vetting, and testsmake lint- Run formatting and go vetmake fmt- Format Go codemake vet- Run go vet
make deps- Download and tidy dependenciesmake clean- Clean build artifacts
make run- Build locally and run with --dry-run --help./media-converter --dry-run /source /dest- Test run without conversion./media-converter /source /dest- Basic conversion
This is a secure, parallel media converter written in Go that converts images to modern formats (AVIF, WebP) and videos to efficient codecs (H.265, AV1).
Entry Point: main.go → cmd/root.go - CLI interface using Cobra
Configuration: internal/config/ - Viper-based config with YAML file support ($HOME/.media-converter.yaml)
Conversion Engine: internal/converter/ - Main conversion orchestrator with parallel processing
Security Layer: internal/security/ - Disk space checks, file integrity verification, timeouts
Logging: internal/logger/ - Structured logging to console and file
Utilities: internal/utils/ - File handling, dependency checks, format detection
Converter (internal/converter/converter.go):
- Orchestrates the entire conversion process
- Manages worker pools with semaphores for parallel processing
- Tracks progress and statistics
- Runs safety tests before batch processing
Image Conversion (internal/converter/image.go):
- Handles photo conversions using ImageMagick
- Supports AVIF and WebP output formats
- Quality settings per format
Video Conversion (internal/converter/video.go):
- Handles video conversions using FFmpeg
- Progress tracking with time-based progress bars
- AWS S3 cost estimation
- Supports H.265, H.264, AV1 codecs
Security Checker (internal/security/security.go):
- File integrity verification
- Disk space monitoring (platform-specific implementations)
- Conversion timeouts
- Output file validation
- Initialization: Validate directories, check dependencies, initialize logger
- Safety Test: Test conversion on a sample file (unless dry-run)
- File Discovery: Walk source directory and categorize files by type
- Parallel Conversion: Use worker pools to convert files concurrently
- Progress Tracking: Real-time progress bars and ETA calculations
- Final Report: Statistics, timing, and cost estimations
The application uses a layered configuration approach:
- Default values in code
- YAML config file (
$HOME/.media-converter.yaml) - Environment variables
- Command line flags (highest priority)
All configuration is managed through Viper and bound to Cobra flags.
Required External Tools:
- FFmpeg (video conversion)
- ImageMagick (image conversion)
Go Dependencies:
github.com/spf13/cobra- CLI frameworkgithub.com/spf13/viper- Configuration managementgithub.com/sirupsen/logrus- Logginggithub.com/fatih/color- Colored outputgolang.org/x/sync- Semaphore for worker pools
Output Structure: Files are organized by date (YYYY/MM-Month/YYYY-MM-DD/) with separate images/ and videos/ subdirectories. Month names support multiple languages (EN, FR, ES, DE).
Logging: All operations are logged to {destination}/conversion.log with detailed timing and error information.
Security: The application prioritizes safety with multiple verification steps, timeouts, and optional original file preservation.
This converter is designed to be 100% safe and idempotent:
- Run multiple times safely - already converted files are automatically skipped via existence and integrity checks
- Resume after interruption - Ctrl+C, crashes, or failures can be resumed by re-running the same command
- Atomic conversions - files are converted to
.tmpthen renamed atomically, never overwriting originals during conversion
- Originals preserved by default (
--keep-originals=true) - Triple verification before deletion: file exists, integrity check, size validation
- Processing markers (
.processingfiles) track active conversions with PID/timestamp - Automatic recovery - detects and cleans up abandoned files from crashed processes
- Corruption detection - automatically re-converts files that fail integrity checks
The converter includes comprehensive recovery mechanisms in internal/security/security.go:
FindAbandonedMarkers()- detects processing markers from dead processesCleanupAbandonedFiles()- removes.tmpfiles and abandoned markersIsFileCorrupted()- validates existing files and marks for re-conversionVerifyOutputFile()- comprehensive integrity verification using external tools
When resuming after interruption, the converter automatically:
- Skips files that were already converted successfully
- Cleans up temporary files from interrupted conversions
- Re-converts any files that were partially processed or corrupted
- Continues from where it left off
Critical for file organization: dates are extracted from file metadata (EXIF, video metadata) NOT filesystem timestamps. The utils.GetFileDate() function tries multiple methods in priority order:
- macOS
mdlsmetadata (most reliable for RAW files) - EXIF data via ImageMagick (
EXIF:DateTimeOriginal) - Video metadata via FFmpeg (
creation_time) - File modification time (fallback, with validation)
This ensures files are organized by their actual creation date, not when they were copied or modified.