Spaces:
Build error
Build error
| import gradio as gr | |
| from moviepy.editor import VideoFileClip | |
| def convert_video(input_video): | |
| output_path = "output_9x16.mp4" | |
| clip = VideoFileClip(input_video) | |
| if clip.duration > 120: | |
| return "⚠️ Video too long! Please upload a clip shorter than 2 minutes." | |
| target_width = int(clip.h * 9 / 16) | |
| x_center = clip.w // 2 | |
| x1 = x_center - target_width // 2 | |
| x2 = x_center + target_width // 2 | |
| clip_resized = clip.crop(x1=x1, x2=x2, y1=0, y2=clip.h) | |
| clip_resized = clip_resized.resize(height=1920, width=1080) | |
| clip_resized.write_videofile(output_path, codec="libx264", audio_codec="aac") | |
| return output_path | |
| demo = gr.Interface( | |
| fn=convert_video, | |
| inputs=gr.Video(label="Upload 16:9 Video"), | |
| outputs=gr.Video(label="Converted 9:16 Video"), | |
| title="16:9 → 9:16 Video Converter", | |
| description="Upload a landscape video (≤2 minutes) and get a portrait version (1080x1920)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(share=True, ssr_mode=False) |