Jeffgold commited on
Commit
0dcabf9
·
1 Parent(s): 0d3cb7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -67,10 +67,10 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
67
  f.write(response.content)
68
  else:
69
  print("Failed to download file from URL.")
70
- return None
71
  else:
72
  print("No input was provided.")
73
- return None
74
 
75
  # Define the output path
76
  output_path = os.path.join(temp_dir, output_file_name)
@@ -78,7 +78,7 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
78
  # Check if the output file exists
79
  if os.path.exists(output_path):
80
  # The file already exists, so we can just display it in the output viewer
81
- return (output_path, "application/octet-stream")
82
  else:
83
  # The file does not exist, so we need to convert it
84
  ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf {quality} -vf scale=-1:720,setsar=1:1 -hls_time 6 -hls_playlist_type vod -f hls {output_path}"
@@ -87,10 +87,10 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
87
  subprocess.run(ffmpeg_command, shell=True, timeout=10)
88
  except subprocess.TimeoutExpired:
89
  print("ffmpeg timed out")
90
- return None
91
  except FileNotFoundError:
92
  print("ffmpeg is not installed.")
93
- return None
94
 
95
  for i in range(10):
96
  if os.path.exists(output_path):
@@ -99,7 +99,8 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
99
  time.sleep(1)
100
 
101
  # The file has now been converted, so we can display it in the output viewer
102
- return (output_path, "application/octet-stream")
 
103
 
104
 
105
  gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio, video_url], outputs='file').launch()
 
67
  f.write(response.content)
68
  else:
69
  print("Failed to download file from URL.")
70
+ return "Failed to download file from URL."
71
  else:
72
  print("No input was provided.")
73
+ return "No input was provided."
74
 
75
  # Define the output path
76
  output_path = os.path.join(temp_dir, output_file_name)
 
78
  # Check if the output file exists
79
  if os.path.exists(output_path):
80
  # The file already exists, so we can just display it in the output viewer
81
+ return output_path
82
  else:
83
  # The file does not exist, so we need to convert it
84
  ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf {quality} -vf scale=-1:720,setsar=1:1 -hls_time 6 -hls_playlist_type vod -f hls {output_path}"
 
87
  subprocess.run(ffmpeg_command, shell=True, timeout=10)
88
  except subprocess.TimeoutExpired:
89
  print("ffmpeg timed out")
90
+ return "ffmpeg timed out"
91
  except FileNotFoundError:
92
  print("ffmpeg is not installed.")
93
+ return "ffmpeg is not installed."
94
 
95
  for i in range(10):
96
  if os.path.exists(output_path):
 
99
  time.sleep(1)
100
 
101
  # The file has now been converted, so we can display it in the output viewer
102
+ return output_path
103
+
104
 
105
 
106
  gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio, video_url], outputs='file').launch()