Communitygithub.com

leonfighting-py/native-subtitle-quote-image-cn

Generate 3:4 or original-aspect-ratio subtitle quote images from local or online videos you have rights to, by sourcing, transcript alignment, quote selection, precise frame capture, tight cropping, collaging, and per-image quality check. Supports two distinct output modes: native subtitle mode (preserves burned-in subtitles) and script subtitle mode (draws approved timings and lines onto actual video frames).

What is native-subtitle-quote-image-cn?

This skill transforms video content into visually appealing subtitle quote images, ideal for social media, articles, or presentations. It accepts both local video files and online sources like YouTube (via yt-dlp) where the user has processing rights. The skill operates in two clearly separate modes: Native Subtitle Mode preserves existing burned-in subtitles from the video without OCR or redrawing, and Script Subtitle Mode draws user-approved, timestamped text onto real video frames, requiring explicit verification of each line. The workflow includes environment checks, non-blocking version updates, and a comprehensive pipeline: sample candidate frames, select quotes with semantic progression, preview subtitle bands, generate a manifest (for native) or a verified JSON timeline (for script mode), and render the final collage. Output defaults to 3:4 aspect ratio (1440x1920) for script mode and content-adaptive layout for native mode, with options for natural layout to preserve original video aspect, custom cropping, and band adjustments. The skill explicitly handles platform-specific quirks (e.g., Bilibili danmaku is not subtitles, Douyin is currently unsupported via yt-dlp) and provides detailed references for portrait/vertical videos, visual styling, and end-to-end workflows. It enforces strict rules against mixing modes, fabricating text, or silently switching from native to script mode when native subtitles are requested.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/leonfighting-py/native-subtitle-quote-image-cn/tree/HEAD/skills/native-subtitle-quote-image

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Video Subtitle Stitching

First, confirm the user's desired subtitle mode, then determine whether the material supports it. Do not mix the two modes, and do not silently switch from native subtitles to drawn subtitles.

Confirm Mode at Start

If the user has not explicitly specified a mode, first ask in the user's current language and briefly explain the two options. For Chinese queries, you can directly use:

Are you choosing native subtitles or script subtitles? Native subtitles preserve the subtitles already in the video frame without redrawing text; script subtitles draw your confirmed lines or translations onto real video frames later and indicate they are post-production subtitles.

When the user has clearly stated "native subtitles," "keep the original subtitles in the frame," "do not redraw subtitles," or "script subtitles," "draw the specified lines/translations onto the frame," proceed according to their choice without repeating the question. If the user has not yet chosen, you can perform a read-only check of the material to explain which mode is feasible, but do not execute mode-specific rendering; wait for the user to choose before continuing. If the selected mode does not match the material, explain the specific reason and ask the user whether they want to switch; do not switch on your own.

Non-Blocking Version Check

Run once at the start of each new task, before processing any material:

python3 "<SKILL_DIR>/scripts/check_update.py" --json
  • The script reads the local version from VERSION within the Skill and only accesses this project's GitHub Latest Release; it caches the result for 24 hours by default.
  • If the result is update_available, inform the user in one sentence of the current version, latest version, and Release link, then continue with the current task. Only notify; do not auto-update or overwrite the local Skill.
  • If the result is up_to_date, do not bother the user. If the result is unavailable, do not block the current task; if it's just a network restriction, you can request read-only access to the GitHub API and retry with --force once; if not authorized, continue the task.
  • The cache contains only the check time, latest version number, and Release link. It does not write to the repository or record account, material, or usage behavior.

Mode Routing

ConditionModeFinal Text SourceCommand
After turning off player CC, subtitles still appear in the screenshot; user wants to keep original subtitlesNative Subtitle ModeVideo frame pixelsrender
The video does not have the required burned-in subtitles, but the user wants to arrange confirmed lines, translations, or insights into a case-style layoutScript Subtitle Modetext in reviewed JSONrender-script
  • Native mode must not OCR then redraw, translate, rewrite, or overlay subtitles.
  • Script mode must explicitly be called "script subtitles" or "post-production drawn subtitles"; do not claim the text is original frame subtitles.
  • Script lines must be verifiable against the original video, user manuscript, or other clear source; do not fabricate names, data, quotes, or translation meanings.
  • When the user only says "keep the original subtitles," do not switch to script mode just because the original subtitles are difficult to handle.

