# skeskinen/smartcut architecture

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

- Interactive diagram: https://gitdiagram.com/skeskinen/smartcut
- Repository: https://github.com/skeskinen/smartcut

## Overview

Video Smartcut is a command-line tool for keeping or removing time ranges from media files, preserving compressed video where possible and recoding around cutpoints. The workflow starts with CLI arguments, opens and analyzes the input, resolves requested times into GOP-aware cut segments, then writes video, audio, and subtitle streams to an output file. The README documents broad format support and passthrough audio. Source excerpts show the main orchestration and cutter responsibilities; some internal calls are supported only by the SOURCE INDEX, so the graph stays at those documented module boundaries.

Main entry points: [`smartcut/media_container.py`](https://github.com/skeskinen/smartcut/blob/main/smartcut/media_container.py) (Media inspection), [`smartcut/smart_cut.py`](https://github.com/skeskinen/smartcut/blob/main/smartcut/smart_cut.py) (Cut segment planning), [`smartcut/__main__.py`](https://github.com/skeskinen/smartcut/blob/main/smartcut/__main__.py) (CLI and time parsing), [`smartcut/video_cutter.py`](https://github.com/skeskinen/smartcut/blob/main/smartcut/video_cutter.py) (Video stream cutter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI"]
  node_cli["CLI and time parsing<br/>[__main__.py]"]
end

subgraph group_planning["Media planning"]
  node_analysis["Media inspection<br/>[media_container.py]"]
  node_segments["Cut segment planning<br/>[smart_cut.py]"]
end

subgraph group_cutting["Stream cutting"]
  node_video["Video stream cutter<br/>[video_cutter.py]"]
  node_tracks["Audio and subtitle cutters<br/>[track_cutters.py]"]
end

subgraph group_support["Media support"]
  node_segment_data["Segment data<br/>[misc_data.py]"]
  node_media_rules["Media format rules<br/>[media_utils.py]"]
  node_nal["NAL keyframe analysis<br/>[nal_tools.py]"]
end

node_user(("CLI user"))
node_input["Input media"]
node_output["Output media"]
node_pyav["PyAV / FFmpeg"]

node_user -->|"provides arguments"| node_cli
node_cli -->|"opens input"| node_analysis
node_input -->|"reads media"| node_analysis
node_cli -->|"requests cut"| node_segments
node_analysis -->|"supplies GOP data"| node_segments
node_segments -->|"creates segments"| node_segment_data
node_segments -->|"dispatches segments"| node_video
node_segments -->|"dispatches segments"| node_tracks
node_video -->|"writes video"| node_output
node_tracks -->|"writes tracks"| node_output
node_analysis -->|"checks keyframes"| node_nal
node_video -->|"uses NAL helpers"| node_nal
node_cli -->|"uses media settings"| node_media_rules
node_analysis -->|"opens and demuxes"| node_pyav
node_video -->|"decodes and encodes"| node_pyav
node_tracks -->|"creates output streams"| node_pyav

click node_cli "https://github.com/skeskinen/smartcut/blob/main/smartcut/__main__.py"
click node_analysis "https://github.com/skeskinen/smartcut/blob/main/smartcut/media_container.py"
click node_segments "https://github.com/skeskinen/smartcut/blob/main/smartcut/smart_cut.py"
click node_segment_data "https://github.com/skeskinen/smartcut/blob/main/smartcut/misc_data.py"
click node_video "https://github.com/skeskinen/smartcut/blob/main/smartcut/video_cutter.py"
click node_tracks "https://github.com/skeskinen/smartcut/blob/main/smartcut/track_cutters.py"
click node_media_rules "https://github.com/skeskinen/smartcut/blob/main/smartcut/media_utils.py"
click node_nal "https://github.com/skeskinen/smartcut/blob/main/smartcut/nal_tools.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_analysis,node_segments toneAmber
class node_video,node_tracks toneMint
class node_segment_data,node_media_rules,node_nal toneRose
class node_input,node_output,node_pyav toneIndigo
```

## Components

### CLI

- [CLI and time parsing](https://github.com/skeskinen/smartcut/blob/main/smartcut/__main__.py): `smartcut/__main__.py`

### Media planning

- [Media inspection](https://github.com/skeskinen/smartcut/blob/main/smartcut/media_container.py): `smartcut/media_container.py`
- [Cut segment planning](https://github.com/skeskinen/smartcut/blob/main/smartcut/smart_cut.py): `smartcut/smart_cut.py`

### Stream cutting

- [Video stream cutter](https://github.com/skeskinen/smartcut/blob/main/smartcut/video_cutter.py): `smartcut/video_cutter.py`
- [Audio and subtitle cutters](https://github.com/skeskinen/smartcut/blob/main/smartcut/track_cutters.py): `smartcut/track_cutters.py`

### Media support

- [Segment data](https://github.com/skeskinen/smartcut/blob/main/smartcut/misc_data.py): `smartcut/misc_data.py`
- [Media format rules](https://github.com/skeskinen/smartcut/blob/main/smartcut/media_utils.py): `smartcut/media_utils.py`
- [NAL keyframe analysis](https://github.com/skeskinen/smartcut/blob/main/smartcut/nal_tools.py): `smartcut/nal_tools.py`

### Other components

- **CLI user**
- **Input media**
- **Output media**
- **PyAV / FFmpeg**

## Connections

- CLI user → CLI and time parsing: provides arguments (evidence: `README.md`)
- CLI and time parsing → Media inspection: opens input (evidence: `smartcut/__main__.py`)
- Input media → Media inspection: reads media (evidence: `smartcut/media_container.py`)
- CLI and time parsing → Cut segment planning: requests cut (evidence: `smartcut/__main__.py`)
- Media inspection → Cut segment planning: supplies GOP data (evidence: `smartcut/smart_cut.py`)
- Cut segment planning → Segment data: creates segments (evidence: `smartcut/smart_cut.py`)
- Cut segment planning → Video stream cutter: dispatches segments (evidence: `smartcut/smart_cut.py`)
- Cut segment planning → Audio and subtitle cutters: dispatches segments (evidence: `smartcut/smart_cut.py`)
- Video stream cutter → Output media: writes video
- Audio and subtitle cutters → Output media: writes tracks
- Media inspection → NAL keyframe analysis: checks keyframes (evidence: `smartcut/media_container.py`)
- Video stream cutter → NAL keyframe analysis: uses NAL helpers (evidence: `smartcut/video_cutter.py`)
- CLI and time parsing → Media format rules: uses media settings (evidence: `smartcut/__main__.py`)
- Media inspection → PyAV / FFmpeg: opens and demuxes (evidence: `smartcut/media_container.py`)
- Video stream cutter → PyAV / FFmpeg: decodes and encodes (evidence: `smartcut/video_cutter.py`)
- Audio and subtitle cutters → PyAV / FFmpeg: creates output streams (evidence: `smartcut/track_cutters.py`)
