Spaces:
Paused
Paused
File size: 1,299 Bytes
f001877 c8942d9 72c532f 7a80d3a c8942d9 5296733 40446f2 d47c1c5 40446f2 ec46e62 701ed9a b7d9c54 131761b ca0877d d0d220f b7d9c54 9bd2eae 7e0e151 c9de927 7e0e151 c9de927 9c183e4 06412df 7e0e151 72c532f 05649bb 7a80d3a 2024db3 7e0e151 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import os
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
# Define temp directory
temp_dir = tempfile.mkdtemp()
video_file = gr.inputs.File(label="Video File", type="file")
quality = gr.inputs.Dropdown(choices=["18", "23", "28", "32"], label="Quality", default="23")
aspect_ratio = gr.inputs.Dropdown(choices=[
"1:1",
"4:3",
"3:2",
"5:4",
"16:9",
"21:9",
"1.85:1",
"2.35:1",
"3:1",
"360",
"9:16",
"16:9",
"2:1",
"1:2",
"9:1",
], label="Aspect Ratio", default="16:9")
video_url = gr.inputs.Textbox(label="Video URL")
def convert_video(video_file: File, quality, aspect_ratio, video_url):
if video_file is None:
output_path = f"{temp_dir}/{Path(video_url).name}.m3u8"
else:
output_path = f"{temp_dir}/{Path(video_file).name}.m3u8"
ffmpeg_command = f"ffmpeg -i {video_file or video_url} -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, video_url], outputs=[outputs.Video()]).launch(share=False)
|