Read Reference Files by Task

  • YouTube and other overseas URLs: First read references/yt-dlp-and-transcripts.md to obtain the videos, metadata, and auxiliary timelines the user is authorized to process. URL tasks must not fall back to "local video only" after a single failed public request: if YouTube returns a bot verification, age verification, or user's own non-public video restriction, first explain the reason and obtain authorization, then follow the reference file with yt-dlp --cookies-from-browser chrome to proceed. Subtitles and videos are downloaded with two separate commands; if the video returns HTTP 403, fall back step by step according to the format fallback table in the reference file; if subtitles return 429, reduce languages and slow down requests; do not retry indefinitely.
  • Bilibili, Douyin and other Chinese platforms: First read references/cn-platforms.md. Domestic platforms have different anti-bot measures and subtitle formats from YouTube; do not apply commands from the above document. Two must-remember conclusions: Bilibili's danmaku is danmaku, not subtitle tracks; Douyin is currently completely unusable on the yt-dlp side, do not repeatedly try cookies, switch to local video mode instead.
  • Source video is portrait or square: First read references/portrait-and-vertical.md. The default subtitle band 0.78–0.96 is designed for landscape subtitles and will miss subtitles when applied to portrait material; directly using --aspect 3:4 will also crop away about 38% of the vertical frame.
  • Read long video → Select topic → Write article/post → Add images: Read references/end-to-end-workflow.md.
  • Subtitle lines too tall, spacing too wide, lacking aesthetic appeal: Read references/visual-style.md.
  • Local short video with time points already determined: Directly execute the core process below.

Environment and Paths

Resolve <SKILL_DIR> as the absolute path of the directory containing the current SKILL.md; do not assume the Agent's working directory is the Skill directory.

# Local native subtitles
python3 "<SKILL_DIR>/scripts/check_environment.py"

# CJK script subtitles
python3 "<SKILL_DIR>/scripts/check_environment.py" --script-mode

# URL + script subtitles
python3 "<SKILL_DIR>/scripts/check_environment.py" --url-mode --script-mode

Core dependencies are Python 3.10+, Pillow, and FFmpeg or imageio-ffmpeg. URL mode additionally requires yt-dlp and the JavaScript runtime needed for full YouTube parsing. The environment check only reports the status; if dependencies are missing, first explain the purpose and obtain authorization, then run:

python3 -m pip install -r "<SKILL_DIR>/requirements.txt"

Do not modify the system Python, shell configuration, browser cookies, or package manager without authorization. Chrome Cookies are only a controlled recovery path after a cookie-less request is blocked by YouTube's login verification; before reading them for the first time, explain the purpose and obtain the user's authorization.

Common Default Layout

  • Native subtitles default to content-adaptive layout: preserve the source width, height is the sum of the main picture and subtitle band, and the entire image is uniformly scaled proportionally. When the user does not specify a ratio, do not proactively add --aspect 3:4.
  • Script subtitles default to output 3:4, 1440×1920.
  • Default to 5 strictly increasing time points: the first frame is the main picture, and the remaining four frames are subtitle bands.
  • Both modes support up to 7 time points per image (1 main picture + 6 subtitle bands); if there are more lines, split into multiple images, do not compress the subtitle bands.
  • For script fixed layout with 4 subtitle bands, the main picture occupies about 70%, and each band about 7.5%. Native mode does not enforce this ratio; the first and subsequent subtitles must maintain the same scaling factor; if the original video has different font sizes, preserve the difference, do not redraw text. The spacing between bands is 0 for both modes.
  • When native mode explicitly uses --aspect 3:4 or --layout fixed, the default --fit crop applies: automatically identify the left and right boundaries of each subtitle sentence, uniformly crop both sides of the entire stitched image, up to the subtitle safety margin, leaving black borders for any remaining excess; if any sentence's subtitle boundary cannot be identified, do not crop and keep edges on the entire image. If the person is off-center, use --crop-center (0–1) to move the cropping window; if the user requires no cropping of the picture, use --fit pad. Do not scale up the main picture alone to fill the canvas. --hero-fraction only adjusts the cropping height of the source main picture, limited by the actual frame height, and does not guarantee that proportion of the final canvas with borders. For script mode, pass it only when auto-layout is genuinely unsuitable.
  • Do not overwrite existing outputs. Only add --overwrite when the user explicitly requests replacement.
  • The renderer will abort on duplicate frames: when all time point frames are nearly identical (suspected static cover video or frozen frames), or when adjacent subtitle bands in native mode are nearly identical. First use sample to review the frames and explain to the user; do not add --allow-duplicate-frames just to generate an image; only add it after the user confirms it is necessary.
  • When the source video is low-resolution, it is possible to output at 1440×1920, but it must be stated that this does not equate to a real resolution improvement.

