Spaces:
Running
Running
| from moviepy.editor import VideoFileClip | |
| def vertical_crop(video_path): | |
| clip = VideoFileClip(video_path) | |
| w, h = clip.size | |
| target_ratio = 9 / 16 | |
| new_width = int(h * target_ratio) | |
| x_center = w / 2 | |
| cropped = clip.crop( | |
| x_center=x_center, | |
| width=new_width, | |
| height=h | |
| ) | |
| output = video_path.replace(".mp4", "_vertical.mp4") | |
| cropped.write_videofile(output, codec="libx264") | |
| return output |