Jeffgold commited on
Commit
c9de927
·
1 Parent(s): 03c91ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -10,17 +10,20 @@ from pathlib import Path
10
  # Define File object
11
  File = Path
12
 
13
- video_file = gr.inputs.File(label="Video File")
14
  quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
15
  aspect_ratio = gr.inputs.Dropdown(choices=["16:9", "4:3", "3:2", "2:1"], label="Aspect Ratio", default="16:9")
16
 
17
  def convert_video(video_file: File, quality, aspect_ratio):
18
- output_path = f"{video_file.name.split('.')[0]}.m3u8"
 
 
 
19
 
20
  temp_dir = tempfile.gettempdir()
21
- ffmpeg_command = f"ffmpeg -i {video_file} -c:v libx264 -crf {quality} -f hls -aspect {aspect_ratio} {temp_dir}/{output_path}"
22
  subprocess.run(ffmpeg_command, shell=True)
23
 
24
  return components.Video(output_path)
25
 
26
- gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio], outputs=[components.Video()]).launch()
 
10
  # Define File object
11
  File = Path
12
 
13
+ video_file = gr.inputs.File(label="Video File", accept="video/*", required=False)
14
  quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
15
  aspect_ratio = gr.inputs.Dropdown(choices=["16:9", "4:3", "3:2", "2:1"], label="Aspect Ratio", default="16:9")
16
 
17
  def convert_video(video_file: File, quality, aspect_ratio):
18
+ if video_file is None:
19
+ output_path = gr.inputs.Textbox(label="Video URL")
20
+ else:
21
+ output_path = f"{video_file.name.split('.')[0]}.m3u8"
22
 
23
  temp_dir = tempfile.gettempdir()
24
+ ffmpeg_command = f"ffmpeg -i {video_file or output_path} -c:v libx264 -crf {quality} -f hls -aspect {aspect_ratio} {temp_dir}/{output_path}"
25
  subprocess.run(ffmpeg_command, shell=True)
26
 
27
  return components.Video(output_path)
28
 
29
+ gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio], outputs=[components.Video()]).launch(share=True)