Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -74,13 +74,18 @@ def get_output_path(input_path, res):
|
|
74 |
output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
|
75 |
return output_path
|
76 |
|
77 |
-
def create_master_playlist(output_paths):
|
78 |
-
master_playlist_path = output_dir / "
|
79 |
with open(master_playlist_path, "w") as f:
|
80 |
f.write("#EXTM3U\n")
|
81 |
for path in output_paths:
|
82 |
-
|
83 |
-
f.write(f'{
|
|
|
|
|
|
|
|
|
|
|
84 |
return master_playlist_path
|
85 |
|
86 |
def upload_file_to_s3(file_path, s3_path):
|
@@ -125,7 +130,8 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
125 |
|
126 |
output_paths.append(output_path)
|
127 |
|
128 |
-
master_playlist_path = create_master_playlist(output_paths)
|
|
|
129 |
output_paths.append(master_playlist_path)
|
130 |
|
131 |
server_ip = get_ip_address()
|
|
|
74 |
output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
|
75 |
return output_path
|
76 |
|
77 |
+
def create_master_playlist(output_paths, input_filename):
|
78 |
+
master_playlist_path = output_dir / f"{input_filename}_master_playlist.m3u8"
|
79 |
with open(master_playlist_path, "w") as f:
|
80 |
f.write("#EXTM3U\n")
|
81 |
for path in output_paths:
|
82 |
+
res = Path(path).stem.split("_")[1]
|
83 |
+
f.write(f'#EXT-X-STREAM-INF:BANDWIDTH=8000000,RESOLUTION={res}\n')
|
84 |
+
# read the .m3u8 file and replace relative links with absolute links
|
85 |
+
with open(path, 'r') as playlist_file:
|
86 |
+
content = playlist_file.read()
|
87 |
+
content = content.replace('.ts', f'.ts?s3://{AWS_S3_BUCKET}')
|
88 |
+
f.write(content + '\n')
|
89 |
return master_playlist_path
|
90 |
|
91 |
def upload_file_to_s3(file_path, s3_path):
|
|
|
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()
|