Skip to content

zenstory-ai/video-recap-skills / skills/video-recap

video-recap

Verified

把一段或多集视频做成带画框字幕的中文解说成片或纯原声高光短片。用户提供 .mp4 / .mov / .mkv / .webm,要求做影视解说、短剧二创、加旁白配音、跨集混剪或导出剪映草稿时使用;串联完成看片识台词、定主线与留原声、按台词停顿切镜头、写词检查、TTS 配音与混音加字幕。触发词:视频解说、影视解说、视频旁白、生成解说、视频 recap、video recap、voiceover、narration、recap。

FileKindSize
SKILL.mdskill md18.4 KB
assets/dashboard/app.jsscript16.2 KB
assets/dashboard/index.htmlother867 B
assets/dashboard/styles.cssother22.6 KB
assets/dashboard/tokens.cssother8.9 KB
assets/dashboard/views.jsscript31.4 KB
references/audio-modes.mdmarkdown3.6 KB
references/config-playbook.mdmarkdown8.1 KB
references/creative-editing-playbook.mdmarkdown12.3 KB
references/data-schema.mdmarkdown34.6 KB
references/index-tts.mdmarkdown2.1 KB
references/jianying/LICENSE.duo-videoother1.0 KB
references/jianying/SOURCE.mdmarkdown703 B
references/jianying/empty_draft_meta_info.jsonconfig1.7 KB
references/jianying/empty_jy_material_video.jsonconfig1.8 KB
references/jianying/empty_jy_meta_material_value.jsonconfig358 B
references/jianying/empty_jy_project_info.jsonconfig3.6 KB
references/jianying/empty_jy_segment.jsonconfig1.3 KB
references/jianying/empty_jy_text_styles.jsonconfig440 B
references/jianying/empty_yj_material_audio.jsonconfig865 B
references/jianying/empty_yj_material_text.jsonconfig2.4 KB
references/packaging.mdmarkdown6.8 KB
references/promotional-copy.mdmarkdown4.1 KB
references/prompt-templates.mdmarkdown2.0 KB
references/research-guide.mdmarkdown2.7 KB
references/resource-library.mdmarkdown12.1 KB
references/shot-review.mdmarkdown4.8 KB
scripts/agent_text.pyscript2.7 KB
scripts/artifacts.pyscript972 B
scripts/asr.pyscript12.5 KB
scripts/asr_timing_evidence.pyscript4.2 KB
scripts/assemble.pyscript31.0 KB
scripts/assemble_constants.pyscript894 B
scripts/assembly_contract.pyscript10.3 KB
scripts/assembly_settings.pyscript3.8 KB
scripts/audio_automation.pyscript6.6 KB
scripts/audio_mix.pyscript18.5 KB
scripts/briefing/__init__.pyscript101 B
scripts/briefing/builder.pyscript31.1 KB
scripts/briefing/context.pyscript6.1 KB
scripts/briefing/timeline.pyscript23.0 KB
scripts/codec_peak.pyscript5.1 KB
scripts/cut.pyscript148 B
scripts/cut_cli.pyscript12.4 KB
scripts/cut_contract.pyscript13.3 KB
scripts/cut_qc.pyscript1.9 KB
scripts/cut_render.pyscript13.2 KB
scripts/dashboard/__init__.pyscript159 B
scripts/dashboard/data.pyscript24.6 KB
scripts/dashboard/io.pyscript7.1 KB
scripts/dashboard/runs.pyscript21.8 KB
scripts/dashboard/templates.pyscript9.6 KB
scripts/dashboard_server.pyscript9.3 KB
scripts/detect.pyscript22.2 KB
scripts/doctor.pyexecutablescript12.9 KB
scripts/entry_suggestion.pyscript4.6 KB
scripts/export_jianying.pyscript5.6 KB
scripts/extract.pyscript2.5 KB
scripts/final_qc.pyscript19.0 KB
scripts/frame_grid.pyscript10.6 KB
scripts/jianying/__init__.pyscript49 B
scripts/jianying/builders.pyscript11.3 KB
scripts/jianying/model.pyscript2.7 KB
scripts/jianying/optional.pyscript1012 B
scripts/jianying/schema.pyscript2.5 KB
scripts/jianying/templates.pyscript1.0 KB
scripts/jianying/timeline_contract.pyscript5.8 KB
scripts/jianying/tracks.pyscript2.0 KB
scripts/jianying/writer.pyscript7.8 KB
scripts/lib.pyscript29.6 KB
scripts/library.pyscript31.1 KB
scripts/lint_summary.pyscript5.0 KB
scripts/loudness.pyscript14.7 KB
scripts/materials.pyscript22.1 KB
scripts/media.pyscript18.8 KB
scripts/narration_audio.pyscript13.5 KB
scripts/narration_lint.pyscript24.1 KB
scripts/narrative_selection.pyscript8.9 KB
scripts/packaging.pyscript6.1 KB
scripts/packaging_fonts.pyscript12.0 KB
scripts/packaging_plates.pyscript31.2 KB
scripts/packaging_studio.pyscript34.1 KB
scripts/providers/__init__.pyscript72 B
scripts/providers/fish_audio.pyscript3.1 KB
scripts/providers/index_tts.pyscript8.8 KB
scripts/recap.pyscript183 B
scripts/recap_cli.pyscript6.9 KB
scripts/recap_inspect.pyscript16.5 KB
scripts/recap_runner.pyscript22.0 KB
scripts/recap_runtime.pyscript11.8 KB
scripts/recap_source.pyscript1.8 KB
scripts/recap_stage_qc.pyscript2.7 KB
scripts/recap_timeline.pyscript7.7 KB
scripts/render_preflight.pyscript1.7 KB
scripts/resources/__init__.pyscript200 B
scripts/resources/lock.pyscript6.8 KB
scripts/resources/project_binding.pyscript16.1 KB
scripts/sentence_boundaries.pyscript28.8 KB
scripts/sentence_gate.pyscript8.6 KB
scripts/sfx_mix.pyscript14.6 KB
scripts/shot_review.pyscript18.9 KB
scripts/source_subtitles.pyscript7.2 KB
scripts/speech_ownership.pyscript9.3 KB
scripts/storyboard.pyscript21.8 KB
scripts/subtitles/__init__.pyscript56 B
scripts/subtitles/core.pyscript19.0 KB
scripts/subtitles/render.pyscript8.0 KB
scripts/timeline.pyscript8.2 KB
scripts/timeline_emit.pyscript5.4 KB
scripts/tts_audio.pyscript9.6 KB
scripts/tts_cache.pyscript4.5 KB
scripts/understand.pyscript171 B
scripts/understanding_brief.pyscript6.3 KB
scripts/understanding_cache.pyscript8.0 KB
scripts/understanding_runner.pyscript9.8 KB
scripts/understanding_storyboard.pyscript11.9 KB
scripts/validate.pyscript5.7 KB
scripts/visual_render.pyscript10.1 KB
scripts/vlm.pyscript16.4 KB
scripts/voiceover.pyscript28.0 KB

