import moviepy.editor as mpy
def enlarge_and_pad_video(input_video, output_video, new_size=(1920, 1920), pad_color=(0, 0, 0)):
# Load the input video
clip = mpy.VideoFileClip(input_video)
# Calculate the padding values (assuming the video needs to be centered)
width_padding = (new_size[0] - clip.size[0]) // 2
height_padding = (new_size[1] - clip.size[1]) // 2
# Create a new video by enlarging and padding the input video
padded_clip = mpy.CompositeVideoClip([clip.set_position(("center", "center"))],
size=new_size,
bg_color=pad_color)
# Write the output video
padded_clip.write_videofile(output_video, codec='libx264', audio_codec='aac')
# Example usage
input_video = "input_1080x1920.mp4"
output_video = "output_1920x1920.mp4"
enlarge_and_pad_video(input_video, output_video)
This code will load the input video, enlarge it to 1920x1920 by keeping the aspect ratio unchanged (padding the extra space), and save it as the output video. The padded areas will be black (rgb: (0, 0, 0)). You can change the padding color by modifying the pad_color parameter.