Skip to content

CLI Interface

Joshua edited this page Oct 22, 2025 · 1 revision

CLI Interface

⚠️ Note: The CLI interface is currently not up to date and may not work properly. It will be updated once the Java desktop application reaches version 1.0. For now, please use the desktop GUI for the best experience.

The Command-Line Interface (CLI) provides automation capabilities for batch processing, scripting, and server deployments.

Overview

CLI mode provides:

  • ✅ Three operation modes (encoder, subtitle, renamer)
  • ✅ Batch processing
  • ✅ Progress callbacks
  • ✅ Configurable settings
  • ✅ Script-friendly output

Current Status

The CLI interface exists but is outdated and may contain bugs or missing features. Development focus is currently on the desktop GUI application.

Quick Start

# Basic usage
python encodeforge_cli.py <mode> <input_files>

# Examples
python encodeforge_cli.py encoder /path/to/videos
python encodeforge_cli.py subtitle /path/to/videos --enable-subtitle-generation
python encodeforge_cli.py renamer /path/to/videos --tmdb-api-key YOUR_KEY

Installation

From Source

git clone https://github.com/yourusername/encodeforge.git
cd encodeforge
pip install -r requirements.txt
cd EncodeForge/src/main/resources/python
python encodeforge_cli.py --help

Prerequisites

  • Python 3.8+
  • FFmpeg installed
  • Required Python packages (see requirements.txt)

Command Reference

Encoder Mode

python encodeforge_cli.py encoder <input> [options]

Basic Options:

--output-dir DIR          Output directory
--output-format FORMAT    Output format (mp4, mkv, avi, mov)
--recursive              Scan directories recursively
--dry-run                Show what would be done

Hardware Acceleration:

--use-nvenc              Use NVIDIA NVENC
--use-amf                Use AMD AMF
--use-qsv                Use Intel Quick Sync
--nvenc-preset PRESET    NVENC preset (p1-p7)
--nvenc-cq VALUE         NVENC quality (0-51)

Example:

python encodeforge_cli.py encoder /videos --use-nvenc --nvenc-cq 23 --output-format mp4

Subtitle Mode

python encodeforge_cli.py subtitle <input> [options]

Options:

--enable-subtitle-generation   Generate with Whisper AI
--enable-subtitle-download     Download from providers
--subtitle-languages LANGS     Comma-separated codes (eng,spa,fra)
--whisper-model MODEL          Whisper model (tiny,base,small,medium,large)
--opensubtitles-api-key KEY    OpenSubtitles API key

Example:

python encodeforge_cli.py subtitle /videos \
  --enable-subtitle-generation \
  --subtitle-languages eng,spa \
  --whisper-model base

Renamer Mode

python encodeforge_cli.py renamer <input> [options]

Options:

--pattern-tv PATTERN      TV show naming pattern
--pattern-movie PATTERN  Movie naming pattern
--tmdb-api-key KEY       TMDB API key
--preview-only           Show preview without renaming

Example:

python encodeforge_cli.py renamer /videos \
  --tmdb-api-key YOUR_KEY \
  --pattern-tv "{title} - S{season}E{episode}" \
  --preview-only

Advanced Examples

Batch Encoding with Hardware Acceleration

# Encode entire directory with NVENC
python encodeforge_cli.py encoder /media/movies \
  --use-nvenc \
  --nvenc-preset p4 \
  --nvenc-cq 23 \
  --output-format mp4 \
  --recursive \
  --output-dir /media/output

Generate Subtitles for Multiple Languages

# Generate English and Spanish subtitles
python encodeforge_cli.py subtitle /media/tv-shows \
  --enable-subtitle-generation \
  --subtitle-languages eng,spa \
  --whisper-model small \
  --recursive

Rename TV Show Library

# Rename TV shows with custom pattern
python encodeforge_cli.py renamer /media/tv-shows \
  --tmdb-api-key YOUR_KEY \
  --pattern-tv "{title} - S{season:02d}E{episode:02d} - {episodeTitle}" \
  --preview-only  # Preview first!

Combined Operations

# Encode + Add Subtitles + Rename
python encodeforge_cli.py encoder /media/input \
  --use-nvenc \
  --enable-subtitle-generation \
  --subtitle-languages eng \
  --enable-renaming \
  --tmdb-api-key YOUR_KEY \
  --pattern-tv "{title} - S{season}E{episode}"

Scripting Examples

Bash Script

#!/bin/bash
# Batch encode videos in current directory

python encodeforge_cli.py encoder . \
  --use-nvenc \
  --nvenc-cq 23 \
  --output-format mp4 \
  --delete-original

