PropmtEditor / edit /build_base.py
Prompt48's picture
Upload edit/build_base.py with huggingface_hub
6819784 verified
Raw
History Blame Contribute Delete
1.72 kB
"""Build the cut 1080p base with dense keyframes for HyperFrames.
Extracts each keep-segment at 1080p (re-encode, dense keyframes, 30ms boundary audio fades),
concats losslessly. Output: hf/base_full.mp4
"""
import subprocess
from pathlib import Path
from cutmap import keep_segments, out_duration
SRC = r"D:\PromptEngineer48\In-Progress\P11-Editor\LMSTUDIO-MTP1.mp4"
EDIT = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit")
SEG_DIR = EDIT / "clips"
SEG_DIR.mkdir(exist_ok=True)
segs = keep_segments()
parts = []
for i, (a, b) in enumerate(segs):
dur = b - a
out = SEG_DIR / f"seg{i:02d}.mp4"
# 30ms fades at boundaries to avoid pops
af = f"afade=t=in:st=0:d=0.03,afade=t=out:st={max(dur-0.03,0):.3f}:d=0.03"
cmd = [
"ffmpeg", "-y", "-ss", f"{a:.3f}", "-i", SRC, "-t", f"{dur:.3f}",
"-vf", "scale=1920:1080:flags=lanczos",
"-c:v", "libx264", "-crf", "18", "-preset", "medium",
"-g", "30", "-keyint_min", "30", "-sc_threshold", "0",
"-af", af, "-c:a", "aac", "-b:a", "192k",
"-movflags", "+faststart", str(out),
]
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
parts.append(out)
print(f" seg{i:02d}: {a:.2f}-{b:.2f} ({dur:.2f}s)")
# concat
listfile = SEG_DIR / "concat.txt"
listfile.write_text("\n".join(f"file '{p.as_posix()}'" for p in parts))
base = EDIT / "hf" / "base_full.mp4"
subprocess.run(["ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", str(listfile),
"-c", "copy", "-movflags", "+faststart", str(base)],
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print(f"base -> {base} (expected out duration {out_duration():.2f}s)")