scripts/visual_render.py

View on GitHub
"""Subtitle layout QC, source-subtitle masking, and video filter helpers."""

import json
import re
from pathlib import Path

from assemble_constants import (
    SUBTITLE_STYLE_REF_H,
    VISUAL_QC,
)
from audio_automation import coalesce_duck_windows
from audio_mix import _seg_place_window
from lib import CONFIG, escape_ffmpeg_filter_path
from source_subtitles import (
    _combined_subtitle_entries,
    _source_subtitle_mask,
)
from subtitles.core import (
    _effective_subtitle_style,
    _frame_row,
    _measured_subtitle_band,
    _measured_subtitle_safe_area,
    _normalize_subtitle_text,
    _style_for_measured_subtitle_band,  # noqa: F401 — re-exported for assemble tests
    _subtitle_style_config,
)


def _visual_text_units(text):
    """Approximate visual text width in em units for deterministic geometry QC."""
    units = 0.0
    for ch in text:
        if ch.isspace():
            units += 0.35
        elif ord(ch) < 128:
            units += 0.56
        else:
            units += 1.0
    return units


def _subtitle_layout_qc(entries, style, safe_area=None):
    """Machine-check subtitle safe-area/multiline/overflow facts for visual_qc.json."""
    play_x = int(style["play_res_x"])
    play_y = int(style["play_res_y"])
    margin_l = int(style["margin_l"])
    margin_r = int(style["margin_r"])
    margin_v = int(style["margin_v"])
    font_size = float(style["font_size"])
    max_lines = CONFIG["subtitle_max_lines"]
    if safe_area is None:
        safe_area = {
            "x": margin_l,
            "y": margin_v,
            "width": max(1, play_x - margin_l - margin_r),
            "height": max(1, play_y - 2 * margin_v),
            "bottom_margin": margin_v,
        }
    usable_w = float(safe_area["width"])
    line_h = font_size * 1.25
    overflow_entries = []
    entry_facts = []
    for i, entry in enumerate(entries):
        raw_text = _normalize_subtitle_text(entry["text"])
        lines = [ln for ln in re.split(r"(?:\\N|\n)+", raw_text) if ln != ""] or [""]
        line_count = len(lines)
        max_w = max(_visual_text_units(line) * font_size for line in lines)
        band_h = line_count * line_h + float(style["outline"]) * 2 + float(style["shadow"])
        overflow_reasons = []
        if line_count > max_lines:
            overflow_reasons.append("max_lines_exceeded")
        if max_w > usable_w + 1e-6:
            overflow_reasons.append("safe_width_exceeded")
        if band_h > safe_area["height"] + 1e-6:
            overflow_reasons.append("safe_height_exceeded")
        fact = {
            "index": i,
            "start": round(float(entry["start"]), 3),
            "end": round(float(entry["end"]), 3),
            "line_count": line_count,
            "max_line_width": round(max_w, 2),
            "safe_width": round(usable_w, 2),
            "band_height": round(band_h, 2),
            "overflow": bool(overflow_reasons),
            "overflow_reasons": overflow_reasons,
        }
        entry_facts.append(fact)
        if overflow_reasons:
            overflow_entries.append(fact)
    return {
        "enabled": CONFIG["burn_subtitles"],
        "renderer": "ass" if CONFIG["burn_subtitles"] else "sidecar_srt",
        "burn_degraded_reason": CONFIG["burn_subtitles_degraded"],
        "style": {
            "font_size": int(font_size),
            "max_chars": int(style["max_chars"]),
            "max_lines": max_lines,
            "play_res_x": play_x,
            "play_res_y": play_y,
            "alignment": int(style["alignment"]),
            "margin_l": margin_l,
            "margin_r": margin_r,
            "margin_v": margin_v,
        },
        "safe_area": safe_area,
        "entries": len(entry_facts),
        "overflow": bool(overflow_entries),
        "overflow_entries": overflow_entries,
        "entry_facts": entry_facts,
    }


