Skip to content

Shenrui-Ma/video-regen-recipes / templates/character-short/bit-by-bit-heartache

bit-by-bit-heartache

Verified

用角色参考图在本机制作 Heartache 连续动作配乐短片.

FileKindSize
.gitignoreother430 B
LICENSEother1.1 KB
LICENSES.mdmarkdown1.4 KB
README.mdmarkdown9.3 KB
SKILL.mdskill md7.3 KB
assets/README.mdmarkdown4.9 KB
assets/default/manifest.jsonconfig3.8 KB
assets/runtime-assets.jsonconfig5.5 KB
profile.jsonconfig3.8 KB
prompts/ref2va.template.txtmarkdown1.6 KB
prompts/yaoguang.historical.txtmarkdown5.0 KB
references/background-removal.mdmarkdown5.5 KB
references/changelog.mdmarkdown916 B
references/character-input.mdmarkdown4.7 KB
references/deployment.mdmarkdown4.9 KB
references/editing.mdmarkdown3.7 KB
references/environment.lock.jsonconfig1.5 KB
references/first-segment-validation.jsonconfig1.8 KB
references/generation.mdmarkdown3.8 KB
references/media-preflight.mdmarkdown4.2 KB
references/native-continuation.mdmarkdown17.8 KB
references/node-sources.jsonconfig6.7 KB
references/node-sources.mdmarkdown3.8 KB
references/package-verification.jsonconfig1.7 KB
references/reference-check.jsonconfig968 B
references/reproduction.mdmarkdown10.1 KB
references/validation.mdmarkdown2.6 KB
references/workflow-recovery.mdmarkdown2.2 KB
references/workflow.lock.jsonconfig1.2 KB
references/yaoguang-run.jsonconfig7.4 KB
scripts/character/prepare_character.pyscript6.5 KB
scripts/distribution/fetch_assets.pyscript5.8 KB
scripts/distribution/package_skill.pyscript5.6 KB
scripts/plan_segments.pyscript3.4 KB
scripts/prepare_driver.pyscript5.2 KB
scripts/render_default.pyscript5.5 KB
scripts/runtime/graphs.pyscript11.3 KB
scripts/runtime/heartache.pyscript14.6 KB
scripts/runtime/local_io.pyscript3.3 KB
scripts/runtime/media.pyscript13.2 KB
scripts/runtime/run_segment.pyscript13.3 KB
sources.mdmarkdown2.4 KB
tests/test_background_removal.pyscript2.6 KB
tests/test_character_input.pyscript12.2 KB
tests/test_default.pyscript879 B
tests/test_distribution.pyscript12.3 KB
tests/test_media_preflight.pyscript2.1 KB
tests/test_prepare_driver.pyscript1.9 KB
tests/test_release_review.pyscript1.7 KB
tests/test_reproduction.pyscript1.9 KB
tests/test_runtime_cli.pyscript11.3 KB
tests/test_runtime_graph.pyscript4.8 KB
tests/test_runtime_io.pyscript2.1 KB
tests/test_runtime_media.pyscript10.2 KB
tests/test_runtime_runner.pyscript1.6 KB
tests/test_segment_plan.pyscript3.4 KB
tests/test_skill_contract.pyscript1.6 KB
workflows/continue.editor.jsonconfig23.8 KB
workflows/first.editor.jsonconfig19.8 KB
workflows/node-schema.jsonconfig22.2 KB
workflows/provenance.jsonconfig911 B

scripts/render_default.py

View on GitHub
#!/usr/bin/env python3
"""Validate the bundled editing sources; explicitly opt in to re-editing, without H3."""
import argparse
from fractions import Fraction
import hashlib
import json
from pathlib import Path
import subprocess
import tempfile

ROOT = Path(__file__).resolve().parents[1]
KEEP = [395, 373, 382, 437]
SOURCE_FRAMES = [158, 158, 175, 175]
FPS = 60


def sha(path):
    result = hashlib.sha256()
    with path.open('rb') as stream:
        for block in iter(lambda: stream.read(1024 * 1024), b''):
            result.update(block)
    return result.hexdigest()


def run(argv):
    result = subprocess.run(argv, capture_output=True, timeout=300)
    if result.returncode:
        raise ValueError('Media command failed; inspect the local input and installed FFmpeg.')
    return result.stdout


def probe(path):
    return json.loads(run(['ffprobe', '-v', 'error', '-count_frames', '-show_streams', '-show_format', '-of', 'json', str(path)]))


