# openhevc/ffmpeg architecture

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

- Interactive diagram: https://gitdiagram.com/openhevc/ffmpeg
- Repository: https://github.com/openhevc/ffmpeg

## Overview

##### Project Type & Purpose
- Open-source, modular multimedia framework and toolset (FFmpeg) for decoding, encoding, filtering and streaming audio/video/subtitles.
- Consists of a set of C libraries plus command-line tools that sit on top of them.

##### High-Level Architectural Layers
[External I/O & Devices]
- Files, network protocols, device capture/playback (e.g., ALSA, avfoundation, v4l2)
uses libavformat & libavdevice
↓
[Core Libraries]
- libavformat – container demux/mux, I/O, streaming protocols
- libavcodec  – decode/encode codecs
- libavfilter – filter graph engine (audio/video filters)
- libswresample – audio resampling/mixing
- libpostproc   – post-processing routines
- libavutil     – utility functions (memory, logging, common data structures, threading)
↓
[CLI Tools & Applications]
- ffmpeg  – main command-line converter/streamer
- ffplay  – minimal media player (uses SDL on top of libs)
- ffprobe – introspection/analysis tool
- Additional small utilities (aviocat, qt-faststart, …)

##### Data Flow & Component Interactions
- Input sources → libavformat/libavdevice
– Demux container or capture device → elementary streams
- libavcodec
– Decode compressed streams → raw audio/video frames
- libavfilter
– Optionally apply filter graph to raw frames
- libswresample / libswscale
– Resample audio, scale/convert video pixel formats
- libavcodec
– Encode processed raw frames → compressed streams
- libavformat
– Mux encoded streams → output container or network protocol
- Tools invoke above pipeline via public C APIs (e.g., avformat_open_input, avcodec_send_frame, av_filter_graph_process)

##### Important Patterns & Principles
- Layered, clean C API per library – each lib has its own header and namespace (libavformat, libavcodec, ...)
- Plugin-style registration – codecs, filters, formats auto-registered at startup
- ABI stability – public headers vs. internal headers
- Architecture-specific optimized code in subdirectories (x86, arm, ppc)
- Threading support in libavutil (frame queues, thread messages)

