Upload edit\build_base.py with huggingface_hub
Browse files- edit//build_base.py +41 -0
edit//build_base.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build the cut 1080p base with dense keyframes for HyperFrames.
|
| 2 |
+
|
| 3 |
+
Extracts each keep-segment at 1080p (re-encode, dense keyframes, 30ms boundary audio fades),
|
| 4 |
+
concats losslessly. Output: hf/base_full.mp4
|
| 5 |
+
"""
|
| 6 |
+
import subprocess
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from cutmap import keep_segments, out_duration
|
| 9 |
+
|
| 10 |
+
SRC = r"D:\PromptEngineer48\In-Progress\P11-Editor\LMSTUDIO-MTP1.mp4"
|
| 11 |
+
EDIT = Path(r"D:\PromptEngineer48\In-Progress\P11-Editor\edit")
|
| 12 |
+
SEG_DIR = EDIT / "clips"
|
| 13 |
+
SEG_DIR.mkdir(exist_ok=True)
|
| 14 |
+
|
| 15 |
+
segs = keep_segments()
|
| 16 |
+
parts = []
|
| 17 |
+
for i, (a, b) in enumerate(segs):
|
| 18 |
+
dur = b - a
|
| 19 |
+
out = SEG_DIR / f"seg{i:02d}.mp4"
|
| 20 |
+
# 30ms fades at boundaries to avoid pops
|
| 21 |
+
af = f"afade=t=in:st=0:d=0.03,afade=t=out:st={max(dur-0.03,0):.3f}:d=0.03"
|
| 22 |
+
cmd = [
|
| 23 |
+
"ffmpeg", "-y", "-ss", f"{a:.3f}", "-i", SRC, "-t", f"{dur:.3f}",
|
| 24 |
+
"-vf", "scale=1920:1080:flags=lanczos",
|
| 25 |
+
"-c:v", "libx264", "-crf", "18", "-preset", "medium",
|
| 26 |
+
"-g", "30", "-keyint_min", "30", "-sc_threshold", "0",
|
| 27 |
+
"-af", af, "-c:a", "aac", "-b:a", "192k",
|
| 28 |
+
"-movflags", "+faststart", str(out),
|
| 29 |
+
]
|
| 30 |
+
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 31 |
+
parts.append(out)
|
| 32 |
+
print(f" seg{i:02d}: {a:.2f}-{b:.2f} ({dur:.2f}s)")
|
| 33 |
+
|
| 34 |
+
# concat
|
| 35 |
+
listfile = SEG_DIR / "concat.txt"
|
| 36 |
+
listfile.write_text("\n".join(f"file '{p.as_posix()}'" for p in parts))
|
| 37 |
+
base = EDIT / "hf" / "base_full.mp4"
|
| 38 |
+
subprocess.run(["ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", str(listfile),
|
| 39 |
+
"-c", "copy", "-movflags", "+faststart", str(base)],
|
| 40 |
+
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 41 |
+
print(f"base -> {base} (expected out duration {out_duration():.2f}s)")
|