Convert Figma logo to code with AI

Zulko logomoviepy

Video editing with Python

12,463
1,559
12,463
482

Top Related Projects

Video Editor for Linux

The swiss army knife of lossless video/audio editing

11,216

cross-platform (Qt), open-source (GPLv3) video editor

OpenShot Video Editor is an award-winning free and open-source video editor for Linux, Mac, and Windows, and is dedicated to delivering high quality video editing and animation solutions to the world.

Free and open source video editor, based on MLT Framework and KDE Frameworks

8,862

Manipulate audio with a simple and easy high level interface

Quick Overview

MoviePy is a Python library for video editing and manipulation. It provides a simple and intuitive interface for tasks such as cutting, concatenating, titling, and applying various effects to video clips. MoviePy is built on top of FFmpeg and can handle a wide range of video formats.

Pros

  • Easy to use with a high-level, Pythonic API
  • Supports a wide range of video editing operations and effects
  • Can work with various video formats thanks to FFmpeg integration
  • Extensible through custom effects and filters

Cons

  • Performance can be slow for complex operations or large video files
  • Limited support for advanced video editing features compared to professional software
  • Dependency on FFmpeg can sometimes cause installation issues
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Cutting a video clip:
from moviepy.editor import VideoFileClip

clip = VideoFileClip("input_video.mp4").subclip(10, 20)
clip.write_videofile("output_video.mp4")
  1. Adding text to a video:
from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip

video = VideoFileClip("input_video.mp4")
text = TextClip("Hello, MoviePy!", fontsize=70, color='white')
text = text.set_pos('center').set_duration(5)

final = CompositeVideoClip([video, text])
final.write_videofile("output_video.mp4")
  1. Concatenating multiple video clips:
from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("clip1.mp4")
clip2 = VideoFileClip("clip2.mp4")
clip3 = VideoFileClip("clip3.mp4")

final_clip = concatenate_videoclips([clip1, clip2, clip3])
final_clip.write_videofile("concatenated_video.mp4")

Getting Started

To get started with MoviePy, first install it using pip:

pip install moviepy

Then, import the necessary modules and start editing your videos:

from moviepy.editor import VideoFileClip, AudioFileClip, concatenate_videoclips

# Load a video file
video = VideoFileClip("my_video.mp4")

# Trim the video
trimmed_video = video.subclip(10, 20)

# Add audio
audio = AudioFileClip("my_audio.mp3")
final_video = trimmed_video.set_audio(audio)

# Write the result to a file
final_video.write_videofile("output_video.mp4")

This example demonstrates loading a video, trimming it, adding an audio track, and saving the result.

Competitor Comparisons

Video Editor for Linux

Pros of Flowblade

  • Full-featured video editing GUI application, offering a more comprehensive editing experience
  • Supports multi-track editing and complex compositions
  • Includes built-in effects and transitions for advanced video production

Cons of Flowblade

  • Less flexible for programmatic video manipulation compared to MoviePy
  • Steeper learning curve for users new to video editing software
  • Limited to Linux operating systems, reducing accessibility for Windows and macOS users

Code Comparison

MoviePy (Python script):

