import gradio as gr import ffmpeg def transcode_video(video): """Transcodes a video file to m3u8 using ffmpeg. Args: video: The video file to transcode. Returns: The path to the transcoded file. """ # Create a folder to save the transcoded video file to. output_dir = os.path.dirname(video.path) if not os.path.exists(output_dir): os.makedirs(output_dir) # Transcode the video file. output_file = os.path.join(output_dir, f"{video.name}.m3u8" ) ffmpeg.input(video.path).output(output_file, format="hls").run() # Return the path to the transcoded file. return output_file demo = gr.Interface(transcode_video, gr.Video(), "playable_video", examples=[ os.path.join(os.path.dirname(__file__), "video/video_sample.mp4")], cache_examples=True) if __name__ == "__main__": demo.launch()