|
import gradio as gr |
|
from moviepy.editor import VideoFileClip, concatenate_videoclips |
|
import random |
|
|
|
|
|
def process_videos(videos, rotate_option): |
|
clips = [] |
|
|
|
|
|
for video_path in videos: |
|
clip = VideoFileClip(video_path) |
|
|
|
|
|
if clip.duration > 3: |
|
clip = clip.subclip(0, 3) |
|
|
|
|
|
if rotate_option == "90 grados": |
|
clip = clip.rotate(90) |
|
elif rotate_option == "180 grados": |
|
clip = clip.rotate(180) |
|
elif rotate_option == "270 grados": |
|
clip = clip.rotate(270) |
|
|
|
clips.append(clip) |
|
|
|
|
|
random.shuffle(clips) |
|
|
|
|
|
final_clip = concatenate_videoclips(clips) |
|
|
|
|
|
output_path = "output_video.mp4" |
|
final_clip.write_videofile(output_path, codec="libx264") |
|
|
|
|
|
return output_path |
|
|
|
|
|
iface = gr.Interface( |
|
fn=process_videos, |
|
inputs=[ |
|
gr.Files(label="Sube tus videos (MP4)", file_count="multiple", type="filepath"), |
|
gr.Radio(["Sin rotaci贸n", "90 grados", "180 grados", "270 grados"], label="Rotar video") |
|
], |
|
outputs=gr.File(label="Video unido de salida"), |
|
title="Mezclar y Unir Videos con Rotaci贸n", |
|
description="Sube varios videos en formato 9:16. El sistema cortar谩 los primeros 3 segundos de cada video, los mezclar谩 en un orden aleatorio, aplicar谩 la rotaci贸n seleccionada y generar谩 un nuevo archivo de video." |
|
) |
|
|
|
|
|
iface.launch() |
|
|