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

10,740

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.

10,740

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

.. image:: https://badge.fury.io/py/moviepy.svg :target: PyPI_ :alt: MoviePy page on the Python Package Index .. image:: https://img.shields.io/gitter/room/movie-py/gitter?color=46BC99&logo=gitter :target: Gitter_ :alt: Discuss MoviePy on Gitter .. image:: https://img.shields.io/github/actions/workflow/status/Zulko/moviepy/test_suite.yml?logo=github :target: https://github.com/Zulko/moviepy/actions/workflows/test_suite.yml :alt: Build status on gh-actions .. image:: https://img.shields.io/coveralls/github/Zulko/moviepy/master?logo=coveralls :target: https://coveralls.io/github/Zulko/moviepy?branch=master :alt: Code coverage from coveralls.io

MoviePy (full documentation_) is a Python library for video editing: cutting, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects. See the gallery_ for some examples of use.

MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with Python 3.6+. Here it is in action in an IPython notebook:

.. image:: https://raw.githubusercontent.com/Zulko/moviepy/master/docs/demo_preview.jpeg :alt: [logo] :align: center

Example

In this example we open a video file, select the subclip between t=50s and t=60s, add a title at the center of the screen, and write the result to a new file:

.. code:: python

from moviepy import *

video = VideoFileClip("myHolidays.mp4").subclip(50,60)

# Make the text. Many more options are available.
txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')
             .with_position('center')
             .with_duration(10) )

result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...

Note: This example uses the new 2.x API, for MoviePy 1.0.3, currently on PyPI, see this snippet <https://gist.github.com/Zulko/57e6e50debef1834fb9b60700b1b9f99>_.

Maintainers wanted!

As there are more and more people seeking support (270 open issues as of Jan. 2021!) and all the MoviePy maintainers seem busy, 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!

Installation

MoviePy depends on the Python modules NumPy_, Imageio_, Decorator_, and Proglog_, which will be automatically installed during MoviePy's installation. The software FFMPEG should be automatically downloaded/installed (by imageio) during your first use of MoviePy (installation will take a few seconds). If you want to use a specific version of FFMPEG, follow the instructions in config_defaults.py. In case of trouble, provide feedback.

Installation by hand: download the sources, either from PyPI_ or, if you want the development version, from GitHub_, unzip everything into one folder, open a terminal and type:

.. code:: bash

$ (sudo) python setup.py install

Installation with pip: if you have pip installed, just type this in a terminal:

.. code:: bash

$ (sudo) pip install moviepy

If you have neither setuptools nor ez_setup installed, the command above will fail. In this case type this before installing:

.. code:: bash

$ (sudo) pip install setuptools

Optional but useful dependencies


You can install ``moviepy`` with all dependencies via:

.. code:: bash

    $ (sudo) pip install moviepy[optional]

ImageMagick_ is not strictly required, but needed if you want to incorporate texts. It can also be used as a backend for GIFs, though you can also create GIFs with MoviePy without ImageMagick.

Once you have installed ImageMagick, MoviePy will try to autodetect the path to its executable. If it fails, you can still configure it by setting environment variables (see the documentation).

PyGame_ is needed for video and sound previews (not relevant if you intend to work with MoviePy on a server but essential for advanced video editing by hand).

For advanced image processing, you will need one or several of the following packages:

- The Python Imaging Library (PIL) or, even better, its branch Pillow_.
- Scipy_ (for tracking, segmenting, etc.) can be used to resize video clips if PIL and OpenCV are not installed.
- `Scikit Image`_ may be needed for some advanced image manipulation.
- `OpenCV 2.4.6`_ or a more recent version (one that provides the package ``cv2``) may be needed for some advanced image manipulation.
- `Matplotlib`_

For instance, using the method ``clip.resize`` requires that at least one of Scipy, PIL, Pillow or OpenCV is installed.


Documentation
-------------

Building the documentation has additional dependencies that require installation.

.. code:: bash

    $ (sudo) pip install moviepy[doc]

The documentation can be generated and viewed via:

.. code:: bash

    $ python setup.py build_docs

You can pass additional arguments to the documentation build, such as clean build:

.. code:: bash

    $ python setup.py build_docs -E

More information is available from the `Sphinx`_ documentation.

New in 1.0.0: Progress bars and messages with Proglog
-------------------------------------------------------

Non-backwards-compatible changes were introduced in 1.0.0 to
manage progress bars and messages using
`Proglog <https://github.com/Edinburgh-Genome-Foundry/Proglog>`_, which
enables to display nice progress bars in the console as well as in
a Jupyter notebook or any user interface, like a website.

To display notebook friendly progress bars, first install IPyWidgets:

.. code::

    sudo pip install ipywidgets
    sudo jupyter nbextension enable --py --sys-prefix widgetsnbextension

Then at the beginning of your notebook enter:

.. code:: python

    import proglog
    proglog.notebook()

Have a look at the Proglog project page for more options.

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, ask for help or simply give feedback. Please read our `Contributing Guidelines`_ for more information about how to contribute!

You can also discuss the project on Reddit_ or Gitter_. These are preferred over GitHub issues for usage questions and examples.


Maintainers
-----------

- Zulko_ (owner)
- `@tburrows13`_
- `@mgaitan`_
- `@earney`_
- `@mbeacom`_
- `@overdrivr`_
- `@keikoro`_
- `@ryanfox`_
- `@mondeja`_


.. MoviePy links
.. _gallery: https://zulko.github.io/moviepy/gallery.html
.. _documentation: https://zulko.github.io/moviepy/
.. _`download MoviePy`: https://github.com/Zulko/moviepy
.. _`Label Wiki`: https://github.com/Zulko/moviepy/wiki/Label-Wiki
.. _Contributing Guidelines: https://github.com/Zulko/moviepy/blob/master/CONTRIBUTING.md

.. Websites, Platforms
.. _Reddit: https://www.reddit.com/r/moviepy/
.. _PyPI: https://pypi.python.org/pypi/moviepy
.. _GitHub: https://github.com/Zulko/moviepy
.. _Gitter: https://gitter.im/movie-py/Lobby

.. Software, Tools, Libraries
.. _Pillow: https://pillow.readthedocs.org/en/latest/
.. _Scipy: https://www.scipy.org/
.. _`OpenCV 2.4.6`: https://github.com/skvark/opencv-python
.. _Pygame: https://www.pygame.org/download.shtml
.. _Numpy: https://www.scipy.org/install.html
.. _imageio: https://imageio.github.io/
.. _`Scikit Image`: https://scikit-image.org/docs/stable/install.html
.. _Decorator: https://pypi.python.org/pypi/decorator
.. _proglog: https://github.com/Edinburgh-Genome-Foundry/Proglog
.. _ffmpeg: https://www.ffmpeg.org/download.html
.. _ImageMagick: https://www.imagemagick.org/script/index.php
.. _`Matplotlib`: https://matplotlib.org/
.. _`Sphinx`: https://www.sphinx-doc.org/en/master/setuptools.html

.. People
.. _Zulko: https://github.com/Zulko
.. _`@mgaitan`: https://github.com/mgaitan
.. _`@tburrows13`: https://github.com/tburrows13
.. _`@earney`: https://github.com/earney
.. _`@mbeacom`: https://github.com/mbeacom
.. _`@overdrivr`: https://github.com/overdrivr
.. _`@keikoro`: https://github.com/keikoro
.. _`@ryanfox`: https://github.com/ryanfox
.. _`@mondeja`: https://github.com/mondeja