Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Gera uma tira com 1 quadro por segundo de um MP4 (qualquer FPS e duração).
|
|
|
|
Economiza tokens: o agente lê UMA imagem em vez de vários quadros soltos.
|
|
Saída: <pasta da execução>/inspect/strip.png (ou ao lado do MP4).
|
|
|
|
Uso:
|
|
python .claude/skills/cenaforge/scripts/inspect_strip.py output/runs/<execução>
|
|
python .claude/skills/cenaforge/scripts/inspect_strip.py video.mp4 --width 160
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import math
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from _common import find_tool, rel, utf8_stdout
|
|
|
|
|
|
def main() -> int:
|
|
utf8_stdout()
|
|
ap = argparse.ArgumentParser(description="Tira de 1 quadro por segundo de um MP4.")
|
|
ap.add_argument("target", help="pasta de execução ou arquivo .mp4")
|
|
ap.add_argument("--width", type=int, default=180, help="largura de cada quadro na tira")
|
|
ap.add_argument("--cols", type=int, default=7)
|
|
args = ap.parse_args()
|
|
|
|
target = Path(args.target).resolve()
|
|
if target.is_dir():
|
|
mp4s = sorted(target.glob("*.mp4"))
|
|
if not mp4s:
|
|
print("nenhum .mp4 em", rel(target))
|
|
return 1
|
|
mp4, out_dir = mp4s[0], target / "inspect"
|
|
else:
|
|
mp4, out_dir = target, target.parent
|
|
ffmpeg, ffprobe = find_tool("ffmpeg"), find_tool("ffprobe")
|
|
if not ffmpeg or not ffprobe:
|
|
print("ffmpeg/ffprobe não encontrados (PATH ou FFMPEG_BIN/FFPROBE_BIN)")
|
|
return 1
|
|
|
|
probe = subprocess.run(
|
|
[ffprobe, "-v", "error", "-select_streams", "v:0", "-count_frames",
|
|
"-show_entries", "stream=r_frame_rate,nb_read_frames", "-of", "json", str(mp4)],
|
|
capture_output=True, text=True)
|
|
if probe.returncode != 0:
|
|
print("ffprobe falhou:", probe.stderr.strip()[-300:])
|
|
return 1
|
|
stream = json.loads(probe.stdout)["streams"][0]
|
|
num, den = (int(x) for x in stream["r_frame_rate"].split("/"))
|
|
fps = round(num / den)
|
|
count = math.ceil(int(stream["nb_read_frames"]) / fps)
|
|
cols = min(args.cols, count)
|
|
rows = math.ceil(count / cols)
|
|
|
|
out_dir.mkdir(parents=True, exist_ok=True)
|
|
out = out_dir / "strip.png"
|
|
vf = f"select='not(mod(n\\,{fps}))',scale={args.width}:-1,tile={cols}x{rows}"
|
|
r = subprocess.run([ffmpeg, "-hide_banner", "-loglevel", "error", "-y", "-i", str(mp4),
|
|
"-vf", vf, "-frames:v", "1", "-fps_mode", "vfr", str(out)],
|
|
capture_output=True, text=True)
|
|
if r.returncode != 0:
|
|
print("ffmpeg falhou:", r.stderr.strip()[-300:])
|
|
return 1
|
|
print(f"{rel(out)} ({count} quadros, 0..{count - 1} s, grade {cols}x{rows}, {fps} FPS)")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|