Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import imageio
|
| 2 |
+
from moviepy.editor import ImageSequenceClip
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def animated_webp_to_video(webp_path, output_path, fps=24):
|
| 6 |
+
"""
|
| 7 |
+
Convert an animated WebP file to an MP4 video.
|
| 8 |
+
|
| 9 |
+
:param webp_path: Path to the animated WebP file.
|
| 10 |
+
:param output_path: Path where the output video will be saved.
|
| 11 |
+
:param fps: Frames per second for the video (default is 24).
|
| 12 |
+
"""
|
| 13 |
+
# Read the animated hereafter file
|
| 14 |
+
reader = imageio.get_reader(webp_path)
|
| 15 |
+
|
| 16 |
+
frames = []
|
| 17 |
+
for frame in reader:
|
| 18 |
+
frames.append(frame)
|
| 19 |
+
|
| 20 |
+
# Convert frames to video
|
| 21 |
+
clip = ImageSequenceClip(frames, fps=fps)
|
| 22 |
+
clip.write_videofile(output_path, codec='libx264')
|
| 23 |
+
|
| 24 |
+
# Define the Gradio interface
|
| 25 |
+
def convert_webp_to_video(webp_file):
|
| 26 |
+
output_path = 'output.mp4' # You can customize this if needed
|
| 27 |
+
animated_webp_to_video(webp_file.name, output_path)
|
| 28 |
+
return output_path
|
| 29 |
+
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=convert_webp_to_video,
|
| 32 |
+
inputs=gr.File(label="Upload an animated WebP file"),
|
| 33 |
+
outputs="video",
|
| 34 |
+
title="Webp to Video Converter",
|
| 35 |
+
description="Upload an animated WebP file and convert it to an MP4 video."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Launch the Gradio interface
|
| 39 |
+
iface.launch()
|