# dannyravi/video2slide architecture

> Architecture diagram of the GitHub repository dannyravi/video2slide, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dannyravi/video2slide
- Repository: https://github.com/dannyravi/video2slide

## Overview

##### Project Type and Purpose
- This is a command-line utility written in Go that converts a video lecture into a slide PDF. It processes an input video file (using external tools like ffmpeg and img2pdf) and produces a PDF file presenting selected frames as slides. The application is designed to run on Linux.

##### Analyzing the File Structure
- Top-Level Files:
– main.go: The entry-point of the application.
– hash.go, helper.go, readVideo.go: These likely contain the core logic for handling the video data – such as reading the video, processing frames, and possibly filtering out duplicates (hash.go might be used to compare frame contents).
– pdf.sh: A helper script that is probably used to invoke the img2pdf conversion or to wrap the PDF generation process.
– go.mod & go.sum: The project’s dependency files managed by Go.
- Directories:
– inFile: Contains the sample input (a video file named “1280.mp4”).
– outFile: Intended to store results (although the README mentions “out.pdf”, this directory may be used for intermediate or example output files).
– .github: Contains CI/CD workflow configurations (e.g., go.yml for automated builds at GitHub Actions).
– README.md: Provides instructions to install dependencies (ffmpeg, img2pdf) and explains the usage of the CLI.

##### Understanding the Processing Flow
- Command Line Interface: Users run the application with flags (like “-s 1” and “-i ./inFile/1280.mp4”) which are parsed in main.go.
- Video Processing: readVideo.go likely handles the extraction of frames by interfacing with external calls (ffmpeg) to pull frames from the input video.
- Processing & Filtering: helper.go and hash.go might perform any image analysis or filtering (e.g., comparing hashes to avoid duplicate slides).
- PDF Generation: Once frames are processed, the images are converted into a PDF. The pdf.sh script, together with img2pdf, helps generate the slide PDF output which is written to a specified path (“out.pdf” as per the README).
- CI/CD: The .github/workflows/go.yml file indicates that there’s automated build and testing integration.

a. Main Components:
– User/CLI Input: The starting point where the input flags and file paths are provided.
– Main Application: Represented by main.go which coordinates the execution.
– Video Reader Module: The code in readVideo.go that interfaces with ffmpeg to extract frames.
– Helper and Filtering Modules: helper.go and hash.go, managing frame processing (possibly to decide which frame qualifies as a slide).
– PDF Conversion Module: The combination of pdf.sh and the external tool (img2pdf) that compiles the frames into a PDF.
– External Dependencies: ffmpeg and img2pdf, which are installed on the Linux system.
– Output: The resulting PDF file (slide deck) stored in, or referenced by, the outFile directory.

b. Relationships and Data Flow:
– Begin with the CLI receiving input which is processed by main.go.
– main.go calls the video reader module, passing in the video file path from inFile.
– The video reader uses ffmpeg to extract image frames.
– The extracted frames are optionally filtered/compared using logic in helper.go and hash.go.
– Processed frames are then passed to the PDF conversion module. Here, pdf.sh and img2pdf wrap the conversion steps.
– The final PDF output is saved and becomes available for the user.

c. Architectural Patterns and Technologies:
– The system follows a layered approach: input handling (CLI), processing logic (frame extraction and filtering), and output generation (PDF conversion).
– It makes use of external services and tools (ffmpeg, img2pdf), indicating a design that leverages the operating system environment.
– The project uses Go’s modularity by separating concerns into different source files.

– Since this is a utility (rather than a full-stack application) concentrate on showing the flow from command-line input through to external tool invocation and output file generation.
– Emphasize the dependency on system-level tools required for video processing and PDF conversion.
– Clearly display how the modules interact and the sequence of steps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    J["CI/CD Pipeline"]:::file
    A["User/CLI Input"]:::cli
    B["Main Application Coordination"]:::internal
    H["Input Video File"]:::file
    C["Video Extraction Module (readVideo.go)"]:::internal
    F["External Tool: ffmpeg"]:::external
    D1["Frame Filtering (hash.go)"]:::internal
    D2["Helper Functions (helper.go)"]:::internal
    E["PDF Conversion Module (pdf.sh)"]:::internal
    G["External Tool: img2pdf"]:::external
    I["PDF Output Directory"]:::file

    %% Flow connections
    J -->|"triggers"| B
    A -->|"provides input"| B
    H -->|"video file"| C
    B -->|"calls"| C
    C -->|"invokes"| F
    F -->|"returns frames"| C
    C -->|"sends frames"| D1
    C -->|"sends frames"| D2
    D1 -->|"filtered frames"| E
    D2 -->|"processed frames"| E
    E -->|"converts using"| G
    G -->|"generates PDF"| E
    E -->|"outputs PDF"| I

    %% Click Events
    click A "https://github.com/dannyravi/video2slide/blob/main/main.go"
    click B "https://github.com/dannyravi/video2slide/blob/main/main.go"
    click C "https://github.com/dannyravi/video2slide/blob/main/readVideo.go"
    click D1 "https://github.com/dannyravi/video2slide/blob/main/hash.go"
    click D2 "https://github.com/dannyravi/video2slide/blob/main/helper.go"
    click E "https://github.com/dannyravi/video2slide/blob/main/pdf.sh"
    click H "https://github.com/dannyravi/video2slide/blob/main/inFile/1280.mp4"
    click I "https://github.com/dannyravi/video2slide/tree/main/outFile"
    click J "https://github.com/dannyravi/video2slide/blob/main/.github/workflows/go.yml"

    %% Styles
    classDef cli fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#DAA520,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef file fill:#D8BFD8,stroke:#8A2BE2,stroke-width:2px;
```
