File size: 1,378 Bytes
f74ecf7 |
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 40 41 42 43 44 45 46 |
import os
import gradio as gr
import ffmpeg
def create_video_from_images(images_folder, frame_rate):
# Get list of images
images = [img for img in os.listdir(images_folder) if img.endswith(".jpg") or img.endswith(".jpeg") or img.endswith(".png")]
images.sort() # Ensure images are in order
if not images:
return "No images found in the folder."
# Create a temporary text file listing all images
with open("input_images.txt", "w") as file:
for img in images:
file.write(f"file '{os.path.join(images_folder, img)}'\n")
output_video = os.path.join(images_folder, "output_video.mp4")
# Use ffmpeg to create the video
(
ffmpeg
.input("input_images.txt", format='concat', safe=0)
.output(output_video, r=frame_rate, pix_fmt='yuv420p')
.run(overwrite_output=True)
)
# Remove temporary file
os.remove("input_images.txt")
return output_video
def gradio_interface(img_folder, frame_rate):
return create_video_from_images(img_folder, frame_rate)
iface = gr.Interface(
fn=gradio_interface,
inputs=[
gr.inputs.Folder(type="dir", label="Upload Folder with Images"),
gr.inputs.Slider(minimum=1, maximum=60, default=30, label="Frame Rate (FPS)")
],
outputs="file", # Return the path to the created video
live=True
)
iface.launch() |