Preserve Original Frame Aspect Ratio

"Person's original proportion / do not crop landscape / original size" is a geometric requirement for the frame, not equivalent to choosing native subtitle mode. The subtitle source is still handled according to the user's choice.

  • When the user requires preserving the full landscape composition, use --layout natural: preserve the source width, height is the sum of the main picture and subtitle bands; do not force 3:4.
  • If --width is not passed, preserve the source width; if a width is passed, scale proportionally only. After cropping, do not resize the frame back to its original dimensions, and do not stretch the final output directly to 1440×1920.
  • Native subtitle mode preserves from the top of the frame to --band-bottom as the main picture and full subtitle band; do not redraw text.
  • Script subtitle mode can use --frame-top / --frame-bottom to crop only the unnecessary area of the source frame; default is to keep the full frame. First preview the boundaries; do not crop out essential parts of the person; --band-center is relative to the cropped frame.
  • natural does not work with --aspect / --hero-fraction; the 70% main picture acceptance criterion only applies to script fixed layout. Both layouts must not stretch non-proportionally.
python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" render-script VIDEO \
  --script script.json --out natural.jpg --layout natural \
  --frame-bottom 0.72

The 0.72 in the example is just a cropping example, not a default for all videos.

Common First Half Workflow

1. Check Source and Subtitle Type

Confirm if the video is local or a URL, the rights to use the material, video duration, language, and target number of images. Use real screenshots to determine whether the subtitles are burned-in or independent tracks; do not rely solely on whether VTT/SRT files were downloaded.

When time points are unclear, first generate an overview of candidate frames:

python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" sample VIDEO \
  --out candidate-contact-sheet.jpg

When candidate time points for lines are already available, generate three frames around each point (before, at, after):

python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" sample VIDEO \
  -t 61.2 -t 68.9 -t 74.5 -t 82.0 -t 88.4 \
  --around 0.8 --out focused-candidates.jpg

2. Select Theme and Stable Frames

One image expresses a single coherent idea. Candidate sentences need semantic progression, and each time point must be verifiable against the video. Avoid empty subtitles, repeated same-sentence, subtitle switching artifacts, transitions, black frames, ad overlays, player UI, and closed eyes.

Native Subtitle Mode

3A. Preview Subtitle Band

Start with single-line subtitles at 0.78–0.96; for two-line subtitles or when the position is higher, preview first, then expand to, e.g., 0.62–0.96.

python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" band VIDEO -t 61.2 \
  --band-top 0.78 --band-bottom 0.96 --out band-preview.jpg

4A. Create Manifest and Render

{
  "images": [
    {
      "title": "Model independent working duration is growing rapidly",
      "times": [61.6, 69.3, 75.0, 82.4, 88.8]
    }
  ]
}
python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" render VIDEO \
  --manifest manifest.json --out-dir OUTPUT_DIR \
  --band-top 0.78 --band-bottom 0.96

title is only used for the filename, not drawn into the image. times must come from stable frames that have been reviewed. Output includes individual JPGs, native_subtitle_timepoints.json, and final_contact_sheet.jpg.

Script Subtitle Mode

3B. Create Reviewed Time Points + Lines JSON

