-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·79 lines (67 loc) · 2.89 KB
/
Copy pathmain.py
File metadata and controls
executable file
·79 lines (67 loc) · 2.89 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""CRAZY VIDEO GLITCH EDITOR — launcher.
GUI: python main.py
CLI: python main.py input.mp4 output.mp4 --preset brainfuck [--datamosh] [--speed 2]
"""
from __future__ import annotations
import sys
def run_cli(argv):
import argparse
from glitchcore import presets, beat, media
from glitchcore.renderer import render, RenderOptions
ap = argparse.ArgumentParser(description="Crazy video glitch editor (CLI)")
ap.add_argument("input")
ap.add_argument("output")
ap.add_argument("--preset", default="brainfuck", choices=list(presets.PRESETS))
ap.add_argument("--datamosh", action="store_true")
ap.add_argument("--speed", type=float, default=1.0)
ap.add_argument("--seed", type=int, default=1337)
args = ap.parse_args(argv)
import os
import tempfile
info = media.probe(args.input)
beats = []
if info.has_audio:
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tf:
wav = tf.name
try:
if media.extract_audio(args.input, wav):
beats = beat.detect_beats(wav)["beats"]
finally:
os.path.exists(wav) and os.remove(wav)
if not beats:
beats = beat.grid_beats(info.duration, 120.0)
chain = presets.build(args.preset, seed=args.seed)
dm = args.datamosh or args.preset in presets.WANTS_DATAMOSH
print(f"Rendering '{args.preset}' (datamosh={dm}, speed={args.speed})…")
render(args.input, args.output, chain, beats,
RenderOptions(speed=args.speed, datamosh=dm),
progress=lambda f, m: print(f"\r{f*100:5.1f}% {m}", end="", flush=True))
print(f"\nDone -> {args.output}")
def run_gui():
import os
import PySide6
from PySide6 import QtWidgets
from gui.main_window import MainWindow # importing this pulls in cv2
# opencv-python bundles its own (Qt5) Qt plugins and unconditionally points
# QT_QPA_PLATFORM_PLUGIN_PATH at them on import, shadowing PySide6's Qt6
# "xcb" plugin. The GUI then aborts with "Could not find the Qt platform
# plugin xcb" — reliably reproducible when launched from the .desktop entry
# (a bare desktop session, no shell to repair the fallback). Repoint the var
# at PySide6's own plugins, after cv2 is imported, before constructing the app.
_platforms = os.path.join(
os.path.dirname(PySide6.__file__), "Qt", "plugins", "platforms")
if os.path.isdir(_platforms):
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = _platforms
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName("Crazy Video Glitch Editor")
win = MainWindow()
win.show()
sys.exit(app.exec())
if __name__ == "__main__":
# 2+ positional, non-flag args => CLI batch render; otherwise launch GUI.
positional = [a for a in sys.argv[1:] if not a.startswith("-")]
if len(positional) >= 2:
run_cli(sys.argv[1:])
else:
run_gui()