Jeffgold's picture
Update app.py
8ca14c3
raw
history blame
1.23 kB
import gradio as gr
from gradio.components import Video
import os
def transcode_video(video_path):
"""Transcodes a video file to m3u8 using ffmpeg.
Args:
video_path: The path to 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_path.split('/')[-1]}.m3u8" )
Input(video_path).output(output_file, format="hls").run()
# Return the path to the transcoded file.
return output_file
video_files = [
"/path/to/NEARHUBanimation.mp4",
]
# Upload the video file to the space.
space.upload_file("/path/to/NEARHUBanimation.mp4")
# Transcode the video file.
space.run_script("transcode_video.py")
# Launch a huggingface interface that allows you to play the transcoded video file.
demo = hfs.Interface(transcode_video,
hfs.components.Video(),
"playable_video",
examples=video_files,
cache_examples=True)
if __name__ == "__main__":
demo.launch()