{
  "lines": [
    {"t": 61.6, "text": "First verified line"},
    {"t": 69.3, "text": "Second verified line"},
    {"t": 75.0, "text": "Third verified line"},
    {"t": 82.4, "text": "Fourth verified line"},
    {"t": 88.8, "text": "Fifth verified line"}
  ]
}
  • t must be strictly increasing and less than the video duration.
  • text must be verified single-line lines; if too long, split into sentences, do not force with tiny font size.
  • Translated lines must have their meaning, names, numbers, and proper nouns verified.
  • The first frame prioritizes expressions, gestures, and composition; subsequent frames prioritize line flow and background readability.

4B. Render Script Subtitles

python3 "<SKILL_DIR>/scripts/native_subtitle_stitch.py" render-script VIDEO \
  --script script.json --out OUTPUT.jpg \
  --aspect 3:4 --width 1440

The script will try common CJK fonts on macOS, Windows, and Linux. If it cannot find one automatically, specify an authorized font with --font /path/to/font.ttc. When adjusting the vertical sampling position of the subtitle band within the original frame, use --band-center; do not use it as a line spacing parameter.

Image-by-Image QA and Bounded Rework

First view a thumbnail overview, then open each full-size JPG.

  • Subtitles are complete, stable, non-repeating, and chronological order matches the original video.
  • Native mode has no character changes; script mode text matches the reviewed JSON.
  • Main subject is complete, no abnormal face-cutting, large blank areas, irrelevant UI, or deformation.
  • Native mode: check if the first and subsequent subtitles use the same scaling factor, no horizontal character cropping; fixed canvas allows outer margins. For --fit crop outputs, verify each image that both ends of each subtitle are complete and the person's face is not cut off by side cropping; in the delivery, indicate the cropping or margin result of the rendering output. For script fixed layout with four bands, the main picture occupies about 68–72%; there is no extra spacing between content blocks.
  • Script mode: font size, stroke, and contrast are readable at both full size and mobile thumbnail sizes.
  • File count, dimensions, ratio, JSON, and overview are consistent.

When issues are found, only adjust the corresponding variables: time points usually shift by 0.3–1.5 seconds; if native subtitles are cropped, adjust the band boundaries; if subtitle lines are too tall, first restore auto-layout; if text is too long, split sentences first. If stable frames cannot be found after three consecutive rounds, switch segments or report limitations; do not micro-tune indefinitely.

Collaboration with Other Tools or Skills

  • yt-dlp: Obtain online videos, metadata, and subtitle tracks the user is authorized to process; not responsible for final rendering.
  • Subtitle tracks or Whisper: Generate timestamped content indices. Native mode only uses it for positioning; script mode can write reviewed text into JSON.
  • Video understanding, topic selection, or content analysis Skills: Suggest topics, time ranges, and sentence order.
  • Writing Skill: Generate accompanying articles or posts; it cannot change on-screen subtitles in native mode.
  • This Skill: Manage final time points, real video frames, subtitle source identification, stitching, and visual QA.

Reuse already downloaded videos, transcripts, and caches from upstream; do not consume network or transcription resources again. Do not assume the user has a specific Skill installed by name; if upstream Skills are missing, independently perform minimal transcript reading and topic selection.

Stopping Conditions

  • The user does not have permission to download, process, or publish the source material.
  • The link requires bypassing DRM, paywalls, geo-restrictions, or other access controls.
  • The user requests native subtitles, but the frame has no burned-in subtitles; first explain, only switch to script mode with the user's consent.
  • Native mode cannot find frames with complete and stable subtitles.
  • Script mode lines or translations have not been verified, or no usable CJK font is available.
  • Source quality, occlusion, or UI is too severe to achieve a readable delivery.

When login, age verification, bot verification, or the user's own non-public video require cookies, authorization must be obtained first; after authorization, preferably let yt-dlp temporarily read the user's own logged-in session via --cookies-from-browser chrome, rather than having the user paste passwords or export cookie files. Do not write browser data into the repository.

Delivery

Provide the output path, individual outputs, timestamps/lines JSON, overview image, and completed visual and technical checks. Clearly mark the subtitle mode used. Only generate a ZIP when the user needs a share package; do not report images that have not been individually opened and checked as completed.

Related Skills