Jeffgold commited on
Commit
998c128
·
1 Parent(s): 6ae4e58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -4,7 +4,7 @@ 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
@@ -17,11 +17,6 @@ output_dir.mkdir(exist_ok=True)
17
  logging.basicConfig(level=logging.INFO)
18
 
19
  standard_resolutions = [240, 360, 480, 720, 1080, 1440, 2160, 4320]
20
- quality_mapping = {
21
- "Low": 35,
22
- "Medium": 23,
23
- "High": 18,
24
- }
25
 
26
  def start_http_server(port=8000):
27
  handler = http.server.SimpleHTTPRequestHandler
@@ -42,10 +37,6 @@ def get_ip_address():
42
  s.close()
43
  return IP
44
 
45
- def get_public_ip_address():
46
- response = requests.get('https://httpbin.org/ip')
47
- return response.json()['origin']
48
-
49
  def download_file(url, destination):
50
  response = requests.get(url)
51
  response.raise_for_status()
@@ -68,9 +59,7 @@ def get_output_path(input_path, res):
68
  output_path = output_dir / (Path(input_path).stem + f"_{res}p.m3u8")
69
  return output_path
70
 
71
- def get_aspect_ratio(input_path, aspect_ratio):
72
- if aspect_ratio is not None:
73
- return aspect_ratio
74
  video = VideoFileClip(str(input_path))
75
  return f"{video.size[0]}:{video.size[1]}"
76
 
@@ -83,9 +72,8 @@ def create_master_playlist(output_paths):
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):
87
  input_path = get_input_path(video_file, video_url)
88
- aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
89
 
90
  video = VideoFileClip(str(input_path))
91
 
@@ -127,19 +115,18 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
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)
 
4
  import subprocess
5
  from pathlib import Path
6
  from moviepy.editor import VideoFileClip
7
+ import gradio as gr
8
  import http.server
9
  import socketserver
10
  import threading
 
17
  logging.basicConfig(level=logging.INFO)
18
 
19
  standard_resolutions = [240, 360, 480, 720, 1080, 1440, 2160, 4320]
 
 
 
 
 
20
 
21
  def start_http_server(port=8000):
22
  handler = http.server.SimpleHTTPRequestHandler
 
37
  s.close()
38
  return IP
39
 
 
 
 
 
40
  def download_file(url, destination):
41
  response = requests.get(url)
42
  response.raise_for_status()
 
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
 
 
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))
79
 
 
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",
128
  allow_flagging='never'
129
  )
130
 
131
  start_http_server()
132
+ interface.launch(server_name=get_ip_address(), server_port=7860)