def filter_graph():
    parts = [f'[{i}:v]fps=60,trim=start_frame=0:end_frame={n},setpts=PTS-STARTPTS[v{i}]' for i,n in enumerate(KEEP)]
    parts += ['[v0][v1][v2][v3]concat=n=4:v=1:a=0,setsar=1[v]',
              '[4:a:0]atrim=start=0:end=26.45,asetpts=PTS-STARTPTS,afade=t=out:st=25.95:d=0.5[a]']
    return ';'.join(parts)


def validate(music=None):
    folder = ROOT/'assets/default'
    manifest = json.loads((folder/'manifest.json').read_text(encoding='utf-8'))
    records = {entry['path']: entry for entry in manifest['assets']}
    clips = [folder/f'clips/part-{i:02d}.mp4' for i in range(1,5)]
    for clip,frames in zip(clips,SOURCE_FRAMES):
        entry = records[clip.relative_to(folder).as_posix()]
        if sha(clip) != entry['sha256']:
            raise ValueError('Default clip hash mismatch; do not use this timing on different source frames.')
        videos = [s for s in probe(clip)['streams'] if s['codec_type']=='video']
        if len(videos)!=1:
            raise ValueError('Expected one video stream.')
        v=videos[0]
        if (int(v['nb_read_frames']),v['width'],v['height'],Fraction(v['avg_frame_rate'])) != (frames,1344,768,Fraction(24)):
            raise ValueError('Default clip geometry, FPS or frame count differs from this preset.')
    selected_music = Path(music).resolve() if music else folder/'music.m4a'
    if not music and sha(selected_music)!=records['music.m4a']['sha256']:
        raise ValueError('Default music hash mismatch.')
    audio=[s for s in probe(selected_music)['streams'] if s['codec_type']=='audio']
    if len(audio)!=1 or float(audio[0].get('duration',0))<26.45:
        raise ValueError('Choose a single audio track at least 26.45 seconds long; no silent padding is applied.')
    return clips,selected_music


def render(clips,music,output):
    output=Path(output).resolve()
    if output.suffix.lower()!='.mp4' or output.exists():
        raise ValueError('Choose a new .mp4 output file.')
    output.parent.mkdir(parents=True,exist_ok=True)
    with tempfile.TemporaryDirectory(prefix='heartache-edit-',dir=output.parent) as tmp:
        target=Path(tmp)/'render.mp4'
        command=['ffmpeg','-nostdin','-v','error','-n']
        for clip in clips: command += ['-i',str(clip)]
        command += ['-i',str(music),'-filter_complex',filter_graph(),'-map','[v]','-map','[a]',
                    '-c:v','libx264','-preset','medium','-crf','18','-pix_fmt','yuv420p','-r','60',
                    '-c:a','aac','-b:a','320k','-ar','44100','-ac','2','-t','26.45',
                    '-map_metadata','-1','-map_metadata:s','-1','-map_chapters','-1','-movflags','+faststart',str(target)]
        run(command)
        media=probe(target)
        video=[s for s in media['streams'] if s['codec_type']=='video'][0]
        audio=[s for s in media['streams'] if s['codec_type']=='audio']
        if int(video['nb_read_frames'])!=sum(KEEP) or Fraction(video['avg_frame_rate'])!=FPS or not audio:
            raise ValueError('Rendered media does not match the timeline; no output published.')
        if abs(float(audio[0].get('duration',0))-26.45)>0.1:
            raise ValueError('Rendered audio duration differs from the timeline.')
        run(['ffmpeg','-nostdin','-v','error','-xerror','-i',str(target),'-map','0:v:0','-map','0:a:0','-f','null','-'])
        # Exclusive creation prevents overwriting another output made during rendering.
        with output.open('xb') as dest, target.open('rb') as src:
            for block in iter(lambda:src.read(1024*1024),b''):dest.write(block)
    return {'frames':1587,'fps':60,'sha256':sha(output),'visual_review':'pending','audio_review':'pending'}


def main():
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--music',type=Path,help='Optional replacement soundtrack; otherwise use the bundled music.')
    parser.add_argument('--output',type=Path)
    parser.add_argument('--execute',action='store_true')
    args=parser.parse_args()
    try:
        clips,music=validate(args.music)
        if args.execute:
            if not args.output:raise ValueError('--execute requires --output.')
            result=render(clips,music,args.output)
        else:
            result={'status':'checked-not-rendered','frames':sum(KEEP),'fps':FPS,'seconds':sum(KEEP)/FPS,'inference':False}
        print(json.dumps(result,ensure_ascii=False))
    except (ValueError,OSError,KeyError,subprocess.SubprocessError) as exc:
        print('Stopped: '+str(exc) if isinstance(exc,ValueError) else 'Stopped: check local files and FFmpeg installation.')
        return 1
    return 0


if __name__=='__main__':
    raise SystemExit(main())
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: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated 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: 194kUpdated Claude CodeCodexVerifiedInstall