-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_ffmpeg.py
More file actions
69 lines (54 loc) · 2.19 KB
/
Copy pathsetup_ffmpeg.py
File metadata and controls
69 lines (54 loc) · 2.19 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
"""
KoKoFish — ffmpeg auto-download helper.
Downloads ffmpeg essentials and extracts ffmpeg.exe to bin/.
Called by the launcher during first-run setup.
"""
import os
import shutil
import sys
import urllib.request
import zipfile
APP_DIR = os.path.dirname(os.path.abspath(__file__))
BIN_DIR = os.path.join(APP_DIR, "bin")
FFMPEG_EXE = os.path.join(BIN_DIR, "ffmpeg.exe")
FFMPEG_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
def download_ffmpeg():
os.makedirs(BIN_DIR, exist_ok=True)
FFPROBE_EXE = os.path.join(BIN_DIR, "ffprobe.exe")
if os.path.isfile(FFMPEG_EXE) and os.path.isfile(FFPROBE_EXE):
print(" ffmpeg toolkit already fully present.")
return True
zip_path = os.path.join(BIN_DIR, "ffmpeg_download.zip")
try:
print(" Downloading ffmpeg toolkit (~80 MB)...")
urllib.request.urlretrieve(FFMPEG_URL, zip_path)
print(" Extracting binaries...")
with zipfile.ZipFile(zip_path, "r") as zf:
for name in zf.namelist():
if name.endswith("bin/ffmpeg.exe") or name.endswith("bin\\ffmpeg.exe"):
zf.extract(name, BIN_DIR)
shutil.copy2(os.path.join(BIN_DIR, name), FFMPEG_EXE)
elif name.endswith("bin/ffprobe.exe") or name.endswith("bin\\ffprobe.exe"):
zf.extract(name, BIN_DIR)
shutil.copy2(os.path.join(BIN_DIR, name), FFPROBE_EXE)
# Cleanup zip and extracted artifact directory structure
os.remove(zip_path)
for d in os.listdir(BIN_DIR):
full = os.path.join(BIN_DIR, d)
if os.path.isdir(full):
shutil.rmtree(full)
if os.path.isfile(FFMPEG_EXE) and os.path.isfile(FFPROBE_EXE):
print(" ffmpeg toolkit ready.")
return True
else:
print(" ERROR: required binaries not found in download.")
return False
except Exception as e:
print(f" ERROR: {e}")
# Cleanup partial download
if os.path.isfile(zip_path):
os.remove(zip_path)
return False
if __name__ == "__main__":
success = download_ffmpeg()
sys.exit(0 if success else 1)