Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -112,35 +112,32 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
112 |
|
113 |
scale = "-1:" + str(res)
|
114 |
output_path = get_output_path(input_path, str(res) + 'p')
|
115 |
-
output_file_stem = output_dir / f"{output_path.stem}_%03d.ts"
|
116 |
|
117 |
ffmpeg_command = [
|
118 |
"ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
|
119 |
"-vf", f"scale={scale}:force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
120 |
"-hls_time", "10", "-hls_playlist_type", "vod", "-hls_segment_filename",
|
121 |
-
str(
|
122 |
]
|
123 |
|
124 |
logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
|
125 |
subprocess.run(ffmpeg_command, check=True)
|
126 |
|
127 |
-
# Upload TS files
|
128 |
-
for ts_file in output_dir.glob(f"{output_file_stem.stem}*.ts"):
|
129 |
-
upload_file_to_s3(ts_file, f"s3://{AWS_S3_BUCKET}/{ts_file.name}")
|
130 |
-
|
131 |
output_paths.append(output_path)
|
132 |
|
133 |
master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
|
134 |
-
|
135 |
output_paths.append(master_playlist_path)
|
136 |
|
137 |
server_ip = get_ip_address()
|
138 |
output_links = []
|
139 |
-
|
140 |
-
# Upload M3U8 files
|
141 |
for path in output_paths:
|
142 |
output_links.append(f'<a href="http://{server_ip}:8000{path}" target="_blank">Download {Path(path).stem}</a>')
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
output_html = "<br>".join(output_links)
|
146 |
return output_html
|
|
|
112 |
|
113 |
scale = "-1:" + str(res)
|
114 |
output_path = get_output_path(input_path, str(res) + 'p')
|
|
|
115 |
|
116 |
ffmpeg_command = [
|
117 |
"ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
|
118 |
"-vf", f"scale={scale}:force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
119 |
"-hls_time", "10", "-hls_playlist_type", "vod", "-hls_segment_filename",
|
120 |
+
str(output_dir / f"{output_path.stem}_%03d.ts"), str(output_path)
|
121 |
]
|
122 |
|
123 |
logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
|
124 |
subprocess.run(ffmpeg_command, check=True)
|
125 |
|
|
|
|
|
|
|
|
|
126 |
output_paths.append(output_path)
|
127 |
|
128 |
master_playlist_path = create_master_playlist(output_paths, Path(input_path).stem)
|
|
|
129 |
output_paths.append(master_playlist_path)
|
130 |
|
131 |
server_ip = get_ip_address()
|
132 |
output_links = []
|
|
|
|
|
133 |
for path in output_paths:
|
134 |
output_links.append(f'<a href="http://{server_ip}:8000{path}" target="_blank">Download {Path(path).stem}</a>')
|
135 |
+
print("Read local file")
|
136 |
+
upload_file_to_s3(path, f"s3://{AWS_S3_BUCKET}/{Path(path).stem}")
|
137 |
+
|
138 |
+
# upload ts files to s3
|
139 |
+
for path in output_dir.glob(f"{Path(input_path).stem}_*p_*.ts"):
|
140 |
+
upload_file_to_s3(path, f"s3://{AWS_S3_BUCKET}/{Path(path).stem}")
|
141 |
|
142 |
output_html = "<br>".join(output_links)
|
143 |
return output_html
|