##### Key Elements Not to Omit
- The filter graph engine (libavfilter) sitting between decode and encode.
- The helper/utility layer (libavutil) used everywhere.
- The separation of demux/mux (libavformat) vs. codecs vs. filters vs. scaling/resampling.
- The CLI frontends’ parsing layer (ffmpeg_opt.c) that configures the pipeline.
- Architecture-specific performance modules in each library.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Tools Layer
    subgraph "CLI Tools"
        direction TB
        ffmpeg["ffmpeg"]:::cli
        ffplay["ffplay"]:::cli
        ffprobe["ffprobe"]:::cli
        ffserver["ffserver"]:::cli
        cmdutils["cmdutils (shared utilities)"]:::cli
    end

    %% Core Libraries Layer
    subgraph "Core Libraries"
        direction TB
        libavutil["libavutil"]:::util
        libavformat["libavformat"]:::core
        libavcodec["libavcodec"]:::core
        libavfilter["libavfilter"]:::core
        libswresample["libswresample"]:::core
        libswscale["libswscale"]:::core
        libpostproc["libpostproc"]:::core

        subgraph "Architecture-Specific (libavcodec)"
            direction TB
            codec_x86["x86"]:::arch
            codec_arm["arm"]:::arch
            codec_ppc["ppc"]:::arch
        end
        libavcodec --> codec_x86
        libavcodec --> codec_arm
        libavcodec --> codec_ppc

        subgraph "Architecture-Specific (libavfilter)"
            direction TB
            filter_x86["x86"]:::arch
        end
        libavfilter --> filter_x86
    end

    %% External I/O & Devices Layer
    subgraph "External I/O & Devices"
        direction TB
        protocols["Demux/Mux & Protocols"]:::ext
        devices["Capture/Playback Devices"]:::ext
    end

    %% Data & Control Flow
    protocols -->|"compressed streams"| libavformat
    devices -->|"capture input"| libavdevice["libavdevice"]:::ext
    libavdevice -->|"elementary streams"| libavformat
    libavformat -->|"compressed streams"| libavcodec
    libavcodec -->|"raw frames"| libavfilter
    libavfilter -->|"filtered frames"| libswscale
    libavfilter -->|"filtered frames"| libswresample
    libswscale -->|"raw frames"| libavcodec
    libswresample -->|"raw audio"| libavcodec
    libavcodec -->|"compressed streams"| libavformat
    libavformat -->|"output container"| protocols

    ffmpeg -->|"calls API"| libavformat
    ffmpeg -->|"calls API"| libavcodec
    ffmpeg -->|"calls API"| libavfilter
    ffmpeg -->|"calls API"| libswresample
    ffmpeg -->|"calls API"| libswscale
    ffplay -->|"calls API"| libavformat
    ffplay -->|"calls API"| libavcodec
    ffprobe -->|"calls API"| libavformat
    ffserver -->|"calls API"| libavformat
    cmdutils -->|"helpers"| ffmpeg
    cmdutils -->|"helpers"| ffplay
    cmdutils -->|"helpers"| ffprobe
    cmdutils -->|"helpers"| ffserver

    %% Click Events
    click ffmpeg "https://github.com/openhevc/ffmpeg/blob/rext/./ffmpeg.c"
    click ffmpeg "https://github.com/openhevc/ffmpeg/blob/rext/./ffmpeg_opt.c"
    click ffmpeg "https://github.com/openhevc/ffmpeg/blob/rext/./ffmpeg.h"
    click ffplay "https://github.com/openhevc/ffmpeg/blob/rext/./ffplay.c"
    click ffprobe "https://github.com/openhevc/ffmpeg/blob/rext/./ffprobe.c"
    click ffserver "https://github.com/openhevc/ffmpeg/blob/rext/./ffserver.c"
    click ffserver "https://github.com/openhevc/ffmpeg/blob/rext/./ffserver_config.c"
    click ffserver "https://github.com/openhevc/ffmpeg/blob/rext/./ffserver_config.h"
    click cmdutils "https://github.com/openhevc/ffmpeg/blob/rext/./cmdutils.c"
    click cmdutils "https://github.com/openhevc/ffmpeg/blob/rext/./cmdutils.h"
    click cmdutils "https://github.com/openhevc/ffmpeg/blob/rext/./cmdutils_common_opts.h"
    click protocols "https://github.com/openhevc/ffmpeg/tree/rext/./libavformat/"
    click devices "https://github.com/openhevc/ffmpeg/tree/rext/./libavdevice/"
    click libavcodec "https://github.com/openhevc/ffmpeg/tree/rext/./libavcodec/"
    click libavfilter "https://github.com/openhevc/ffmpeg/tree/rext/./libavfilter/"
    click libavutil "https://github.com/openhevc/ffmpeg/tree/rext/./libavutil/"
    click libpostproc "https://github.com/openhevc/ffmpeg/tree/rext/./libpostproc/"
    click libswresample "https://github.com/openhevc/ffmpeg/tree/rext/./libswresample/"
    click libswscale "https://github.com/openhevc/ffmpeg/tree/rext/./libswscale/"
    click codec_x86 "https://github.com/openhevc/ffmpeg/tree/rext/./libavcodec/x86/"
    click codec_arm "https://github.com/openhevc/ffmpeg/tree/rext/./libavcodec/arm/"
    click codec_ppc "https://github.com/openhevc/ffmpeg/tree/rext/./libavcodec/ppc/"
    click filter_x86 "https://github.com/openhevc/ffmpeg/tree/rext/./libavfilter/x86/"
    click configure "https://github.com/openhevc/ffmpeg/tree/rext/./configure"
    click makefile "https://github.com/openhevc/ffmpeg/tree/rext/./Makefile"
    click common_mak "https://github.com/openhevc/ffmpeg/blob/rext/./common.mak"
    click arch_mak "https://github.com/openhevc/ffmpeg/blob/rext/./arch.mak"

    %% Styles
    classDef cli fill:#cce5ff,stroke:#004085,color:#004085
    classDef core fill:#d4edda,stroke:#155724,color:#155724
    classDef util fill:#d1ecf1,stroke:#0c5460,color:#0c5460
    classDef arch fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef ext fill:#fff3cd,stroke:#856404,color:#856404
```
