SubX-CLI
English | ไธญๆ
AI subtitle processing CLI tool, which automatically matches, renames, and converts subtitle files.
Features
AI subtitle processing CLI tool, which automatically matches, renames, and converts subtitle files.
Features
- ๐ค AI Smart Matching - Uses AI technology to automatically identify video-subtitle correspondence and rename files
- ๐ File Organization - Automatically copy or move matched subtitle files to video folders for seamless playback
- ๐ Format Conversion - Supports conversion between mainstream subtitle formats like SRT, ASS, VTT, SUB
- ๐ Audio Synchronization - Directly decode various audio container formats (MP4, MKV, WebM, OGG, WAV) for VAD-based synchronization without intermediate transcoding
- โฐ 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 Settings
# OpenRouter setup (Free DeepSeek model)
# Or OpenAI setup
# Azure OpenAI setup
# Note: Azure OpenAI deployment ID is now configured via `ai.model` instead of a separate field
# Configure VAD settings
# Enable general backup feature
# Configure parallel processing
2. Basic Usage
Subtitle Matching and Renaming
# Process a single folder
# Process multiple input sources using -i parameter
# Preview mode (no actual execution)
# Recursively process subfolders
# Combine -i parameter with recursive processing
# Copy matched subtitles to video folders
# Move matched subtitles to video folders
# Advanced: Mix files and directories with multiple options
# Combine with recursive and backup options
Format Conversion
# Convert single file
# Batch conversion using -i parameter for multiple directories
# Batch conversion with recursive directory scanning
# Batch conversion
# Convert while keeping original file
# Advanced: Mix files and directories with encoding specification
Timeline Correction
# Automatic VAD synchronization (requires audio/video file)
# Manual synchronization (only subtitle file required)
# VAD with custom sensitivity
# Batch processing mode (processes entire directories)
# Batch processing using -i parameter for multiple directories
# Batch processing with recursive directory scanning
# Advanced: Multiple directories with specific sync method
# Batch mode with detailed output and dry-run
Character Encoding Detection
# Specify files directly
# Using -i parameter for directory processing (flat)
# Using -i parameter with recursive directory scanning
# Advanced: Mix specific files with directory scanning
Cache Management
# Clear dry-run cache
Usage Examples
Typical Workflow
# 1. Process downloaded videos and subtitles
# 2. AI match and rename subtitles with file organization
# 3. Unify conversion to SRT format
# 4. Fix time synchronization issues
Advanced Workflow with -i Parameter
# 1. Process multiple directories with different sources
# 2. Match and organize from multiple input sources
# 3. Batch convert all subtitle formats to SRT with recursive scanning
# 4. Batch synchronize all media with multiple directories
# 5. Check encoding of all subtitle files
File Organization Scenarios
# Scenario 1: Keep original subtitles in place, copy to video folders
# Scenario 1b: Multiple input sources with copy operation
# Scenario 2: Move subtitles to video folders, clean up original locations
# Scenario 2b: Multiple input sources with move operation
# Scenario 3: Preview file organization operations
# Scenario 3b: Preview with multiple input sources
# Scenario 4: Organize files with backup protection
# Scenario 4b: Multiple sources with backup protection
# Scenario 5: Advanced - Mix specific files with directories
Folder Structure Example
Before processing (distributed structure):
media/
โโโ movies/
โ โโโ Action/
โ โ โโโ The.Matrix.1999.1080p.BluRay.mkv
โ โโโ Drama/
โ โโโ Forrest.Gump.1994.720p.WEB-DL.mp4
โโโ subtitles/
โโโ english/
โ โโโ Matrix_EN_Sub.srt
โ โโโ ForrestGump_English.srt
โโโ chinese/
โโโ ้งญๅฎขไปปๅ_ไธญๆๅญๅน.srt
โโโ ้ฟ็ๆญฃๅณ.็นไธญ.srt
After processing with --copy option (AI Smart Matching):
media/
โโโ movies/
โ โโโ Action/
โ โ โโโ The.Matrix.1999.1080p.BluRay.mkv
โ โ โโโ The.Matrix.1999.1080p.BluRay.srt # AI matched Matrix_EN_Sub.srt and renamed
โ โ โโโ The.Matrix.1999.1080p.BluRay.zh.srt # AI matched ้งญๅฎขไปปๅ_ไธญๆๅญๅน.srt and renamed
โ โโโ Drama/
โ โโโ Forrest.Gump.1994.720p.WEB-DL.mp4
โ โโโ Forrest.Gump.1994.720p.WEB-DL.srt # AI matched ForrestGump_English.srt and renamed
โ โโโ Forrest.Gump.1994.720p.WEB-DL.zh.srt # AI matched ้ฟ็ๆญฃๅณ.็นไธญ.srt and renamed
โโโ subtitles/ # Original files preserved
โโโ english/
โ โโโ Matrix_EN_Sub.srt
โ โโโ ForrestGump_English.srt
โโโ chinese/
โโโ ้งญๅฎขไปปๅ_ไธญๆๅญๅน.srt
โโโ ้ฟ็ๆญฃๅณ.็นไธญ.srt
After processing with --move option (AI Smart Matching):
media/
โโโ movies/
โ โโโ Action/
โ โ โโโ The.Matrix.1999.1080p.BluRay.mkv
โ โ โโโ The.Matrix.1999.1080p.BluRay.srt # AI matched and renamed, then moved
โ โ โโโ The.Matrix.1999.1080p.BluRay.zh.srt # AI matched and renamed, then moved
โ โโโ Drama/
โ โโโ Forrest.Gump.1994.720p.WEB-DL.mp4
โ โโโ Forrest.Gump.1994.720p.WEB-DL.srt # AI matched and renamed, then moved
โ โโโ Forrest.Gump.1994.720p.WEB-DL.zh.srt # AI matched and renamed, then moved
โโโ subtitles/ # Original files removed
โโโ english/ # Empty directories
โโโ chinese/
Configuration
SubX supports comprehensive configuration through environment variables and configuration files.
Quick Configuration
# Set OpenAI API Key
# Optional: Custom OpenAI endpoint
# Or use config commands
Configuration File Location
- Linux/macOS:
~/.config/subx/config.toml - Windows:
%APPDATA%\subx\config.toml
For detailed configuration options, see Configuration Guide.
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
--copy, -c Copy matched subtitle files to video folders
--move, -m Move matched subtitle files to video folders
File Organization:
The --copy and --move options enable automatic file organization for better
media player compatibility. When subtitles are matched with videos in different
directories, these options will copy or move the subtitle files to the same
folder as their corresponding video files.
- --copy: Preserves original subtitle files in their original locations
- --move: Removes original subtitle files after moving them
- These options are mutually exclusive and cannot be used together
- Only applied when subtitle and video files are in different directories
- Includes automatic filename conflict resolution with backup support
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 confidence, default encoding, 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 fallback, etc.
subx-cli sync - Timeline Correction
Options:
<VIDEO> Video file path (supports MP4, MKV/WebM, OGG, WAV audio input)
<SUBTITLE> Subtitle file path
<PATHS>... Files or directories to process (positional)
--offset <SECONDS> Manually specify offset (must not exceed sync.max_offset_seconds config)
--batch Batch processing mode
--method <METHOD> Sync method (auto|vad, default: from sync.default_method config)
--vad-sensitivity <SENSITIVITY> VAD detection sensitivity (0.0-1.0, overrides config)
Audio Format Support:
- MP4, MKV/WebM, OGG, WAV containers (automatically transcoded to WAV for analysis)
Configuration Support:
- Sync Settings: Default sync method, maximum offset range, etc.
- VAD Processing: Sensitivity, padding chunks, min speech duration, 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
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 the audio/video file is accessible and check if the file format is supported. If VAD sync doesn't work well, try:
- Adjust VAD sensitivity:
subx-cli config set sync.vad.sensitivity 0.8(higher for quiet audio) - Use manual offset for difficult cases:
subx-cli sync --offset <seconds> subtitle.srt - Check VAD configuration:
subx-cli config set sync.vad.enabled true - For very noisy audio:
subx-cli config set sync.vad.min_speech_duration_ms 200 - Adjust VAD parameters:
subx-cli config set sync.vad.padding_chunks 3
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 and default encoding:
Q: Format conversion issues or styling problems?
A: Configure format conversion settings:
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
Q: File organization (copy/move) operations fail?
A: Check the following common issues:
- Ensure target video directories have write permissions
- Check if there's sufficient disk space for copy operations
- For filename conflicts, the system will automatically rename files with numeric suffixes
- Use
--dry-runto preview operations before execution:subx-cli match --dry-run --copy /path
Q: Can I use both --copy and --move together?
A: No, these options are mutually exclusive. Choose either --copy to preserve original files or --move to clean up original locations.
Q: Why are some subtitles not being copied/moved to video folders?
A: The copy/move operations only apply when:
- Subtitle and video files are in different directories
- AI matching confidence exceeds the threshold (default 80%)
- Files don't already exist in the target location with identical names
Use
--dry-runto see which operations will be performed.
Q: How to handle filename conflicts during copy/move operations?
A: The system automatically handles conflicts by:
- Comparing file content when names match
- Auto-renaming with numeric suffixes (e.g.,
movie.srtโmovie.1.srt) - Creating backups when
--backupis enabled - Skipping conflicting files and continuing with others
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.