Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import logging
|
2 |
import requests
|
3 |
-
import gradio
|
4 |
from urllib.parse import urlparse
|
5 |
import subprocess
|
6 |
from pathlib import Path
|
7 |
from moviepy.editor import VideoFileClip
|
8 |
-
|
9 |
-
from gradio import components
|
10 |
import http.server
|
11 |
import socketserver
|
12 |
import threading
|
@@ -78,11 +76,11 @@ def get_aspect_ratio(input_path, aspect_ratio):
|
|
78 |
|
79 |
def create_master_playlist(output_paths):
|
80 |
master_playlist_path = output_dir / "master_playlist.m3u8"
|
81 |
-
with open(master_playlist_path,
|
82 |
f.write("#EXTM3U\n")
|
83 |
for path in output_paths:
|
84 |
-
f.write(f
|
85 |
-
f.write(f
|
86 |
return master_playlist_path
|
87 |
|
88 |
def convert_video(video_file, quality, aspect_ratio, video_url):
|
@@ -90,6 +88,8 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
90 |
aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
|
91 |
|
92 |
video = VideoFileClip(str(input_path))
|
|
|
|
|
93 |
original_height = video.size[1]
|
94 |
|
95 |
output_paths = []
|
@@ -127,22 +127,19 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
127 |
return output_html
|
128 |
|
129 |
# Change "video" to "file"
|
130 |
-
video_file =
|
131 |
-
quality =
|
132 |
-
aspect_ratio =
|
133 |
-
video_url =
|
134 |
-
|
135 |
-
# Update the aspect ratio selection to include the comprehensive list
|
136 |
-
# aspect_ratio = gr.inputs.Dropdown(choices=aspect_ratios, label="Aspect Ratio", default="16:9")
|
137 |
|
138 |
-
interface =
|
139 |
fn=convert_video,
|
140 |
inputs=[video_file, quality, aspect_ratio, video_url],
|
141 |
-
outputs=
|
142 |
title="NEAR Hub Video Transcoder to m3u8",
|
143 |
description="convert video files to m3u8 for VOD streaming",
|
144 |
-
allow_flagging=
|
145 |
)
|
146 |
|
147 |
start_http_server()
|
148 |
-
interface.launch(server_name=
|
|
|
1 |
import logging
|
2 |
import requests
|
|
|
3 |
from urllib.parse import urlparse
|
4 |
import subprocess
|
5 |
from pathlib import Path
|
6 |
from moviepy.editor import VideoFileClip
|
7 |
+
from gradio import components as gr
|
|
|
8 |
import http.server
|
9 |
import socketserver
|
10 |
import threading
|
|
|
76 |
|
77 |
def create_master_playlist(output_paths):
|
78 |
master_playlist_path = output_dir / "master_playlist.m3u8"
|
79 |
+
with open(master_playlist_path, "w") as f:
|
80 |
f.write("#EXTM3U\n")
|
81 |
for path in output_paths:
|
82 |
+
f.write(f'#EXT-X-STREAM-INF:BANDWIDTH=8000000,RESOLUTION={Path(path).stem.split("_")[1]}\n')
|
83 |
+
f.write(f'{Path(path).name}\n')
|
84 |
return master_playlist_path
|
85 |
|
86 |
def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
|
88 |
aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
|
89 |
|
90 |
video = VideoFileClip(str(input_path))
|
91 |
+
|
92 |
+
# Get the original height to avoid upscaling
|
93 |
original_height = video.size[1]
|
94 |
|
95 |
output_paths = []
|
|
|
127 |
return output_html
|
128 |
|
129 |
# Change "video" to "file"
|
130 |
+
video_file = gr.File(label="Your video file")
|
131 |
+
quality = gr.Slider(minimum=1, maximum=50, default=25, label="Quality (1:Speed - 50:Quality)")
|
132 |
+
aspect_ratio = gr.Dropdown(["16:9", "4:3", "1:1", "3:4", "9:16", "1:1", "2:1", "1:2"], label="Aspect Ratio", default="16:9")
|
133 |
+
video_url = gr.Textbox(lines=1, placeholder="or paste video url here", label="Video URL")
|
|
|
|
|
|
|
134 |
|
135 |
+
interface = gr.Interface(
|
136 |
fn=convert_video,
|
137 |
inputs=[video_file, quality, aspect_ratio, video_url],
|
138 |
+
outputs=gr.HTML(label="Download Links"),
|
139 |
title="NEAR Hub Video Transcoder to m3u8",
|
140 |
description="convert video files to m3u8 for VOD streaming",
|
141 |
+
allow_flagging='never'
|
142 |
)
|
143 |
|
144 |
start_http_server()
|
145 |
+
interface.launch(server_name=get_ip_address(), server_port=7860)
|