Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,7 +67,7 @@ def get_input_path(video_file, video_url):
|
|
| 67 |
raise ValueError("No input was provided.")
|
| 68 |
|
| 69 |
def get_output_path(input_path, res):
|
| 70 |
-
output_path = output_dir / (Path(input_path).stem + f"_{res}.m3u8")
|
| 71 |
return output_path
|
| 72 |
|
| 73 |
def get_aspect_ratio(input_path, aspect_ratio):
|
|
@@ -102,7 +102,7 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
| 102 |
output_path = get_output_path(input_path, str(res) + 'p')
|
| 103 |
|
| 104 |
ffmpeg_command = [
|
| 105 |
-
|
| 106 |
"-vf", f"scale={scale}:force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
| 107 |
"-hls_time", "10", "-hls_playlist_type", "vod", "-hls_segment_filename",
|
| 108 |
str(output_dir / f"{output_path.stem}_%03d.ts"), str(output_path)
|
|
@@ -116,18 +116,16 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
| 116 |
master_playlist_path = create_master_playlist(output_paths)
|
| 117 |
output_paths.append(master_playlist_path)
|
| 118 |
|
| 119 |
-
|
| 120 |
-
output_links = []
|
| 121 |
-
for path in output_paths:
|
| 122 |
-
output_links.append(f'<a href="http://your_server_ip:8000/{path}" target="_blank">Download {Path(path).stem}</a>')
|
| 123 |
-
output_html = "<br>".join(output_links)
|
| 124 |
-
return output_html
|
| 125 |
-
|
| 126 |
server_ip = get_ip_address() # or get_public_ip_address() if you need the public IP
|
|
|
|
| 127 |
for path in output_paths:
|
| 128 |
# Replace 'your_server_ip' with server_ip
|
| 129 |
output_links.append(f'<a href="http://{server_ip}:8000/{path}" target="_blank">Download {Path(path).stem}</a>')
|
| 130 |
|
|
|
|
|
|
|
|
|
|
| 131 |
# Change "video" to "file"
|
| 132 |
video_file = gradio.inputs.File(label="Your video file")
|
| 133 |
quality = gradio.inputs.Slider(minimum=1, maximum=50, default=25, label="Quality (1:Speed - 50:Quality)")
|
|
@@ -147,4 +145,4 @@ interface = gradio.Interface(
|
|
| 147 |
)
|
| 148 |
|
| 149 |
start_http_server()
|
| 150 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 67 |
raise ValueError("No input was provided.")
|
| 68 |
|
| 69 |
def get_output_path(input_path, res):
|
| 70 |
+
output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
|
| 71 |
return output_path
|
| 72 |
|
| 73 |
def get_aspect_ratio(input_path, aspect_ratio):
|
|
|
|
| 102 |
output_path = get_output_path(input_path, str(res) + 'p')
|
| 103 |
|
| 104 |
ffmpeg_command = [
|
| 105 |
+
"ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
|
| 106 |
"-vf", f"scale={scale}:force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
| 107 |
"-hls_time", "10", "-hls_playlist_type", "vod", "-hls_segment_filename",
|
| 108 |
str(output_dir / f"{output_path.stem}_%03d.ts"), str(output_path)
|
|
|
|
| 116 |
master_playlist_path = create_master_playlist(output_paths)
|
| 117 |
output_paths.append(master_playlist_path)
|
| 118 |
|
| 119 |
+
# Get server IP and generate output links
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
server_ip = get_ip_address() # or get_public_ip_address() if you need the public IP
|
| 121 |
+
output_links = []
|
| 122 |
for path in output_paths:
|
| 123 |
# Replace 'your_server_ip' with server_ip
|
| 124 |
output_links.append(f'<a href="http://{server_ip}:8000/{path}" target="_blank">Download {Path(path).stem}</a>')
|
| 125 |
|
| 126 |
+
output_html = "<br>".join(output_links)
|
| 127 |
+
return output_html
|
| 128 |
+
|
| 129 |
# Change "video" to "file"
|
| 130 |
video_file = gradio.inputs.File(label="Your video file")
|
| 131 |
quality = gradio.inputs.Slider(minimum=1, maximum=50, default=25, label="Quality (1:Speed - 50:Quality)")
|
|
|
|
| 145 |
)
|
| 146 |
|
| 147 |
start_http_server()
|
| 148 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|