Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,6 @@ def start_http_server(port=8000):
|
|
| 28 |
def get_ip_address():
|
| 29 |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 30 |
try:
|
| 31 |
-
# doesn't have to be reachable
|
| 32 |
s.connect(('10.255.255.255', 1))
|
| 33 |
IP = s.getsockname()[0]
|
| 34 |
except Exception:
|
|
@@ -59,10 +58,6 @@ def get_output_path(input_path, res):
|
|
| 59 |
output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
|
| 60 |
return output_path
|
| 61 |
|
| 62 |
-
def get_aspect_ratio(input_path):
|
| 63 |
-
video = VideoFileClip(str(input_path))
|
| 64 |
-
return f"{video.size[0]}:{video.size[1]}"
|
| 65 |
-
|
| 66 |
def create_master_playlist(output_paths):
|
| 67 |
master_playlist_path = output_dir / "master_playlist.m3u8"
|
| 68 |
with open(master_playlist_path, "w") as f:
|
|
@@ -72,7 +67,7 @@ def create_master_playlist(output_paths):
|
|
| 72 |
f.write(f'{Path(path).name}\n')
|
| 73 |
return master_playlist_path
|
| 74 |
|
| 75 |
-
def convert_video(video_file, quality, video_url):
|
| 76 |
input_path = get_input_path(video_file, video_url)
|
| 77 |
|
| 78 |
video = VideoFileClip(str(input_path))
|
|
@@ -104,24 +99,22 @@ def convert_video(video_file, quality, video_url):
|
|
| 104 |
master_playlist_path = create_master_playlist(output_paths)
|
| 105 |
output_paths.append(master_playlist_path)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
server_ip = get_ip_address() # or get_public_ip_address() if you need the public IP
|
| 109 |
output_links = []
|
| 110 |
for path in output_paths:
|
| 111 |
-
# Replace 'your_server_ip' with server_ip
|
| 112 |
output_links.append(f'<a href="http://{server_ip}:8000/{path}" target="_blank">Download {Path(path).stem}</a>')
|
| 113 |
|
| 114 |
output_html = "<br>".join(output_links)
|
| 115 |
return output_html
|
| 116 |
|
| 117 |
-
# Change "video" to "file"
|
| 118 |
video_file = gr.inputs.File(label="Your video file")
|
| 119 |
quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
|
|
|
|
| 120 |
video_url = gr.inputs.Textbox(lines=1, placeholder="or paste video url here", label="Video URL")
|
| 121 |
|
| 122 |
interface = gr.Interface(
|
| 123 |
fn=convert_video,
|
| 124 |
-
inputs=[video_file, quality, video_url],
|
| 125 |
outputs=gr.outputs.HTML(label="Download Links"),
|
| 126 |
title="NEAR Hub Video Transcoder to m3u8",
|
| 127 |
description="convert video files to m3u8 for VOD streaming",
|
|
|
|
| 28 |
def get_ip_address():
|
| 29 |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 30 |
try:
|
|
|
|
| 31 |
s.connect(('10.255.255.255', 1))
|
| 32 |
IP = s.getsockname()[0]
|
| 33 |
except Exception:
|
|
|
|
| 58 |
output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
|
| 59 |
return output_path
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def create_master_playlist(output_paths):
|
| 62 |
master_playlist_path = output_dir / "master_playlist.m3u8"
|
| 63 |
with open(master_playlist_path, "w") as f:
|
|
|
|
| 67 |
f.write(f'{Path(path).name}\n')
|
| 68 |
return master_playlist_path
|
| 69 |
|
| 70 |
+
def convert_video(video_file, quality, aspect_ratio, video_url):
|
| 71 |
input_path = get_input_path(video_file, video_url)
|
| 72 |
|
| 73 |
video = VideoFileClip(str(input_path))
|
|
|
|
| 99 |
master_playlist_path = create_master_playlist(output_paths)
|
| 100 |
output_paths.append(master_playlist_path)
|
| 101 |
|
| 102 |
+
server_ip = get_ip_address()
|
|
|
|
| 103 |
output_links = []
|
| 104 |
for path in output_paths:
|
|
|
|
| 105 |
output_links.append(f'<a href="http://{server_ip}:8000/{path}" target="_blank">Download {Path(path).stem}</a>')
|
| 106 |
|
| 107 |
output_html = "<br>".join(output_links)
|
| 108 |
return output_html
|
| 109 |
|
|
|
|
| 110 |
video_file = gr.inputs.File(label="Your video file")
|
| 111 |
quality = gr.inputs.Slider(minimum=1, maximum=50, label="Quality (1:Speed - 50:Quality)")
|
| 112 |
+
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")
|
| 113 |
video_url = gr.inputs.Textbox(lines=1, placeholder="or paste video url here", label="Video URL")
|
| 114 |
|
| 115 |
interface = gr.Interface(
|
| 116 |
fn=convert_video,
|
| 117 |
+
inputs=[video_file, quality, aspect_ratio, video_url],
|
| 118 |
outputs=gr.outputs.HTML(label="Download Links"),
|
| 119 |
title="NEAR Hub Video Transcoder to m3u8",
|
| 120 |
description="convert video files to m3u8 for VOD streaming",
|