Spaces:
Paused
Paused
import gradio as gr | |
import ffmpeg | |
from gradio.components import File | |
import os | |
def transcode_video(input_video_file, output_file, output_format, output_fps): | |
"""Transcodes a video file to m3u8 using ffmpeg. | |
Args: | |
input_video_file: The path to the video file to transcode. | |
output_file: The path to the transcoded m3u8 file. | |
output_format: The output format of the transcoded file. | |
output_fps: The output framerate of the transcoded file. | |
Returns: | |
The path to the transcoded file. | |
""" | |
# Create a folder to save the transcoded video file to. | |
output_dir = os.path.dirname(output_file) | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
# Transcode the video file. | |
ffmpeg.input(input_video_file).output(output_file, format=output_format, fps=output_fps).run() | |
# Return the path to the transcoded file. | |
return output_file | |
def name_file(file_path): | |
return os.path.basename(file_path.name) | |
input_video_file = File(accept=".mp4, .mov, .avi, .flv, .wmv, .mpeg, .mpg, .ogg, .webm") | |
outputs={"output_file": File(name_file(input_video_file), accept=".m3u8")} | |
gr.Interface( | |
transcode_video, | |
inputs={"input_video_file": input_video_file}, | |
outputs=outputs | |
).launch() | |