from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("video1.mp4")
clip2 = VideoFileClip("video2.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile("output.mp4")

Flowblade (XML project file snippet):

<mlt>
  <playlist id="playlist0">
    <entry producer="producer0" in="0" out="250"/>
    <entry producer="producer1" in="0" out="300"/>
  </playlist>
</mlt>

Note: Flowblade uses a GUI for most operations, so direct code comparison is limited. The XML snippet represents a simplified project structure.

The swiss army knife of lossless video/audio editing

Pros of LosslessCut

  • User-friendly GUI for video editing, making it accessible to non-programmers
  • Focuses on lossless cutting, preserving original video quality
  • Supports a wide range of video formats and codecs

Cons of LosslessCut

  • Limited to basic cutting and merging operations
  • Less flexibility for complex video processing tasks
  • Not suitable for programmatic video manipulation

Code Comparison

MoviePy (Python):

from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("video1.mp4").subclip(0, 5)
clip2 = VideoFileClip("video2.mp4").subclip(2, 8)
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile("output.mp4")

LosslessCut (JavaScript):

// No direct code comparison available as LosslessCut is a GUI-based application
// It doesn't provide a programming interface for video manipulation

MoviePy is a Python library for programmatic video editing, offering extensive control over video processing tasks. It's ideal for developers and those comfortable with coding. LosslessCut, on the other hand, is a desktop application with a graphical interface, making it more accessible to general users for quick, lossless video cutting and merging operations.

11,216

cross-platform (Qt), open-source (GPLv3) video editor

Pros of Shotcut

  • Full-featured video editing GUI application, offering a more comprehensive set of tools for video editing
  • Cross-platform support (Windows, macOS, Linux) with a native interface
  • Real-time preview and rendering capabilities

Cons of Shotcut

  • Steeper learning curve due to its complex interface and extensive features
  • Requires more system resources compared to MoviePy's lightweight Python-based approach
  • Less suitable for programmatic video manipulation and automation tasks

Code Comparison

MoviePy (Python):

from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("video1.mp4")
clip2 = VideoFileClip("video2.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile("output.mp4")

Shotcut (XML-based project file):

<?xml version="1.0" encoding="utf-8"?>
<mlt LC_NUMERIC="C" version="7.13.0" root="/path/to/project" producer="main_bin">
  <playlist id="main_bin">
    <property name="xml_retain">1</property>
  </playlist>
  <producer id="producer0" in="00:00:00.000" out="00:00:04.999">
    <property name="resource">/path/to/video1.mp4</property>
  </producer>
  <producer id="producer1" in="00:00:00.000" out="00:00:04.999">
    <property name="resource">/path/to/video2.mp4</property>
  </producer>
</mlt>

OpenShot Video Editor is an award-winning free and open-source video editor for Linux, Mac, and Windows, and is dedicated to delivering high quality video editing and animation solutions to the world.

Pros of OpenShot

  • Full-featured GUI video editor with a user-friendly interface
  • Supports a wide range of video, audio, and image formats
  • Includes advanced features like keyframe animation and 3D animated titles

Cons of OpenShot

  • Steeper learning curve for beginners compared to MoviePy's simple API
  • Requires installation of the full application, which may be resource-intensive
  • Less suitable for programmatic video editing tasks

Code Comparison

MoviePy (Python script):

from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("video1.mp4")
clip2 = VideoFileClip("video2.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile("output.mp4")

OpenShot (XML project file snippet):

<project>
  <clip id="0" src="video1.mp4" start="0" end="10" />
  <clip id="1" src="video2.mp4" start="10" end="20" />
  <track>
    <clip id="0" position="0" />
    <clip id="1" position="10" />
  </track>
</project>

MoviePy is more suitable for scripting and automation, while OpenShot provides a comprehensive GUI for interactive video editing. MoviePy offers simplicity and flexibility for programmers, whereas OpenShot caters to users who prefer a traditional video editing interface with a broader set of features.

Free and open source video editor, based on MLT Framework and KDE Frameworks

Pros of kdenlive

  • Full-featured video editing GUI application with a timeline interface
  • Supports a wide range of video and audio formats
  • Offers advanced features like multi-track editing, transitions, and effects

Cons of kdenlive

  • Requires installation and is not easily integrated into other Python projects
  • Limited programmatic control compared to MoviePy's scripting capabilities
  • Steeper learning curve for users new to video editing software

Code Comparison

MoviePy (Python script):

from moviepy.editor import VideoFileClip, concatenate_videoclips

clip1 = VideoFileClip("video1.mp4")
clip2 = VideoFileClip("video2.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile("output.mp4")

kdenlive (XML project file snippet):

<mlt>
  <playlist id="playlist0">
    <entry producer="producer0" in="00:00:00.000" out="00:00:10.000"/>
    <entry producer="producer1" in="00:00:00.000" out="00:00:15.000"/>
  </playlist>
</mlt>

Note: kdenlive uses a GUI for most operations, so direct code comparison is limited. The XML snippet represents a simplified project structure.

8,862

Manipulate audio with a simple and easy high level interface

Pros of pydub

  • Lightweight and focused specifically on audio processing
  • Simple and intuitive API for basic audio operations
  • Faster processing for audio-only tasks

Cons of pydub

  • Limited to audio manipulation, lacks video capabilities
  • Fewer advanced audio processing features compared to moviepy

Code Comparison

pydub:

from pydub import AudioSegment

sound = AudioSegment.from_mp3("example.mp3")
first_10_seconds = sound[:10000]
first_10_seconds.export("first_10_seconds.mp3", format="mp3")

moviepy:

from moviepy.editor import AudioFileClip

audio = AudioFileClip("example.mp3")
first_10_seconds = audio.subclip(0, 10)
first_10_seconds.write_audiofile("first_10_seconds.mp3")

Summary

pydub is a lightweight library focused on audio processing, offering a simple API for basic operations. It's faster for audio-only tasks but lacks video capabilities. moviepy, on the other hand, provides a more comprehensive set of features for both audio and video manipulation, making it more versatile but potentially slower for simple audio tasks. The choice between the two depends on the specific requirements of your project, with pydub being ideal for quick audio processing and moviepy better suited for more complex audio-visual tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MoviePy

MoviePy page on the Python Package Index Discuss MoviePy on Gitter Build status on gh-actions Code coverage from coveralls.io

[!NOTE] MoviePy recently upgraded to v2.0, introducing major breaking changes. You can consult the last v1 docs here but beware that v1 is no longer maintained. For more info on how to update your code from v1 to v2, see this guide.

MoviePy (online documentation here) is a Python library for video editing: cuts, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects.

MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with Python 3.9+.

Example

In this example we open a video file, select the subclip between 10 and 20 seconds, add a title at the center of the screen, and write the result to a new file:

from moviepy import VideoFileClip, TextClip, CompositeVideoClip

# Load file example.mp4 and keep only the subclip from 00:00:10 to 00:00:20
# Reduce the audio volume to 80% of its original volume

clip = (
    VideoFileClip("long_examples/example2.mp4")
    .subclipped(10, 20)
    .with_volume_scaled(0.8)
)

# Generate a text clip. You can customize the font, color, etc.
txt_clip = TextClip(
    font="Arial.ttf",
    text="Hello there!",
    font_size=70,
    color='white'
).with_duration(10).with_position('center')

# Overlay the text clip on the first video clip
final_video = CompositeVideoClip([clip, txt_clip])
final_video.write_videofile("result.mp4")

How MoviePy works

Under the hood, MoviePy imports media (video frames, images, sounds) and converts them into Python objects (numpy arrays) so that every pixel becomes accessible, and video or audio effects can be defined in just a few lines of code (see the built-in effects for examples).

The library also provides ways to mix clips together (concatenations, playing clips side by side or on top of each other with transparency, etc.). The final clip is then encoded back into mp4/webm/gif/etc.

This makes MoviePy very flexible and approachable, albeit slower than using ffmpeg directly due to heavier data import/export operations.

Installation

Intall moviepy with pip install moviepy. For additional installation options, such as a custom FFMPEG or for previewing, see this section. For development, clone that repo locally and install with pip install -e .

Documentation

The online documentation (here) is automatically built at every push to the master branch. To build the documentation locally, install the extra dependencies via pip install moviepy[doc], then go to the docs folder and run make html.

Contribute

MoviePy is open-source software originally written by Zulko and released under the MIT licence. The project is hosted on GitHub, where everyone is welcome to contribute and open issues or give feedback Please read our Contributing Guidelines. To ask for help or simply discuss usage and examples, use our Reddit channel.

Maintainers

Maintainers wanted! this library has only been kept afloat by the involvement of its maintainers, and there are times where none of us have enough bandwidth. We'd love to hear about developers interested in giving a hand and solving some of the issues (especially the ones that affect you) or reviewing pull requests. Open an issue or contact us directly if you are interested. Thanks!