artificialguybr commited on
Commit
b273a44
1 Parent(s): 757859b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -20,26 +20,27 @@ st = os.stat('ffmpeg')
20
  os.chmod('ffmpeg', st.st_mode | stat.S_IEXEC)
21
 
22
  def process_video(video, high_quality, target_language):
23
- with tempfile.TemporaryDirectory() as temp_dir:
24
- output_filename = os.path.join(temp_dir, "resized_video.mp4")
25
-
26
- if high_quality:
27
- ffmpeg.input(video).output(output_filename, vf='scale=-1:720').run()
28
- video_path = output_filename
29
- else:
30
- video_path = video
 
31
 
32
- if not os.path.exists(video_path):
33
- return f"Error: {video_path} does not exist."
34
 
35
- with tempfile.TemporaryDirectory() as temp_dir:
36
- audio_output = os.path.join(temp_dir, "output_audio.wav")
37
-
38
- try:
39
- ffmpeg.input(video_path).output(audio_output, acodec='pcm_s24le', ar=48000, map='a').run()
40
- except ffmpeg.Error as e:
41
- stderr_output = e.stderr.decode('utf-8') if e.stderr else "Unknown error"
42
- return f"FFmpeg error: {stderr_output}"
43
 
44
 
45
  y, sr = sf.read("output_audio.wav")
@@ -83,7 +84,9 @@ def process_video(video, high_quality, target_language):
83
  if not os.path.exists("output_video.mp4"):
84
  return "Error: output_video.mp4 was not generated."
85
 
86
- return "output_video.mp4"
 
 
87
 
88
  iface = gr.Interface(
89
  fn=process_video,
 
20
  os.chmod('ffmpeg', st.st_mode | stat.S_IEXEC)
21
 
22
  def process_video(video, high_quality, target_language):
23
+ try:
24
+ with tempfile.TemporaryDirectory() as temp_dir:
25
+ output_filename = os.path.join(temp_dir, "resized_video.mp4")
26
+
27
+ if high_quality:
28
+ ffmpeg.input(video).output(output_filename, vf='scale=-1:720').run()
29
+ video_path = output_filename
30
+ else:
31
+ video_path = video
32
 
33
+ if not os.path.exists(video_path):
34
+ return {"error": f"{video_path} does not exist."}
35
 
36
+ with tempfile.TemporaryDirectory() as temp_dir:
37
+ audio_output = os.path.join(temp_dir, "output_audio.wav")
38
+
39
+ try:
40
+ ffmpeg.input(video_path).output(audio_output, acodec='pcm_s24le', ar=48000, map='a').run()
41
+ except ffmpeg.Error as e:
42
+ stderr_output = e.stderr.decode('utf-8') if e.stderr else "Unknown error"
43
+ return {"error": f"FFmpeg error: {stderr_output}"}
44
 
45
 
46
  y, sr = sf.read("output_audio.wav")
 
84
  if not os.path.exists("output_video.mp4"):
85
  return "Error: output_video.mp4 was not generated."
86
 
87
+ return {"file": "output_video.mp4"}
88
+ except Exception as e:
89
+ return {"error": f"An unexpected error occurred: {str(e)}"}
90
 
91
  iface = gr.Interface(
92
  fn=process_video,