Jeffgold commited on
Commit
e98f21f
·
1 Parent(s): 089efa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -104,14 +104,12 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
104
  raise ValueError("Please provide either a video file or a video URL.")
105
 
106
  input_path = get_input_path(video_file, video_url)
107
-
108
  video = VideoFileClip(str(input_path))
109
 
110
  # Get the original height to avoid upscaling
111
  original_height = video.size[1]
112
 
113
  output_paths = []
114
-
115
  for res in standard_resolutions:
116
  if res > original_height:
117
  continue
@@ -136,19 +134,22 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
136
 
137
  output_links = []
138
  for path in output_paths:
139
- s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem}"
 
140
  upload_file_to_s3(path, s3_path)
141
- output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem}" target="_blank">Download {Path(path).stem}</a>')
142
 
143
  # upload ts files to s3
144
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
145
- s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem.split('_')[1]}/{Path(path).stem}"
 
146
  upload_file_to_s3(path, s3_path)
147
- output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{Path(path).stem.split('_')[1]}/{Path(path).stem}" target="_blank">Download {Path(path).stem}</a>')
148
 
149
  output_html = "<br>".join(output_links)
150
  return output_html
151
 
 
152
  video_file = gr.inputs.File(label="Your video file")
153
  quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
154
  aspect_ratio = gr.inputs.Dropdown(["16:9", "4:3", "1:1", "3:4", "9:16", "1:1", "2:1", "1:2"], label="Aspect Ratio", default="16:9")
 
104
  raise ValueError("Please provide either a video file or a video URL.")
105
 
106
  input_path = get_input_path(video_file, video_url)
 
107
  video = VideoFileClip(str(input_path))
108
 
109
  # Get the original height to avoid upscaling
110
  original_height = video.size[1]
111
 
112
  output_paths = []
 
113
  for res in standard_resolutions:
114
  if res > original_height:
115
  continue
 
134
 
135
  output_links = []
136
  for path in output_paths:
137
+ res_folder = Path(path).stem.split("_")[1]
138
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{res_folder}/{Path(path).name}"
139
  upload_file_to_s3(path, s3_path)
140
+ output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{res_folder}/{Path(path).name}" target="_blank">Download {Path(path).stem}</a>')
141
 
142
  # upload ts files to s3
143
  for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
144
+ res_folder = Path(path).stem.split("_")[1]
145
+ s3_path = f"s3://{AWS_S3_BUCKET}/{Path(input_path).stem}/{res_folder}/{Path(path).name}"
146
  upload_file_to_s3(path, s3_path)
147
+ output_links.append(f'<a href="https://s3-us-east-1.amazonaws.com/{AWS_S3_BUCKET}/{Path(input_path).stem}/{res_folder}/{Path(path).name}" target="_blank">Download {Path(path).stem}</a>')
148
 
149
  output_html = "<br>".join(output_links)
150
  return output_html
151
 
152
+
153
  video_file = gr.inputs.File(label="Your video file")
154
  quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
155
  aspect_ratio = gr.inputs.Dropdown(["16:9", "4:3", "1:1", "3:4", "9:16", "1:1", "2:1", "1:2"], label="Aspect Ratio", default="16:9")