File size: 1,193 Bytes
513d2f5 |
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 |
import imageio
from moviepy.editor import ImageSequenceClip
import gradio as gr
def animated_webp_to_video(webp_path, output_path, fps=24):
"""
Convert an animated WebP file to an MP4 video.
:param webp_path: Path to the animated WebP file.
:param output_path: Path where the output video will be saved.
:param fps: Frames per second for the video (default is 24).
"""
# Read the animated hereafter file
reader = imageio.get_reader(webp_path)
frames = []
for frame in reader:
frames.append(frame)
# Convert frames to video
clip = ImageSequenceClip(frames, fps=fps)
clip.write_videofile(output_path, codec='libx264')
# Define the Gradio interface
def convert_webp_to_video(webp_file):
output_path = 'output.mp4' # You can customize this if needed
animated_webp_to_video(webp_file.name, output_path)
return output_path
iface = gr.Interface(
fn=convert_webp_to_video,
inputs=gr.File(label="Upload an animated WebP file"),
outputs="video",
title="Webp to Video Converter",
description="Upload an animated WebP file and convert it to an MP4 video."
)
# Launch the Gradio interface
iface.launch() |