echo "Encoding complete!"

Python Script

#!/usr/bin/env python3
import subprocess
import sys

def encode_videos(input_dir, output_dir):
    cmd = [
        "python", "encodeforge_cli.py", "encoder",
        input_dir,
        "--use-nvenc",
        "--nvenc-cq", "23",
        "--output-dir", output_dir,
        "--recursive"
    ]
    
    result = subprocess.run(cmd, capture_output=True, text=True)
    
    if result.returncode == 0:
        print("Encoding successful!")
        print(result.stdout)
    else:
        print("Encoding failed!")
        print(result.stderr)
        sys.exit(1)

if __name__ == "__main__":
    encode_videos("/videos/input", "/videos/output")

Automation Script

#!/usr/bin/env python3
import os
import subprocess
from pathlib import Path

def process_directory(dir_path):
    """Process all videos in directory"""
    
    # Check for FFmpeg
    result = subprocess.run(
        ["python", "encodeforge_cli.py", "encoder", "--help"],
        capture_output=True
    )
    
    if result.returncode != 0:
        print("CLI not available")
        return
    
    # Process directory
    cmd = [
        "python", "encodeforge_cli.py", "encoder",
        str(dir_path),
        "--use-nvenc",
        "--recursive"
    ]
    
    subprocess.run(cmd)

if __name__ == "__main__":
    watch_dir = Path("/media/watch")
    
    # Monitor directory for new files
    while True:
        for file in watch_dir.rglob("*.mkv"):
            print(f"Processing: {file}")
            process_directory(file.parent)
            # Add logic to move or delete processed files
        time.sleep(60)  # Check every minute

Output & Logging

Progress Output

🎬 Starting conversion of 10 files...
Settings: NVENC=True, Quality=23

Converting file1.mkv: 45.2%
Converting file2.mkv: 23.1%
...

Results Output

================================================================================
CONVERSION RESULTS
================================================================================
✅ Successfully converted 10 files
  ✅ file1.mkv → file1.mp4
  ✅ file2.mkv → file2.mp4
...

Error Handling

# Verbose logging
python encodeforge_cli.py encoder /videos --verbose

# Save logs to file
python encodeforge_cli.py encoder /videos > log.txt 2>&1

Configuration

Environment Variables

# Set API keys
export TMDB_API_KEY="your_key"
export OPENSUBTITLES_API_KEY="your_key"

# Set paths
export FFMPEG_PATH="/usr/bin/ffmpeg"
export OUTPUT_DIR="/media/output"

Configuration File

Create ~/.encodeforge/config.json:

{
  "tmdb_api_key": "your_key",
  "opensubtitles_api_key": "your_key",
  "default_output_dir": "/media/output",
  "default_quality": 23,
  "default_preset": "p4"
}

Troubleshooting

Common Issues

Issue: "Command not found"

  • Solution: Use full path to Python script

Issue: "FFmpeg not found"

  • Solution: Install FFmpeg or set --ffmpeg-path

Issue: "Import error"

  • Solution: Install requirements: pip install -r requirements.txt

Issue: "Permission denied"

  • Solution: Check file permissions, run with appropriate user

Debug Mode

# Enable debug logging
python encodeforge_cli.py encoder /videos --debug

# Check FFmpeg
python encodeforge_cli.py encoder /videos --check-ffmpeg

Integration Examples

Cron Job

# Edit crontab
crontab -e

# Run every night at 2 AM
0 2 * * * /path/to/encodeforge_cli.py encoder /videos/input --recursive

Systemd Service

Create /etc/systemd/system/encodeforge.service:

[Unit]
Description=EncodeForge Batch Processor
After=network.target

[Service]
Type=simple
User=media
ExecStart=/usr/bin/python /opt/encodeforge/cli.py encoder /media/input
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable encodeforge
sudo systemctl start encodeforge

Performance Tips

  1. Use Hardware Acceleration - Much faster than software encoding
  2. Batch Processing - Process multiple files efficiently
  3. Dry Run First - Test commands before actual processing
  4. Monitor Resources - Watch CPU/GPU/disk usage
  5. Parallel Processing - Run multiple instances for different folders

Related Pages


Need automation? The CLI is perfect for scripting and batch processing!

🏠 Getting Started

Home

Getting Started


📚 User Guides

Encoder Mode

Subtitle Mode

Metadata Mode


🔧 Additional Interfaces

CLI Interface ⚠️

Web UI ⚠️


⚙️ Configuration

Settings & Configuration


📋 Project Info

Roadmap

Support


👨‍💻 For Developers

Developer Guide

Building from Source

Clone this wiki locally