File size: 452 Bytes
1425afc | 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 | 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 |