Spaces:
Sleeping
Sleeping
File size: 2,329 Bytes
37516ca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import sys, shutil, argparse
from pathlib import Path
from datetime import datetime
APP_PATH = Path.home() / "Fenix" / "ltx_service.py"
ANCHOR = " shutil.copy(ruta, destino)\n mat = destino"
REPLACEMENT = """ shutil.copy(ruta, destino)
# --- PARCHE: normalizar clip a H.264 + yuv420p ---
import subprocess
destino_norm = destino.replace(".mp4", "_norm.mp4")
cmd = [
"ffmpeg", "-y", "-i", destino,
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
"-r", "24",
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2",
"-movflags", "+faststart",
destino_norm
]
r = subprocess.run(cmd, capture_output=True, text=True)
norm_path = Path(destino_norm)
if r.returncode != 0 or not norm_path.exists() or norm_path.stat().st_size < 10_240:
print(f"[LTX] ERROR normalizando {destino}:\\n{r.stderr}", flush=True)
raise RuntimeError(f"Clip normalizado invalido: {destino_norm}")
print(f"[LTX] Normalizado OK: {destino_norm} ({norm_path.stat().st_size // 1024} KB)", flush=True)
destino = destino_norm
# --- FIN PARCHE ---
mat = destino"""
parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
original = APP_PATH.read_text(encoding="utf-8")
if ANCHOR not in original:
print("[ERROR] Anclaje no encontrado.")
sys.exit(1)
if "PARCHE: normalizar clip" in original:
print("[INFO] Parche ya aplicado.")
sys.exit(0)
patched = original.replace(ANCHOR, REPLACEMENT, 1)
if args.dry_run:
print("[DRY RUN] Anclaje encontrado. Listo para aplicar.")
sys.exit(0)
backup = Path(str(APP_PATH) + datetime.now().strftime(".bak_%Y%m%d_%H%M%S"))
shutil.copy2(APP_PATH, backup)
print(f"[OK] Backup: {backup}")
APP_PATH.write_text(patched, encoding="utf-8")
print("[OK] Parche aplicado. Ahora: git add ltx_service.py && git commit -m 'fix: normalizar clips LTX' && git push")
|