Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -72,15 +72,14 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
72 |
video = VideoFileClip(str(input_path))
|
73 |
original_height = video.size[1]
|
74 |
|
75 |
-
output_paths = []
|
76 |
|
77 |
for res in standard_resolutions:
|
78 |
-
# Skip if resolution is higher than original
|
79 |
if res > original_height:
|
80 |
continue
|
81 |
|
82 |
-
scale = "-1:" + str(res)
|
83 |
-
output_path = get_output_path(input_path, str(res) + 'p')
|
84 |
|
85 |
ffmpeg_command = [
|
86 |
"ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
|
@@ -92,28 +91,30 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
92 |
logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
|
93 |
subprocess.run(ffmpeg_command, check=True)
|
94 |
|
95 |
-
output_paths.append(output_path)
|
96 |
|
97 |
master_playlist_path = create_master_playlist(output_paths)
|
98 |
output_paths.append(master_playlist_path)
|
99 |
|
100 |
-
|
101 |
|
102 |
for path in output_paths:
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
117 |
|
118 |
video_file = gr.inputs.File(label="Video File")
|
119 |
quality = gr.inputs.Dropdown(
|
|
|
72 |
video = VideoFileClip(str(input_path))
|
73 |
original_height = video.size[1]
|
74 |
|
75 |
+
output_paths = []
|
76 |
|
77 |
for res in standard_resolutions:
|
|
|
78 |
if res > original_height:
|
79 |
continue
|
80 |
|
81 |
+
scale = "-1:" + str(res)
|
82 |
+
output_path = get_output_path(input_path, str(res) + 'p')
|
83 |
|
84 |
ffmpeg_command = [
|
85 |
"ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
|
|
|
91 |
logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
|
92 |
subprocess.run(ffmpeg_command, check=True)
|
93 |
|
94 |
+
output_paths.append(output_path)
|
95 |
|
96 |
master_playlist_path = create_master_playlist(output_paths)
|
97 |
output_paths.append(master_playlist_path)
|
98 |
|
99 |
+
html_blocks = []
|
100 |
|
101 |
for path in output_paths:
|
102 |
+
video_path = f'http://localhost:5000/files/{path.name}'
|
103 |
+
video_component = f'''
|
104 |
+
<div style="margin-bottom: 20px; border: 1px solid #ccc; padding: 10px;">
|
105 |
+
<video width="320" height="240" controls>
|
106 |
+
<source src="{video_path}" type="video/mp4">
|
107 |
+
Your browser does not support the video tag.
|
108 |
+
</video>
|
109 |
+
<p>
|
110 |
+
<a href="{video_path}" target="_blank">Download {path.stem}</a>
|
111 |
+
</p>
|
112 |
+
<p>Resolution: {path.stem.split('_')[-1]}</p>
|
113 |
+
</div>
|
114 |
+
'''
|
115 |
+
html_blocks.append(video_component)
|
116 |
+
|
117 |
+
return "\n".join(html_blocks),
|
118 |
|
119 |
video_file = gr.inputs.File(label="Video File")
|
120 |
quality = gr.inputs.Dropdown(
|