
Video editing with Python - wilsonfiifi
https://github.com/Zulko/moviepy
======
rayalez
I've recently learned that 3blue1brown's [1] videos are generated with python:

[https://github.com/3b1b/manim](https://github.com/3b1b/manim)

[1]
[https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw](https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw)

~~~
makmanalp
I've actually played around with this a bit and it was surprisingly pleasant
to use even with all the "beta software" warnings

------
minimaxir
A few months ago I used MoviePy to create animated Magic: the Gathering cards
(HN discussion:
[https://news.ycombinator.com/item?id=15449955](https://news.ycombinator.com/item?id=15449955)
, technical writeup: [http://minimaxir.com/2017/11/magic-the-
gifening/](http://minimaxir.com/2017/11/magic-the-gifening/))

Even though MoviePy is an "older" library (original HN discussion from back in
2014:
[https://news.ycombinator.com/item?id=7121104](https://news.ycombinator.com/item?id=7121104)),
it still works pretty well, although you may have to fuss around with the low-
level FFMPEG settings to get what you want. I'm surprised that there hasn't
been more usage of MoviePy actually.

------
justswim
I'm the CTO at Kapwing ([https://www.kapwing.com](https://www.kapwing.com)),
where we use MoviePy for all of our products (all of which help users edit
video online). Sometimes the documentation has been enigmatic but overall the
library has made it really easy to create a video processing backend without
having to dive deeply into combining ImageMagick and FFMPEG at a low level.

Funny enough, MoviePy makes it so easy to edit videos that we also use it to
edit images. But the way it works is when a user uploads an image, we convert
the image into a video format, edit it with MoviePy, then convert it back into
an image. A little inefficient, but it works better for us than writing a
completely different branch of code to handle images.

Having worked with MoviePy for a while my main ideas for improvement would be:
1) Create a callback for video editing progress so that it could be outputted
to the frontend, etc, 2) Make predefined transitions - currently transitions
need to be manually calculated, would be nice to have smarter presets to make
it easier to create something like a slideshow, 3) improve threading over
multiple CPUs - not sure how possible it would be for the library itself to
handle this but from our initial tests ffmpeg by itself seems to handle
threading more effectively

------
soegaard
Don’t forget to check Leif Andersen’s video language

    
    
      https://lang.video/
    

It is a Racket language for editing videos. Quite handy when you need to edit
many, similar conference videos.

~~~
baldfat
I love this tool and just started using it.

If this did DNxHD codec transcoding I would love it forever. I need to ask and
look to see if this is possible to add. When you edit videos you SHOULD
transcode your videos into a format that actually uses one image per frame
(DNxHD or PreRes (On Mac)) and than then deliver it back into a compressed
format like H.264.

~~~
unicornporn
> When you edit videos you SHOULD transcode your videos into a format that
> actually uses one image per frame (DNxHD or PreRes (On Mac)) and than then
> deliver it back into a compressed format like H.264.

Yes, you should transcode your videos to an intra-frame codec (i use ProRes at
540p). But (and this is important), this is only a proxy format. When you
export your creation the video editor should automatically use the original
files for rendering. Premiere this very well nowadays[1].

[1] [https://helpx.adobe.com/premiere-pro/how-to/proxy-
media.html](https://helpx.adobe.com/premiere-pro/how-to/proxy-media.html)

~~~
baldfat
If you have a H.264 (non-intraframed) and it is playing back in preview fine I
try to just use that instead most of the time.

ProRes 540p is HUGE. Are you working with 4k? If not I would knock that down.
Apple ProRes 422 is only 147 Mbs. [https://www.premiumbeat.com/blog/5-things-
you-should-know-ab...](https://www.premiumbeat.com/blog/5-things-you-should-
know-about-prores/)

~~~
unicornporn
> ProRes 540p is HUGE.

540p means 540 pixels on the short side (height). That is very low res and
they're not big.

> Are you working with 4k?

Very close, UHD resolution.

------
m45t3r
It seems similar to Vapoursynth:
[http://www.vapoursynth.com/](http://www.vapoursynth.com/)

AFAIK, Vapoursynth is more powerful thanks to its module system, however the
ability to integrate with IPython notebooks of MoviePy seems nice.

------
153957
Recently I discovered ffmpeg-python [1], also a nice Python frontend to
FFmpeg. One of its best features is being able to show nice graphs [2] showing
where which filters are applied from in to output. And all FFmpeg filters can
be used, it is a thin layer over FFmpeg, just much more readable.

[1] [https://github.com/kkroening/ffmpeg-
python](https://github.com/kkroening/ffmpeg-python) [2]
[https://github.com/kkroening/ffmpeg-python#complex-filter-
gr...](https://github.com/kkroening/ffmpeg-python#complex-filter-graphs)

------
debt
Video editing apis are a pretty neat way to edit video.

Apple provides a nice set of apis to achieve this as well:

[https://developer.apple.com/documentation/avfoundation/avmut...](https://developer.apple.com/documentation/avfoundation/avmutablecomposition)

------
mncharity
A few years ago I used moviepy to make the animated user-test videos in [1].
The idea was to create science education videos using a software-like process
of iterative development and guerrilla street usability testing.

Traditional science education videos are created by sort of a waterfall
process. Throw the script/footage/video over the wall, and just hope it kind
of works when it hits users. But it seems this usually doesn't work -
prolifically creating misconceptions, while failing to provide transferable
understanding. Ok for a "motivational speaker" role, but not for a "tutor".
Someone at a leading educational video shop once told me 'sure, it would be
great to make user testing part of our development - just as soon as we find
anyone willing to fund that'.

Regrettably, my videos didn't user test well. The exercise didn't converge,
and was abandoned. I had envisioned an incremental process, of informal
testing for appeal, understanding and misconceptions, while improving clarity
of explanation. Instead, what I found was a minefield. Bacteria and viruses
get bad press, so for some "a fun story about bacteria!" has the emotion tone
of "a fun story about genocide!". An elderly British gentleman was distressed
by the mention of "millimeters", which brought back unhappy memories of
learning metric as a child. An MIT student was disturbed by the viscerals of
breaking off the head of a T4 phage (zoomed to chicken-size). Someone ran away
exclaiming "how could you show me something so disgusting?!", for reasons
unknown, but perhaps from having not understood anything, and thus seeing a
pile of E.coli, as a pile of poo. Lot's of "oh my, I certainly didn't
anticipate _that_ failure mode". And this wasn't long-tail variance - I wasn't
testing enough to see any. This kind of nonlinearity seemed common case. I
also hit some newby with "insufficient domain expertise on tap" mistakes, like
underestimating the interference effects between spoken and written input -
having a character speaking visible text works startlingly poorly.

I wrapped moviepy in a framework to create lots of minor variants for
testing...

    
    
        class NovX4 (FilmCommon2):
            default_shots = 'context','question','realsize','zooming','views','playset','buildings','measure','stories'
            question_shots = 'question_how','question_sizes','question_planets','question_atoms'
    

with the animations timed to recorded speech (the computer voices I had
available didn't test well)... _" How can you remember, the sizes of small
things?"_

    
    
            question_how_script = aka(am18.HowCanYouRemember)
            question_sizes_script = aka(am18.TheSizesOfThings)
    

and animation code sharing using inheritance and mixins and injection and ...

    
    
        class NovX6 (NovX4):
    
            def question_sizes_frame (self,t,d):
                ca = self.setup_table()
                ca.teacher().draw()
                ca.side_table()
                ca.room.mv(.2,.55).gs().otp().rotate(.2).draw_milli(image_of_book_life_size_zoo).gr()
                ca.room.mv(.0,.3).gs().otp().rotate(.4).draw_milli(image_of_pizza_slice).gr()
                if t > d * .5:
                    ca.room.mv(.3,.4).gs().otp().rotate(-.2).draw_milli(image_of_walking_cat).gr()
                self.teardown()
    

Doing programmatic video production had some nice properties, vis a
traditional video animation pipeline. It was easier to revise past decisions,
to support a set of active and evolving tests, and thus to explore possibility
space. Without my being a "redraw this scene for the tenth time this morning"
magically-fast skilled animation artist. But some things would have been much
easier with a normal direct-manipulation UI. And there was a slippery slope of
reinventing wheels ("oh, I guess I need to add feature X to the character
rigging to get that effect :("). If I were starting on it today, years
later... I'd likely use python and Blender instead. For the ecosystem. I was
pushing moviepy well outside its normal use case.

[1] The stick-figure videos, in the top _How to remember sizes_ section, of
the slowly-loading wasn't-intended-to-be-public page
[http://www.clarifyscience.info/part/Atoms](http://www.clarifyscience.info/part/Atoms)
.

------
bob_theslob646
If anyone wants to read the docs , here is a direct link

>[http://zulko.github.io/moviepy/](http://zulko.github.io/moviepy/)

~~~
rebuilder
The docs do appear to be somewhat incomplete, though, there's functionality
used in the examples that the docs otherwise don't seem to mention even
exists.

~~~
Miredly
I've used Moviepy fairly extensively in a recent project and yes, the docs are
incomplete. I've had to resort to actually reading the source code to figure
out why, for example, my argument was being ignored. I still have some
unresolved (though seemingly obscure) issues with transparency, and my
question to the moviepy subreddit went unanswered.

------
marttt
Is there anything similar for non-destructive audio production except for
Ecasound [1], Nama [2], Csound or SoX?

There was an interesting paper about SPED, a sound file editor [3], but I'm
afraid this was just a proposal. And AudioRegent [4], and a few links,
somewhere, to using makefiles in audio production, but I've lost track on
these.

A quote from the SPED paper:

    
    
        "The editor should be usable without graphical user
        interface or it should not make any assumptions about 
        it.
        This feature may seem strange if we think of the modern
        computer based editing systems which basically always
        have some kind of graphical user interface. On the other
        hand when comparing to analogue tape splicing one
        might ask how mandatory the graphical user interface
        really is."
    

I've been thinking that a CLI audio editor (slicer, re-organizer) with a
syntax similar to ed or sam [5] would be cool to experiment with. Imagine a
CLI non-destructive digital audio editor built on top of a RPi or similar,
running headless, only needing a tiny conrtol panel with a few buttons; maybe
hooked to a tiny e-ink display for emergencies.

(Yep, love sound editing; tired of screens or laptops in bags. I would love an
"iPod Nano of non-destructive digital audio editing", but I am not the man to
build one myself.)

1: [http://nosignal.fi/ecasound/](http://nosignal.fi/ecasound/)

2: [https://freeshell.de/~bolangi/nama](https://freeshell.de/~bolangi/nama)

3: [https://tinyurl.com/y9s8mgme](https://tinyurl.com/y9s8mgme) [pdf]

4:
[http://journal.code4lib.org/articles/2882](http://journal.code4lib.org/articles/2882)

5:
[http://doc.cat-v.org/plan_9/4th_edition/papers/sam/](http://doc.cat-v.org/plan_9/4th_edition/papers/sam/)

------
lanewinfield
I use this for my Freeze Frame Bot (and many others). MoviePy is super
powerful and love playing with it.

[http://twitter.com/freezeframebot](http://twitter.com/freezeframebot)

------
blt
This looks cool. I am planning to write some tools for semi-automated
processing of a video dataset soon. Are there any other strong alternatives to
this library that I should consider? Am OK with any language.

An example task: automatically detect cuts between different shots with high
sensitivity, e.g. many false positives, show the user a clip of +/\- 2 seconds
around each proposed cut, user presses a key to confirm/deny that it's
actually a cut.

~~~
Miredly
It seems to me like what you're trying to do is analyze video, while Moviepy
is mostly really good at programatic editing. Have you looked in to OpenCV?

~~~
blt
Yeah I would detect the cuts with something else. I just need the library to
read/write video files, display them on screen, etc.

------
ageofwant
I have this notion that in time, as people's general comfort level interacting
with computers and advanced computing platforms like Python become rote. That
computer interfaces will be more REPL like, and less application, or GUI like.
That the principle of general computing will be applicable at interaction
level, not application level, if you will.

Future users may consider today's restrictive GUI interfaces as quaint
anachronism of the stupid ages.

~~~
sbergot
I strongly disagree with this prediction. That may be true for some lines of
work where people have a strong technical background and uses a specific set
of applications all the time (such as scientific computing). In all other
cases, gui will always win because:

\- Non technical people lack the capacity to formalize their goal \- many
document creators want wysiwyg applications \- programming languages are
powerful but hard to "discover". People don't want to read the docs for
something they will use once in a while

~~~
ageofwant
'Future people' will all be 'technically strong' by today's standards at
least. They will expect their tools to be powerful and have a whole childhood
to familiarize and internalise concepts and paradigms. Pointy clicky is not
going to cut it, not for anything worth doing. Of course there will be toys,
of which I enjoy many, I'm not talking about those.

The only intuitive interface is the nipple, everything else is learned. It
also seems you got stuck on the notion that 'programming languages' are hard.
That does not need to be the case, not for native talkers. And REPL and
'wysiwyg' are certainly not mutually exclusive things,
[http://nbviewer.jupyter.org/url/jakevdp.github.com/downloads...](http://nbviewer.jupyter.org/url/jakevdp.github.com/downloads/notebooks/XKCD_plots.ipynb)
that seems pretty what you see is what you get to me.

~~~
aluhut
I wonder where you get that prediction from. We've came from windows GUIs over
single apps on mobile phones to "just tell the machine what you want". The
development goes further away from consoles and "typing" of any kind.

Consumers want GUIs. Show and don't tell is the way it goes.

------
dimatura
I've used moviepy quite a lot and even submitted a PR or two. It's not
perfect, and docs aren't super up to date. For many tasks a good nonlinear
editor is way easier. BUT, it also makes some tasks really easy that seem
surprisingly complex to do with (the admittedly simple) GUI tools I've tried.
E.g. making a 3x3 montage of videos playing simultaneously, with a caption
beneath each.

------
z_open
I think I'll just use this. I often need to cut up videos and I've found that
using linux's video editing tools are horrendous. Even using ffmpeg from the
command line doesn't work out due to its horrendous tolerance for choosing
start and end points.

