How red77290/dmd_gif_converter works
1. Repository shape
- This project is split into three major layers under src/: a conversion engine, an AI-assisted auto-action/video analysis engine, and a cross-platform desktop UI.
- The README makes clear there are also two entry modes: a GUI launcher and a CLI automation path, with the UI depending on optional third-party packages while the core engine is intended to stay lightweight.
2. Primary product goal
- The system transforms source media files—animated GIFs or common video formats—into output optimized for a 128×32 HUB75 LED matrix.
- The important architectural constraint is that the output is not a generic video export; it is tailored for DMD/LED visibility, which drives the color, framing, trimming, and scoring subsystems.
3. Core conversion pipeline
- src/engine/conversion is the main media-processing subsystem.
- It contains the command-line entrypoints, conversion core logic, FFmpeg helpers, colorimetry/quality logic, and several services that break work into jobs, run batch orchestration, and apply overlays.
- The data flow here is: input media → job expansion/batch orchestration → FFmpeg-based conversion → optional overlay/color adjustments → exported GIF/output artifact.
4. Conversion services boundary
- The services/ subpackage is where most of the reusable conversion behaviors live:
- ffmpeg_converter.py for actual transcoding,
- batch_orchestrator.py for multi-file processing,
- job_expander.py for splitting or normalizing work,
- gif_search_service.py and search_engines.py for remote GIF acquisition,
- pillow_overlay.py for text or image overlays when FFmpeg is not enough.
- This is the main boundary between “orchestration” and “media processing.”
5. Auto-action / cinematic framing subsystem
- src/engine/auto_action is the AI-assisted framing pipeline.
- It includes reader/renderer/writer components plus camera.py, pipeline.py, and interfaces.py, indicating a staged flow:
- read frames
- analyze/track subjects
- decide camera motion and crop
- render intermediate output
- write final framed media
- The README’s “Auto Action Framing” maps to this subsystem: it dynamically tracks subjects and crops the scene to keep action centered for a tiny display.
6. Analysis and scene classification
- src/engine/analysis appears to provide the non-UI analytical core used to classify scenes and drive automated decisions.
- scene_types.py, analyzer.py, and analysis.py suggest a pipeline that scores or labels content so the rest of the system can choose the right camera/profile behavior.
- This is the bridge between raw frame data and higher-level heuristics like platformer/talking/action scene handling.
7. AI moments extraction
- The auto_action/ai_moments.py module and the UI’s dedicated AI moments panel indicate a separate feature for finding the best highlight segments inside long videos.
- The README describes this as “AI Iconic Moments,” which is conceptually distinct from framing: it selects which parts of a source video are worth exporting, whereas auto-action decides how to frame them.
- In architecture terms, this is a pre-conversion content selection layer that feeds clips into the conversion workflow.
8. Plugin-style scoring and detection
- src/plugins contains reusable AI/heuristic components:
- detectors/ for detection logic,
- trackers/ for tracking subject motion,
- scorers/ for quality/ranking logic such as AI moments, DMD-specific scoring, and highlights.
- This suggests the engine is designed with pluggable scoring and detection strategies, so different pipelines can share common detection/tracking primitives without hard-coding behavior into the UI or converter.
9. Configuration and feature flags
- src/engine/config holds separate config modules for auto-action, conversion, display, and export.
- That separation indicates configuration is organized by feature domain, not by user interface screen.
- The README’s “Per-GIF Config,” “Advanced Settings,” and “Let Me Handle It” modes all depend on these config boundaries, where global defaults can be overridden per file or per operation.
10. UI architecture
- src/ui is a structured desktop app built around controllers, models, panels, preview, settings, events, and widgets.
- application_state.py is the shared state model; event_bus.py is the coordination mechanism; controllers mediate between UI actions and engine calls.
- Panels are split by responsibility: action list, AI moments, left/middle panels, preview, and settings screens. This suggests a model–event–controller style rather than a monolithic Tkinter window.
11. Preview and visualization path
- The UI includes a preview subsystem (src/ui/preview) and a DMD LED simulator (dmd_led_sim.py).
- From the README, the preview is three-part: source, auto-action intermediate, and final DMD output.
- This means the UI does not just display final results; it visualizes the intermediate pipeline states so users can inspect cropping, auto-framing, and the LED-grid effect before exporting.
12. External dependencies and runtime boundaries
- FFmpeg is the key system-level dependency for media processing.
- OpenCV + ONNX Runtime are optional and only matter for auto-action/YOLO-style inference.
- CustomTkinter, Pillow, duckduckgo-search, and Requests are UI/auxiliary dependencies.
- The architecture intentionally keeps the CLI/engine mostly standard-library-based, while the UI and AI features are opt-in through extra packages.
13. Entry points and deployment model
- The repository provides OS-specific launchers (launch_ui.sh, .bat, .ps1) that bootstrap a local environment and start the GUI.
- That indicates the UI is expected to be run as a self-contained desktop application, while the engine can also be used headlessly via CLI modules in engine/conversion/cli.py and engine/auto_action/cli.py.
14. Testing and repo validation
- The tests/ tree is organized to mirror the architecture: separate suites for auto_action, converter, engine/analysis, and ui.
- This mirrors the system boundaries and suggests each subsystem is meant to be testable in isolation, especially where AI, FFmpeg, and UI event flow intersect.
Main entry points: app.py App · pipeline.py Pipeline · services Services · controllers Controllers
Components 27
Conversion Engine
Media conversion pipeline for GIF/video to DMD-optimized output.
- CLI · Headless conversion entrypoint for batch or scripted use.
src/engine/conversion/cli.py - Core · Central conversion workflow coordinating media transforms and output generation.
src/engine/conversion/core.py - Services · Reusable orchestration and media-processing services boundary.
src/engine/conversion/services - FFmpeg · Primary transcoding and media conversion implementation.
src/engine/conversion/services/ffmpeg_converter.py - Batch · Coordinates multi-file processing and batch execution.
src/engine/conversion/services/batch_orchestrator.py - Jobs · Expands or normalizes incoming work items before conversion.
src/engine/conversion/services/job_expander.py - Overlays · GIF search, remote acquisition, and Pillow-based overlays.
src/engine/conversion/services
Auto Action
AI-assisted framing, clip selection, and cinematic crop pipeline.
- Auto CLI · Headless entrypoint for AI-assisted framing and moments workflows.
src/engine/auto_action/cli.py - Pipeline · Staged auto-action workflow from reading frames to final rendered output.
src/engine/auto_action/pipeline.py - Camera · Decides framing, motion, and crop behavior for tiny-display output.
src/engine/auto_action/camera.py - AI Moments · Selects highlight or iconic segments worth exporting.
src/engine/auto_action/ai_moments.py
Analysis
Scene analysis and classification used by automated decisions.
- Analysis Core · Scores and labels scenes to drive automated decisions.
src/engine/analysis/analysis.py - Scene Types · Defines scene categories and classification labels.
src/engine/analysis/scene_types.py
Plugins
Reusable detectors, trackers, and scoring strategies.
- Detectors · Reusable subject and motion detection primitives.
src/plugins/detectors/detector.py - Trackers · Motion and subject tracking primitives shared across pipelines.
src/plugins/trackers/tracker.py - Scorers · Heuristics and AI scoring for highlights, DMD visibility, and moments.
src/plugins/scorers
Desktop UI
Cross-platform desktop application, state, preview, and controls.
- App · Main desktop application shell and launcher wiring.
src/ui/app.py - State · Shared UI state model used across panels and controllers.
src/ui/models/application_state.py - Event Bus · Event-driven coordination mechanism between controllers and views.
src/ui/events/event_bus.py - Controllers · Bridges user actions to engine calls and state updates.
src/ui/controllers - Panels · Main workspace panels for actions, AI moments, and layout.
src/ui/panels - Preview · Source, auto-action, and final-output preview path.
src/ui/preview/preview_panel.py - DMD Sim · Simulates the HUB75 LED matrix appearance in the UI.
src/ui/dmd_led_sim.py - Settings · Feature-specific settings for conversion, display, export, and auto-action.
src/ui/settings
Tests
Architecture-mirroring test suites for major subsystems.
- Converter Tests · Tests for conversion core, CLI, quality, and FFmpeg helpers.
tests/converter - Auto Action Tests · Tests for framing, camera, analysis, detector, tracker, and AI moments.
tests/auto_action - UI Tests · Tests for application state, event bus, controllers, preview, and widgets.
tests/ui
Connections 26
- CLI → Core: invokes · CLI drives the main conversion workflow.
- Core → Services: delegates · Core conversion logic relies on reusable services.
- Services → FFmpeg: uses · Transcoding is handled by the FFmpeg service.
- Services → Batch: uses · Batch execution is coordinated here.
- Services → Jobs: uses · Incoming work is expanded into executable jobs.
- Services → Overlays: uses · Search and overlay helpers support the conversion pipeline.
- Auto CLI → Pipeline: invokes · CLI starts the staged auto-action pipeline.
- Pipeline → Camera: drives · Pipeline feeds framing and crop decisions into camera logic.
- Pipeline → Detectors: uses · Detection primitives support subject and motion analysis.
- Pipeline → Trackers: uses · Tracking primitives maintain subject continuity.
- Pipeline → Scorers: uses · Scoring strategies rank candidate clips or frames.
- AI Moments → Analysis Core: scores with · AI moments depends on scene analysis and ranking.
- Analysis Core → Scene Types: classifies · Analysis assigns scene categories and behaviors.
- App → State: binds · Desktop shell binds to shared application state.
- App → Event Bus: coordinates · Events connect UI components and controllers.
- App → Controllers: hosts · Controllers mediate between user actions and engine calls.
- Controllers → Core: triggers · UI can launch conversion workflows.
- Controllers → Pipeline: triggers · UI can launch auto-action framing workflows.
- App → Panels: renders · Main workspace is composed of multiple functional panels.
- App → Preview: shows · Preview exposes source, intermediate, and final states.
- App → DMD Sim: simulates · LED matrix output is visualized in-app.
- App → Settings: configures · Feature-specific settings screens configure the app.
- Controllers → Event Bus: publishes · Controllers push state changes through the event bus.
- Converter Tests → Core: covers · Converter tests exercise core conversion behavior.
- Auto Action Tests → Pipeline: covers · Auto-action tests exercise framing and analysis flow.
- UI Tests → App: covers · UI tests validate state, events, and panel behavior.