|
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). |
|
""" |
|
|
|
reader = imageio.get_reader(webp_path) |
|
|
|
frames = [] |
|
for frame in reader: |
|
frames.append(frame) |
|
|
|
|
|
clip = ImageSequenceClip(frames, fps=fps) |
|
clip.write_videofile(output_path, codec='libx264') |
|
|
|
|
|
def convert_webp_to_video(webp_file): |
|
output_path = 'output.mp4' |
|
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." |
|
) |
|
|
|
|
|
iface.launch() |