def _subtitle_delivery_warnings(mask, *, has_subtitles):
    """Non-blocking, machine-readable record of a default burn that degraded to the sidecar."""
    reason = CONFIG["burn_subtitles_degraded"]
    if not reason or not has_subtitles:
        return []
    return [{
        "code": "subtitle_burn_degraded",
        "reason": reason,
        "delivered": "sidecar_srt",
        "mask_dropped": mask["trigger"] == "burn_subtitles_degraded",
        "message": (
            "当前 ffmpeg 缺少 libass/subtitles 滤镜:字幕未烧录进画面,"
            "已改为在成片旁输出同名 .srt 外挂字幕"
        ),
        "next_action": "如需烧录硬字幕,请安装带 libass 的 ffmpeg 后重跑,或直接随成片交付外挂 .srt 字幕",
    }]


def _build_visual_qc(
    tts_segments, work_dir, video_duration, canvas, *, mask_filter=None, packaging_qc=None
):
    style = _effective_subtitle_style(canvas, work_dir)
    if (
        int(style["max_chars"]) == int(CONFIG["subtitle_max_chars"])
        and float(style.get("bridge_gap_seconds", 0.0)) <= 0.0
        and packaging_qc is None
    ):
        entries = _combined_subtitle_entries(tts_segments, work_dir, video_duration)
    else:
        entries = _combined_subtitle_entries(
            tts_segments,
            work_dir,
            video_duration,
            max_chars=int(style["max_chars"]),
            bridge_gap_seconds=float(style.get("bridge_gap_seconds", 0.0)),
        )
    subtitle_layout = _subtitle_layout_qc(
        entries,
        style,
        safe_area=(
            None
            if packaging_qc is not None
            else _measured_subtitle_safe_area(style, canvas, work_dir=work_dir)
        ),
    )
    mask = _source_subtitle_mask()
    mask.update({
        "ratio": min(0.5, CONFIG["source_subtitle_mask_ratio"]) if mask["active"] else None,
        "filter": "drawbox" if mask_filter else None,
        "opacity": CONFIG["subtitle_mask_opacity"],
        "timing": CONFIG["source_subtitle_mask_timing"],
        "subtitle_y_top": CONFIG["subtitle_y_top"],
        "subtitle_y_bot": CONFIG["subtitle_y_bot"],
    })
    warnings = _subtitle_delivery_warnings(mask, has_subtitles=bool(entries))
    if packaging_qc and packaging_qc.get("warnings"):
        warnings.extend(packaging_qc["warnings"])
    blocking_codes = []
    if subtitle_layout["overflow"]:
        blocking_codes.append("subtitle_overflow")
    if packaging_qc and packaging_qc.get("blocking_codes"):
        blocking_codes.extend(packaging_qc["blocking_codes"])
    geometry = {
        "canvas": {
            "width": canvas["width"],
            "height": canvas["height"],
            "fps": canvas["fps"],
        },
        "storage": {
            "width": canvas["storage_width"],
            "height": canvas["storage_height"],
        },
        "rotation": canvas["rotation"],
        "sample_aspect_ratio": canvas["sample_aspect_ratio"],
        "display_aspect_ratio": canvas["display_aspect_ratio"],
    }
    if packaging_qc is not None:
        geometry["packaging"] = {
            k: v for k, v in packaging_qc.items() if k not in {"blocking_codes", "warnings"}
        }
    return {
        "schema_version": 1,
        "artifact": VISUAL_QC,
        "verdict": "FAIL" if blocking_codes else "PASS",
        "blocking": bool(blocking_codes),
        "blocking_codes": blocking_codes,
        "warnings": warnings,
        "geometry": geometry,
        "subtitles": subtitle_layout,
        "mask": mask,
    }


