Jeffgold commited on
Commit
7e0e151
·
1 Parent(s): 3178e82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -16,7 +16,7 @@ File = Path
16
  # Define temp directory
17
  temp_dir = tempfile.mkdtemp()
18
 
19
- video_file = gr.inputs.File(label="Video File", type="file")
20
  quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
21
  aspect_ratio = gr.inputs.Dropdown(choices=[
22
  "1:1",
@@ -36,19 +36,19 @@ aspect_ratio = gr.inputs.Dropdown(choices=[
36
  "9:1",
37
  ], label="Aspect Ratio", default="16:9")
38
 
39
- video_url = gr.inputs.Textbox(label="Video URL", type="text")
40
 
41
- def convert_video(video_file: File, quality, aspect_ratio):
42
  if video_file is None:
43
- output_path = gr.inputs.Textbox(label="Video URL")
44
  else:
45
  output_path = f"{temp_dir}/{Path(video_file).name}.m3u8"
46
 
47
- ffmpeg_command = f"ffmpeg -i {video_file or output_path} -c:v libx264 -crf {quality} -f hls -aspect {aspect_ratio} {temp_dir}/{output_path}"
48
  subprocess.run(ffmpeg_command, shell=True)
49
 
50
  return components.Video(output_path)
51
 
52
  from gradio import outputs
53
 
54
- gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio], outputs=[outputs.Video()]).launch(share=False)
 
16
  # Define temp directory
17
  temp_dir = tempfile.mkdtemp()
18
 
19
+ video_file = gr.inputs.File(label="Video File", type="file", accept="video/*")
20
  quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
21
  aspect_ratio = gr.inputs.Dropdown(choices=[
22
  "1:1",
 
36
  "9:1",
37
  ], label="Aspect Ratio", default="16:9")
38
 
39
+ video_url = gr.inputs.Textbox(label="Video URL", accept="video/*")
40
 
41
+ def convert_video(video_file: File, quality, aspect_ratio, video_url):
42
  if video_file is None:
43
+ output_path = f"{temp_dir}/{Path(video_url).name}.m3u8"
44
  else:
45
  output_path = f"{temp_dir}/{Path(video_file).name}.m3u8"
46
 
47
+ ffmpeg_command = f"ffmpeg -i {video_file or video_url} -c:v libx264 -crf {quality} -f hls -aspect {aspect_ratio} {temp_dir}/{output_path}"
48
  subprocess.run(ffmpeg_command, shell=True)
49
 
50
  return components.Video(output_path)
51
 
52
  from gradio import outputs
53
 
54
+ gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio, video_url], outputs=[outputs.Video()]).launch(share=False)