Resizing Videos with Python (and ChatGPT)

Ryan Knightly
The Floating Point
Published in
2 min readJun 27, 2023

I recently needed to resize a video file to 886 x 1920 pixels to comply with App Store requirements for video previews.

There are a few options to do this, from iMovie to online tools to more advanced video editors. However, iMovie is slow and difficult to use, the online editors make you pay to remove a watermark, and video editors cost money and take time to learn.

Why not write a script to do it? And this is 2023, so why not ask ChatGPT to help? Here’s what I asked:

Write a Python script to take a .mov video file and convert the dimensions to a given height and width in pixels.

I had to tweak the output to match Apple’s video specs, but here’s the working version. All it requires is pip install moviepy and it's ready to go.

from moviepy.editor import VideoFileClip

def resize_video(input_path, output_path, width, height):
# Load the video clip
video = VideoFileClip(input_path)

# Resize the video clip
resized_video = video.resize((width, height))

# Write the resized video to the output file
resized_video.write_videofile(output_path, fps=30, codec='libx264', audio_codec='aac')

# Close the video clip
video.close()

# Example usage
input_file = 'input.mov'
output_file = 'resized_output.mov'
desired_width = 886
desired_height = 1920

resize_video(input_file, output_file, desired_width, desired_height)

This is now my favorite way to resize videos.

But a more important takeaway is this: ChatGPT is an excellent tool for prototyping and writing quick scripts.

In the days before LLMs, we would first have to discover that moviepy does what we want, read the documentation to learn that we need to create a VideoFileClip, how to resize it, and how to write it out. Not too bad, but more work than asking ChatGPT to do most of that work for you.

--

--