def _write_visual_qc(work_dir, qc):
    path = Path(work_dir) / VISUAL_QC
    path.write_text(json.dumps(qc, ensure_ascii=False, indent=2), encoding="utf-8")
    return path


def _escape_subtitle_filter_path(path):
    """Escape a path for ffmpeg subtitle/ass video filter arguments."""
    return escape_ffmpeg_filter_path(path)


def _subtitle_burn_filter(subtitle_path, font_file=None):
    """Build the ffmpeg video filter used for hard-sub rendering."""
    filt = f"subtitles=filename='{_escape_subtitle_filter_path(subtitle_path)}'"
    effective_font_file = font_file if font_file is not None else CONFIG["subtitle_font_file"]
    if effective_font_file:
        fonts_dir = Path(effective_font_file).expanduser().resolve().parent
        filt += f":fontsdir='{_escape_subtitle_filter_path(fonts_dir)}'"
    return filt


def _output_downscale_filter(max_h):
    """Lanczos downscale that forces BOTH output dimensions even (libx264/yuv420p need it)."""
    return f"scale=-2:'2*trunc(min(ih,{max_h})/2)':flags=lanczos"


def _source_subtitle_mask_filter(canvas, work_dir, tts_segments, video_duration):
    """Return source-subtitle drawbox filters, optionally scoped to narration windows."""
    if not _source_subtitle_mask()["active"]:
        return None
    opacity = CONFIG["subtitle_mask_opacity"]
    timing = CONFIG["source_subtitle_mask_timing"]
    if timing not in {"all", "narration"}:
        raise ValueError(f"SOURCE_SUBTITLE_MASK_TIMING 必须是 all 或 narration,当前为 {timing!r}")

    band = _measured_subtitle_band(canvas)
    if band is not None:
        y_top, y_bot = band
        padding = CONFIG["subtitle_mask_padding"]
        mask_top = _frame_row(canvas, max(0, y_top - padding))
        mask_bot = _frame_row(canvas, min(canvas["height"], y_bot + padding))
        geometry = f"x=0:y={mask_top}:w=iw:h={mask_bot - mask_top}"
    else:
        style = _subtitle_style_config(canvas)
        play_res_y = float(style["play_res_y"])
        line_h = float(style["font_size"]) * 1.25
        pad = 10.0 * play_res_y / SUBTITLE_STYLE_REF_H
        sub_band = (float(style["margin_v"]) + line_h + pad) / play_res_y
        ratio = min(0.5, max(CONFIG["source_subtitle_mask_ratio"], sub_band))
        geometry = f"x=0:y=ih-ih*{ratio:.3f}:w=iw:h=ih*{ratio:.3f}"

    base = f"drawbox={geometry}:color=black@{opacity:.2f}:t=fill"
    filters = []
    if opacity > 0:
        if timing == "all":
            filters.append(base)
        else:
            windows = [
                (start, end, 0.0)
                for start, end in map(_seg_place_window, tts_segments)
                if end > start
            ]
            filters.extend(
                f"{base}:enable='between(t,{start:.3f},{end:.3f})'"
                for start, end, _ in coalesce_duck_windows(windows, bridge=0.001)
            )
    return ",".join(filters) if filters else None
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall