forked from YYuX-1145/Bert-VITS2-Integration-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_ffmpeg.py
55 lines (46 loc) · 1.68 KB
/
setup_ffmpeg.py
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
import os
import sys
import re
from pathlib import Path
import winreg
def check_ffmpeg_path():
path_list = os.environ['Path'].split(';')
ffmpeg_found = False
for path in path_list:
if 'ffmpeg' in path.lower() and 'bin' in path.lower():
ffmpeg_found = True
print("FFmpeg already installed.")
break
return ffmpeg_found
def add_ffmpeg_path_to_user_variable():
ffmpeg_bin_path = Path('.\\ffmpeg\\bin')
if ffmpeg_bin_path.is_dir():
abs_path = str(ffmpeg_bin_path.resolve())
try:
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r"Environment",
0,
winreg.KEY_READ | winreg.KEY_WRITE
)
try:
current_path, _ = winreg.QueryValueEx(key, "Path")
if abs_path not in current_path:
new_path = f"{current_path};{abs_path}"
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
print(f"Added FFmpeg path to user variable 'Path': {abs_path}")
else:
print("FFmpeg path already exists in the user variable 'Path'.")
finally:
winreg.CloseKey(key)
except WindowsError:
print("Error: Unable to modify user variable 'Path'.")
sys.exit(1)
else:
print("Error: ffmpeg\\bin folder not found in the current path.")
sys.exit(1)
def main():
if not check_ffmpeg_path():
add_ffmpeg_path_to_user_variable()
if __name__ == "__main__":
main()