Skip to content

Guide · Open source

How to use MoviePy: edit video with Python code

Updated · written with AI from the project's own documentation and checked against our catalogue data

MoviePy is a Python library for editing video from code. You write a script to cut clips, join them, add titles, layer videos and apply effects, then export the result as mp4, webm or GIF. This guide walks through installing it, running the example from the project README, and knowing when it is the right tool.

MoviePyZulko/moviepy · ★ 15.1k · MIT

Quick start

  1. 1Check Python. Confirm you have Python 3.9 or newer installed on Windows, Mac or Linux.
  2. 2Install MoviePy. Run pip install moviepy to install the library from PyPI.
  3. 3Prepare a video. Pick a local video file to edit and note its path.
  4. 4Write the edit script. Create a Python file that loads the clip, trims it and adds a title using the README example.
  5. 5Export the result. Call write_videofile with a filename such as result.mp4 to save the output.

Install MoviePy with pip

MoviePy requires Python 3.9 or newer and runs on Windows, Mac and Linux. Install the library from the Python Package Index (PyPI) with pip.

  • Check that you have Python 3.9+ installed.
  • Install the package from PyPI with the command below.
  • For a custom FFMPEG setup or preview support, see the installation section of the online docs.
pip install moviepy

Run a first video edit: trim a clip and add a title

The README example opens a video file, keeps only the part from 10 to 20 seconds, lowers the audio volume to 80 percent, creates a text title and places it at the center of the screen. The two clips are then combined and written to a new file.

Replace the file path with a video you have locally. The font value must point to a font file available on your system; the example uses Arial.ttf.

  • VideoFileClip loads the source video.
  • subclipped(10, 20) keeps the segment between 10 and 20 seconds.
  • with_volume_scaled(0.8) sets the audio to 80 percent of its original volume.
  • TextClip creates the title; with_duration(10) and with_position('center') set how long it shows and where.
  • CompositeVideoClip stacks the clips and write_videofile exports the result.
from moviepy import VideoFileClip, TextClip, CompositeVideoClip clip = ( VideoFileClip("long_examples/example2.mp4") .subclipped(10, 20) .with_volume_scaled(0.8) ) txt_clip = TextClip( font="Arial.ttf", text="Hello there!", font_size=70, color='white' ).with_duration(10).with_position('center') final_video = CompositeVideoClip([clip, txt_clip]) final_video.write_videofile("result.mp4")

Understand what MoviePy does under the hood

MoviePy imports video frames, images and sounds and converts them into numpy arrays, so every pixel can be read and changed. This is why you can define custom video or audio effects in a few lines of Python.

The library also mixes clips together, for example by concatenating them or placing one clip on top of another with transparency. The final result is encoded back into mp4, webm, GIF and other formats.

The trade-off is speed. The README says MoviePy is slower than using ffmpeg directly because of the heavier data import and export work.

Use MoviePy for GIFs, batch edits and custom effects

Because edits are plain Python, you can apply the same steps to many files in a loop. The README lists cutting, concatenating, titling, compositing and creating custom effects as core features, and the built-in effects are documented in the online reference.

For GIFs, export the finished clip to a .gif filename, as the README notes GIF is among the supported output formats.

  • Batch trimming: loop over a folder of videos and call subclipped on each.
  • Titles: add a TextClip and overlay it with CompositeVideoClip.
  • Short GIFs from footage: trim a segment and write it to a .gif file.
  • Custom per-frame effects: write your own effect in Python.

Check the v1 versus v2 version before you copy code

MoviePy recently moved to v2.0 with major breaking changes. The README states that v1 is no longer maintained and points to a guide for updating code from v1 to v2. Older tutorials may use v1 method names that no longer work.

If you have existing v1 code, read the update guide before upgrading. If you are starting fresh, follow the current examples, which use the v2 style such as subclipped and with_volume_scaled.

What people use it for

  • Batch-trim the start and end of many recordings with one script.
  • Add a fixed title to a set of videos.
  • Turn a segment of existing footage into a short GIF.
  • Write custom per-frame effects for a project in Python.

Frequently asked questions

How do I install MoviePy?

Run pip install moviepy. The README lists this as the install command from PyPI, and it needs Python 3.9 or newer. The online docs cover extra options such as a custom FFMPEG or preview support.

Is MoviePy free to use?

MoviePy is released under the MIT licence, as stated in the README. The source is hosted on GitHub, where you can read the licence terms.

Does MoviePy have a graphical editor?

No. The README describes MoviePy as code-only, with no interface. You edit videos by writing Python scripts.

Is MoviePy faster than ffmpeg?

No. The README says MoviePy is slower than using ffmpeg directly because of heavier data import and export. It is more flexible and easier to script, so it suits many tasks but not time-critical pipelines.

What are alternatives to MoviePy?

The README lists ffmpeg, PyAV and OpenCV as comparable projects. ffmpeg is the usual choice when speed matters most, while MoviePy is aimed at writing edits and effects in Python.

Why does my old MoviePy code not work?

MoviePy v2 introduced major breaking changes, and the README says v1 is no longer maintained. Read the official guide for updating from v1 to v2 and adjust your code to match.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

MoviePy suits Python developers, students and hobbyists who want to script video edits, make GIFs or write custom effects. Pick a graphical editor if you want a visual interface, or ffmpeg, PyAV or OpenCV if speed for large pipelines is the priority.

Install options & downloads