SubX-CLI
English | 中文
An subtitle processing CLI tool that powered by AI technology to automatically match, rename, and process subtitle files.
[!NOTE]
This project is currently in early development. Basic functionality has been implemented, but there may still be room for improvement. If you find any issues please feel free to submit an Issue.
Features
- 🤖 AI Smart Matching - Uses AI technology to automatically identify video-subtitle correspondence and rename files
- 🔄 Format Conversion - Supports conversion between mainstream subtitle formats like SRT, ASS, VTT, SUB
- ⏰ Timeline Correction - Automatically detects and corrects subtitle timing offset issues
- 🏃 Batch Processing - Process entire folders of media files at once
- 🔍 Dry-run Mode - Preview operation results for safety and reliability
- 📦 Cache Management - Reuse previous analysis results for repeated dry-runs to improve efficiency
Installation
Linux
Method 1: Download and run installation script
|
Method 2: Direct download of pre-compiled binaries
# Download latest version
Method 3: Install using Cargo compilation
# Install from crates.io
# Or compile from source
Quick Start
1. Configure API Keys
# Set OpenAI API Key (for AI matching functionality)
# Optional: Set custom OpenAI Base URL (for OpenAI API or private deployment)
# Or set through configuration commands
2. Basic Usage
Subtitle Matching and Renaming
# Process a single folder
# Preview mode (no actual execution)
# Recursively process subfolders
Format Conversion
# Convert single file
# Batch conversion
# Convert while keeping original file
Timeline Correction
# Auto-detect offset
# Manually specify offset
# Batch sync entire folder
Cache Management
# Clear dry-run cache
Usage Examples
Typical Workflow
# 1. Process downloaded videos and subtitles
# 2. AI match and rename subtitles
# 3. Unify conversion to SRT format
# 4. Fix time synchronization issues
Folder Structure Example
Before processing:
TV_Show_S01/
├── S01E01.mkv
├── S01E02.mkv
├── subtitle_from_internet_1.ass
└── subtitle_from_internet_2.ass
After processing:
TV_Show_S01/
├── S01E01.mkv
├── S01E01.ass # Matched and renamed
├── S01E02.mkv
└── S01E02.ass # Matched and renamed
Configuration Options
Configuration File Location
- Linux/macOS:
~/.config/subx/config.toml - Windows:
%APPDATA%\subx\config.toml
Configuration Example
[]
# AI service provider, currently supports "openai"
= "openai"
# AI model to use
= "gpt-4o-mini"
# API endpoint, can be overridden by OPENAI_BASE_URL environment variable
= "https://api.openai.com/v1"
# API key, can be overridden by OPENAI_API_KEY environment variable
= "your-api-key-here"
# AI response randomness control (0.0-2.0)
= 0.3
# Maximum content length sent to AI
= 2000
# Number of retry attempts for API request failures
= 3
# Retry interval (milliseconds)
= 1000
[]
# Default output format
= "srt"
# Whether to preserve styling during conversion
= true
# Default text encoding
= "utf-8"
# Encoding detection confidence threshold (0.0-1.0)
= 0.7
[]
# Maximum offset range for audio sync (seconds)
= 30.0
# Audio correlation analysis threshold (0.0-1.0)
= 0.7
# Audio energy threshold for dialogue detection
= 0.01
# Minimum dialogue segment duration (milliseconds)
= 500
# Dialogue segment merge gap (milliseconds)
= 500
# Whether to enable dialogue detection feature
= true
# Audio processing sample rate (Hz)
= 16000
# Whether to auto-detect audio sample rate
= true
[]
# Whether to enable file backup, can be overridden by SUBX_BACKUP_ENABLED environment variable
= false
# Maximum number of concurrent jobs
= 4
# Task execution timeout (seconds)
= 3600
# Whether to display progress bar
= true
# Worker thread idle timeout (seconds)
= 300
[]
# Task queue size limit
= 100
# Whether to enable task priority scheduling
= true
# Whether to enable automatic load balancing
= true
# Queue overflow strategy ("block" | "drop_oldest" | "reject")
= "block"
Command Reference
subx-cli match - AI Matching and Renaming
Options:
<PATH> Target folder path
--dry-run Preview mode, no actual execution
--confidence <NUM> Minimum confidence threshold (0-100, default: 80)
--recursive Recursively process subfolders
--backup Backup original files before renaming
Configuration Support:
- AI Settings: Support custom API endpoints, models, temperature, etc.
- Parallel Processing: Support max concurrency, task queue size, priority scheduling, etc.
- General Settings: Support backup, progress bar, timeout control, etc.
subx-cli convert - Format Conversion
Options:
<INPUT> Input file or folder path
--format <FORMAT> Target format (srt|ass|vtt|sub)
--output, -o <FILE> Output filename
--keep-original Keep original file
--encoding <ENC> Specify text encoding (default: utf-8)
Configuration Support:
- Format Settings: Default output format, style preservation, encoding detection, etc.
subx-cli detect-encoding - File Encoding Detection
Options:
<FILES>... Target file paths
-v, --verbose Show detailed sample text
Configuration Support:
- Format Settings: Encoding detection confidence threshold, default encoding, etc.
subx-cli sync - Timeline Correction
Options:
<VIDEO> Video file path
<SUBTITLE> Subtitle file path
--offset <SECONDS> Manually specify offset
--batch Batch processing mode
--range <SECONDS> Offset detection range (default: max_offset_seconds from config)
--threshold <THRESHOLD> Correlation threshold (0-1, default: correlation_threshold from config)
Configuration Support:
- Sync Settings: Maximum offset range, correlation threshold, dialogue detection, etc.
- Audio Processing: Sample rate, dialogue detection threshold, segment merging, etc.
subx-cli config - Configuration Management
Usage:
subx-cli config set <KEY> <VALUE> Set configuration value
subx-cli config get <KEY> Get configuration value
subx-cli config list List all configurations
subx-cli config reset Reset configuration
subx-cli cache - Dry-run Cache Management
Options:
clear Clear all dry-run cache files
subx-cli generate-completion - Generate Shell Completion Scripts
Usage:
subx-cli generate-completion <SHELL> Supported shells: bash, zsh, fish, powershell, elvish
Supported Formats
| Format | Read | Write | Description |
|---|---|---|---|
| SRT | ✅ | ✅ | SubRip subtitle format |
| ASS | ✅ | ✅ | Advanced SubStation Alpha format |
| VTT | ✅ | ✅ | WebVTT format |
| SUB | ✅ | ⚠️ | Various SUB variant formats |
Troubleshooting
Common Issues
Q: What to do if AI matching accuracy is low?
A: Ensure filenames contain sufficient identifying information (like show name, season, episode numbers). You can also try adjusting the --confidence parameter or configure AI model temperature: subx-cli config set ai.temperature 0.1
Q: Timeline sync fails? A: Ensure video files are accessible and check if file formats are supported. If automatic sync isn't ideal, you can try:
- Manually specify offset:
subx-cli sync --offset <seconds> video.mp4 subtitle.srt - Adjust sync configuration:
subx-cli config set sync.correlation_threshold 0.6 - Enable dialogue detection:
subx-cli config set sync.enable_dialogue_detection true
Q: Poor performance when processing large numbers of files? A: You can adjust parallel processing configuration:
Q: Inaccurate encoding detection?
A: Adjust detection confidence threshold: subx-cli config set formats.encoding_detection_confidence 0.8
Q: Cache files taking up too much space?
A: Use the subx-cli cache clear command to clear all cache files.
Q: How to re-match when new videos and subtitles are added?
A: Clear cache first with subx-cli cache clear, then re-run the match command.
Q: What to do about task execution timeouts?
A: Increase timeout duration: subx-cli config set general.task_timeout_seconds 7200 # Set to 2 hours
LICENSE
GPLv3
GNU GENERAL PUBLIC LICENSE Version 3
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
[!NOTE]
This project is fully developed using GitHub Copilot and Codex CLI, with an attempt to maintain the maintainability of the software architecture. My goal is to practice controlling and planning professional software engineering work entirely through prompt engineering with AI. This is what professional vibe coding should be.