RandomPersonRR commited on
Commit
2297f9b
·
verified ·
1 Parent(s): ba84416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -6,25 +6,18 @@ import glob
6
  import shutil
7
  import gradio as gr
8
 
9
- # Make sure fdkaac is executable (only needed once, but harmless)
10
- os.system("chmod +x fdkaac")
11
-
12
- # Locate binaries and check existence
13
  ffmpeg_path = shutil.which("ffmpeg")
14
  yt_dlp_path = shutil.which("yt-dlp")
15
- fdkaac_path = os.path.abspath("./fdkaac")
16
-
17
- print("[DEBUG] Detected Paths:")
18
- print("FFmpeg:", ffmpeg_path)
19
- print("yt-dlp:", yt_dlp_path)
20
- print("fdkaac:", fdkaac_path)
21
 
 
 
22
  if not ffmpeg_path:
23
  raise FileNotFoundError("FFmpeg not found in PATH.")
24
  if not yt_dlp_path:
25
  raise FileNotFoundError("yt-dlp not found in PATH.")
26
- if not os.path.isfile(fdkaac_path):
27
- raise FileNotFoundError("fdkaac binary not found in current directory.")
28
 
29
  accel = 'auto'
30
  video_base_opts = ['-crf', '63', '-c:v', 'libx264', '-tune', 'zerolatency']
@@ -34,13 +27,16 @@ CONVERTED_FOLDER = 'converted'
34
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
35
  os.makedirs(CONVERTED_FOLDER, exist_ok=True)
36
 
37
- async def run_subprocess(cmd):
38
- print(f"\n[DEBUG] Running command:\n{' '.join(cmd)}\n")
 
 
 
39
  process = await asyncio.create_subprocess_exec(
40
  *cmd,
41
  stdout=asyncio.subprocess.PIPE,
42
  stderr=asyncio.subprocess.PIPE,
43
- env=os.environ.copy() # Inherit full environment for safety
44
  )
45
  stdout, stderr = await process.communicate()
46
  if process.returncode != 0:
@@ -70,7 +66,7 @@ async def convert_video_task(input_path, downscale, faster, use_mp3):
70
  await run_subprocess([
71
  fdkaac_path, '-b', '1k', '-C', '-f', '2', '-G', '1', '-w', '8000',
72
  '-o', audio_output, audio_wav
73
- ])
74
 
75
  video_cmd = [
76
  ffmpeg_path, '-y', '-hwaccel', accel, '-i', input_path,
 
6
  import shutil
7
  import gradio as gr
8
 
9
+ # Set executable fdkaac path
10
+ fdkaac_path = os.path.abspath("./fdkaac")
 
 
11
  ffmpeg_path = shutil.which("ffmpeg")
12
  yt_dlp_path = shutil.which("yt-dlp")
13
+ subprocess.run("chmod", "+x", fdkaac_path)
 
 
 
 
 
14
 
15
+ if not os.path.isfile(fdkaac_path):
16
+ raise FileNotFoundError("fdkaac binary not found in current directory.")
17
  if not ffmpeg_path:
18
  raise FileNotFoundError("FFmpeg not found in PATH.")
19
  if not yt_dlp_path:
20
  raise FileNotFoundError("yt-dlp not found in PATH.")
 
 
21
 
22
  accel = 'auto'
23
  video_base_opts = ['-crf', '63', '-c:v', 'libx264', '-tune', 'zerolatency']
 
27
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
28
  os.makedirs(CONVERTED_FOLDER, exist_ok=True)
29
 
30
+ async def run_subprocess(cmd, use_fdkaac=False):
31
+ env = os.environ.copy()
32
+ if use_fdkaac:
33
+ env["LD_LIBRARY_PATH"] = env.get("LD_LIBRARY_PATH", "") + ":/usr/local/lib"
34
+ print(f"[DEBUG] Running command:\n{' '.join(cmd)}\n")
35
  process = await asyncio.create_subprocess_exec(
36
  *cmd,
37
  stdout=asyncio.subprocess.PIPE,
38
  stderr=asyncio.subprocess.PIPE,
39
+ env=env
40
  )
41
  stdout, stderr = await process.communicate()
42
  if process.returncode != 0:
 
66
  await run_subprocess([
67
  fdkaac_path, '-b', '1k', '-C', '-f', '2', '-G', '1', '-w', '8000',
68
  '-o', audio_output, audio_wav
69
+ ], use_fdkaac=True)
70
 
71
  video_cmd = [
72
  ffmpeg_path, '-y', '-hwaccel', accel, '-i', input_path,