Spaces:
Paused
Paused
File size: 993 Bytes
c8942d9 72c532f 7a80d3a c8942d9 5296733 40446f2 d47c1c5 40446f2 ec46e62 90e2263 131761b 412d007 d0d220f 11f8d05 c9de927 6d721d7 06412df 412d007 72c532f 05649bb 7a80d3a 2024db3 412d007 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import ffmpeg
import subprocess
from gradio import components
import tempfile
from pathlib import Path
from gradio import inputs
# Define File object
File = Path
video_file = gr.inputs.File(label="Video File")
quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
aspect_ratio = gr.inputs.Slider(min=1, max=16, step=1, label="Aspect Ratio", default=16)
def convert_video(video_file: File, quality, aspect_ratio):
if video_file is None:
output_path = gr.inputs.Textbox(label="Video URL")
else:
output_path = f"{temp_dir}/{Path(video_file).stem}.m3u8"
ffmpeg_command = f"ffmpeg -i {video_file or output_path} -c:v libx264 -crf {quality} -f hls -aspect {aspect_ratio} {temp_dir}/{output_path}"
subprocess.run(ffmpeg_command, shell=True)
return components.Video(output_path)
from gradio import outputs
gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio], outputs=[outputs.Video()]).launch()
|