SuperAPI AI Directory

video-subtitle-remover

Design & creation

View repository

Updated 10-16 06:49

About this skill

Video Subtitle Remover Skill (Video Subtitle Remover)

Trigger Scenarios

This skill is triggered when the user mentions the following keywords:

  • "remove subtitles", "remove video subtitles"
  • "remove the text/watermark in the video"
  • "get rid of this video's subtitles"

Workflow

This is a heavy task that requires local GPU/Apple Silicon acceleration. You need to act as a complete executor, fromenvironment preparationtoexecutiontaking full responsibility.

Phase 1: Environment Check and Preparation (Very Important)

Before the first run, you must check the environment and install the required components on the user's machine. The working directory convention is:~/.opencode/tools/video-subtitle-remover。

  1. Check Directory and Code Use bash to check whether ~/.opencode/tools/video-subtitle-remover/run_remove.py exists. If it does not exist, perform the following initialization operations:
# 1. 创建工作目录
mkdir -p ~/.opencode/tools/video-subtitle-remover/backend/models/{V4/ch_det,sttn}
cd ~/.opencode/tools/video-subtitle-remover

# 2. 拉取核心代码 (跳过模型文件)
curl -sL "https://api.github.com/repos/YaoFANGUK/video-subtitle-remover/git/trees/main?recursive=1" | python3 -c "
import sys, json, os, urllib.request
data = json.load(sys.stdin)
for item in data.get('tree', []):
    if item['type'] != 'blob': continue
    path = item['path']
    ext = os.path.splitext(path)[1].lower()
    if ext in {'.pth', '.onnx', '.pdiparams', '.pdmodel'} or '__pycache__' in path or item.get('size', 0) > 500000: continue
    
    os.makedirs(os.path.dirname(path) if os.path.dirname(path) else '.', exist_ok=True)
    url = f'https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/{path}'
    try:
        content = urllib.request.urlopen(url).read()
        with open(path, 'wb') as f: f.write(content)
    except: pass
"
  1. Install Python Dependencies

    pip3 install torch torchvision
    pip3 install filesplit==3.0.2 scikit-image pyclipper lmdb PyYAML omegaconf tqdm easydict scikit-learn pandas webdataset einops av shapely paddleocr paddle2onnx albumentations imgaug
    
  2. Download and Merge Models (Required for STTN Mode) If backend/models/sttn/infer_model.pth or backend/models/V4/ch_det/inference.pdiparams does not exist, use curl to download:

    cd ~/.opencode/tools/video-subtitle-remover/backend/models
    # 下载 STTN 模型
    curl -L -o sttn/infer_model.pth "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/sttn/infer_model.pth"
    
    # 下载并合并 PaddleOCR 文本检测模型 (3个分割包)
    curl -L -o V4/ch_det/inference_1.pdiparams "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/inference_1.pdiparams"
    curl -L -o V4/ch_det/inference_2.pdiparams "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/inference_2.pdiparams"
    curl -L -o V4/ch_det/inference_3.pdiparams "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/inference_3.pdiparams"
    curl -L -o V4/ch_det/fs_manifest.csv "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/fs_manifest.csv"
    curl -L -o V4/ch_det/inference.pdiparams.info "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/inference.pdiparams.info"
    curl -L -o V4/ch_det/inference.pdmodel "https://raw.githubusercontent.com/YaoFANGUK/video-subtitle-remover/main/backend/models/V4/ch_det/inference.pdmodel"
    
    # 使用 Python 合并
    python3 -c "from fsplit.filesplit import Filesplit; fs=Filesplit(); fs.merge(input_dir='V4/ch_det')"
    
  3. Inject Fix Code and Startup Script Use edit tool to modify backend/config.py:

    • Fix Mac's MPS device support (device = torch.device('mps'))
    • Fix FFMPEG_PATH to point to the system ffmpeg (shutil.which('ffmpeg'))
    • Remove unnecessary LAMA and ProPainter model validation.

    And use write tool to generate run_remove.py startup script.

Phase 2: Execute the Task

  1. Extract Information and Evaluate Obtain the absolute path of the video provided by the user, run ffprobe or ls -lh to get the frame count, and give the user an estimate of the processing time.

  2. Execute Processing Run the processing script:

    export KMP_DUPLICATE_LIB_OK=True
    python3 ~/.opencode/tools/video-subtitle-remover/run_remove.py "<视频绝对路径>"
    

    Note: If the video is long, be sure to use tmux to run it in the background.

  3. Deliver Results Use open command to automatically open the output _no_sub.mp4 video for the user.