Skip to content

Commit

Permalink
Now you can do clip.resize instead of clip.vfx( fx.resize, )
Browse files Browse the repository at this point in the history
  • Loading branch information
Zulko committed Dec 20, 2013
1 parent 8f47936 commit a49b2fe
Show file tree
Hide file tree
Showing 28 changed files with 308 additions and 66 deletions.
2 changes: 1 addition & 1 deletion docs/_themes/flask/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- block extrahead %}
{{ super() }}
{% if theme_touch_icon %}
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
<link rel="orange-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
{% endif %}
<link media="only screen and (max-device-width: 480px)" href="{{
pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" />
Expand Down
3 changes: 2 additions & 1 deletion docs/crash_course/crash_course.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Example code
In a typical script, you load or generate some clips, modify them, combine them, and write the result to a video file.
So let us load a movie of my last holidays, lower the volume, add a title in the center of the video for the ten first seconds, and write the result in a file: ::
from moviepy.all import *
from moviepy.editor import *
# Load myHolidays.mp4 and select the subclip 00:00:50 - 00:00:60
clip = VideoFileClip("myHolidays.mp4").subclip(50,60)
Expand Down Expand Up @@ -193,6 +193,7 @@ Much better ! There are already many effects implemented in the modules ``moviep
fx( vfx.speedx, 2).\ # double speed
fx( vfx.colorx, 0.5) # darken (decreases the RGB values)

For convenience, frequently used methods such as ``resize`` can be called in a simpler way: ``clip.resize(...)`` instead of ``clip.fx( vfx.resize, ...)``


clip.fl
Expand Down
Binary file added docs/explications.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
MoviePy
=======

MoviePy is a Python module for script-based movie editing, which enables basic operations (cuts, concatenations, title insertions) to be done in a few lines. It can also be used for advanced compositing and special effects. Let me put together the clips in my demonstration folder: ::
MoviePy is a Python module for script-based movie editing, which enables basic operations (cuts, concatenations, title insertions) to be done in a few lines. It can also be used for advanced compositing and special effects. Let me put together the clips in my demonstration folder (you will find the code for most clips in the :ref:`examples`): ::
import os
from moviepy.all import *
from moviepy.editor import *
files = sorted( os.listdir("clips/") )
clips = [ VideoFileClip('clips/%s'%f) for f in files]
video = concatenate(clips, transition = VideoFileClip("logo.avi"))
Expand All @@ -22,9 +22,16 @@ MoviePy is a Python module for script-based movie editing, which enables basic o
allowfullscreen="true" width="550" height="450"></embed></object>
</center>

You will find the code for most clips in the :ref:`examples`.
How it works
-------------

You can do pretty much any effect you want with MoviePy, but it is just a framework, and in most cases you will need to code a little (or find someone who will !) to come to your goal.
MoviePy uses mainly ``ffmpeg`` for reading/writing multimedia files, and Numpy/Scipy for image and sound manipulations.

.. image:: explications.jpeg
:width: 570px
:align: center

You can do pretty much any effect you want with MoviePy, but it is just a framework, and in many cases you will need to code a little (or find someone who will !) to come to your goal.


User's Guide
Expand All @@ -38,6 +45,8 @@ User's Guide
examples/examples
ref/ref

Contribute !
-------------

MoviePy is a (still experimental) open source software written by Zulko_ and released under the MIT licence. Everyone is very welcome to help improve the project, fork it, blog on it, share code for new effects, etc... The more, the merrier !

Expand Down
8 changes: 4 additions & 4 deletions examples/compo_from_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from moviepy.all import *
from moviepy.plugins.segmenting import findObjects
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# Load the image specifying the regions.
im = ImageClip("../../ultracompositing/motif.png")
Expand All @@ -19,13 +19,13 @@
"../../videos/grsm_0005.mov"]]

# fit each clip into its region
comp_clips = [c.fx(vfx.resize, r.size).\
comp_clips = [c.resize(r.size).\
set_mask(r.mask).\
set_pos(r.screenpos)
for c,r in zip(clips,regions)]

cc = CompositeVideoClip(comp_clips,im.size)
cc.fx( vfx.resize, 0.6).to_videofile("../../bigcompo.avi")
cc.resize(0.6).to_videofile("../../bigcompo.avi")

# Note that this particular composition takes quite a long time of
# rendering (about 20s on my computer for just 4s of video).
10 changes: 5 additions & 5 deletions examples/example_with_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
movie put together.
"""

from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.drawing import color_split


Expand All @@ -22,7 +22,7 @@
# MAKE THE LEFT CLIP : cut, crop, add a mask

clip_left = main_clip.coreader().subclip(0,duration).\
fx( vfx.crop, x1=60, x2=60 + 2*W/3)
crop( x1=60, x2=60 + 2*W/3)

mask = color_split((2*W/3,H), p1=(W/3,H), p2=(2*W/3,0),
col1=1, col2=0, grad_width=2)
Expand All @@ -33,7 +33,7 @@
# MAKE THE RIGHT CLIP : cut, crop, add a mask

clip_right = main_clip.coreader().subclip(21,21+duration).\
fx( vfx.crop, x1=70, x2=70+2*W/3)
crop(x1=70, x2=70+2*W/3)

mask = color_split((2*W/3,H), p1=(2,H), p2=(W/3+2,0),
col1=0, col2=1, grad_width=2)
Expand All @@ -44,8 +44,8 @@

# ASSEMBLE AND WRITE THE MOVIE TO A FILE

cc = CompositeVideoClip([clip_right.set_pos('right').fx(afx.volumex, 0.4),
clip_left.set_pos('left').fx(afx.volumex, 0.4)],
cc = CompositeVideoClip([clip_right.set_pos('right').volumex(0.4),
clip_left.set_pos('left').volumex(0.4)],
size = (W,H))
#cc.preview()
cc.to_videofile("../../biphone3.avi",fps=24, codec='mpeg4')
2 changes: 1 addition & 1 deletion examples/headblur.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pickle

from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.tracking import manual_tracking, to_fxfy


Expand Down
4 changes: 2 additions & 2 deletions examples/masked_credits.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.credits import credits1

# Load the mountains clip, cut it, slow it down, make it look darker
clip = VideoFileClip('../../videos/badl-0001.mov', audio=False).\
subclip(37,46).\
fx( vfx.speedx, 0.4).\
speedx( 0.4).\
fx( vfx.colorx, 0.7)

# Save the first frame to later make a mask with GIMP (only once)
Expand Down
10 changes: 6 additions & 4 deletions examples/moving_letters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects

# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.
Expand All @@ -10,9 +10,11 @@
cvc = CompositeVideoClip( [txtClip.set_pos('center')],
size=screensize, transparent=True)

# WE DEFINE FOUR WAYS OF MOVING THE LETTERS
# THE NEXT FOUR FUNCTIONS DEFINE FOUR WAYS OF MOVING THE LETTERS

rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)],

# helper function
rotMatrix = lambda a: np.array( [[np.cos(a),np.sin(a)],
[-np.sin(a),np.cos(a)]] )

def vortex(screenpos,i,nletters):
Expand Down Expand Up @@ -41,7 +43,7 @@ def vortexout(screenpos,i,nletters):



# WE USE THE PLUGIN TO LOCATE AND SEPARATE EACH LETTER
# WE USE THE PLUGIN findObjects TO LOCATE AND SEPARATE EACH LETTER

letters = findObjects(cvc) # a list of ImageClips

Expand Down
11 changes: 7 additions & 4 deletions examples/painting_effect.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
""" requires scikit-image installed (for vfx.painting) """

from moviepy.all import *
from moviepy.editor import *

# WE TAKE THE SUBCLIPS WHICH ARE 2 SECONDS BEFORE & AFTER THE FREEZE

charade = VideoFileClip("../../videos/charade.mp4")
tfreeze = cvsecs(19,21) # Time of the freeze, 19'21

# when using several subclips of a same clip, it can be faster
# to create 'coreaders' of the clip (=other entrance points).
clip_before = charade.coreader().subclip(tfreeze -2,tfreeze)
clip_after = charade.coreader().subclip(tfreeze ,tfreeze +2)

Expand All @@ -22,8 +24,8 @@
painting_txt = CompositeVideoClip([painting,txt.set_pos((10,180))]).\
add_mask().\
set_duration(3).\
fx( transfx.crossfadein, 0.5).\
fx( transfx.crossfadeout, 0.5)
crossfadein( 0.5).\
crossfadeout( 0.5)

# FADEIN/FADEOUT EFFECT ON THE PAINTED IMAGE

Expand All @@ -35,4 +37,5 @@
painting_fading.set_duration(3),
clip_after])

final_clip.to_videofile('../../audrey.avi',fps=charade.fps, codec = "mpeg4", audio_bitrate="3000k")
final_clip.to_videofile('../../audrey.avi',fps=charade.fps,
codec = "mpeg4", audio_bitrate="3000k")
2 changes: 1 addition & 1 deletion examples/soundtrack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" A simple test script on how to put a soundtrack to a movie """
from moviepy.all import *
from moviepy.editor import *


# We load a movie and replace the sound with some music:
Expand Down
4 changes: 2 additions & 2 deletions examples/star_worms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from skimage import transform as tf

from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.drawing import color_gradient


Expand Down Expand Up @@ -135,7 +135,7 @@ def annotate(clip,txt,txt_color='white',bg_color=(0,0,255)):


def resizeCenter(clip):
return clip.fx( vfx.resize, height=h).set_pos('center')
return clip.resize( height=h).set_pos('center')


def composeCenter(clip):
Expand Down
2 changes: 1 addition & 1 deletion examples/the_end.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from moviepy.all import *
from moviepy.editor import *
from moviepy.video.tools.drawing import circle

clip = VideoFileClip("../../videos/badl-0006.mov", audio=False).\
Expand Down
10 changes: 5 additions & 5 deletions examples/ukulele_concerto.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from moviepy.all import *
from moviepy.editor import *

# UKULELE CLIP, OBTAINED BY CUTTING AND CROPPING
# RAW FOOTAGE

ukulele = VideoFileClip("../../videos/moi_ukulele.MOV", audio=False).\
subclip(60+33, 60+50).\
fx( vfx.crop, 486, 180, 1196, 570)
crop(486, 180, 1196, 570)

w,h = moviesize = ukulele.size

Expand All @@ -14,9 +14,9 @@

piano = (VideoFileClip("../../videos/douceamb.mp4",audio=False).
subclip(30,50).
fx( vfx.resize, (w/3,h/3)). # one third of the total screen
fx( vfx.margin, 6,color=(255,255,255)). #white margin
fx( vfx.margin, bottom=20, right=20, opacity=0). # transparent
resize((w/3,h/3)). # one third of the total screen
margin( 6,color=(255,255,255)). #white margin
margin( bottom=20, right=20, opacity=0). # transparent
set_pos(('right','bottom')) )


Expand Down
13 changes: 13 additions & 0 deletions moviepy/audio/fx/audio_left_right.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np

def audio_left_right(audioclip, left=1, right=1, merge=False):
"""
For a stereo audioclip, this function enables to change the volume
of the left and right channel separately (with the factors `left`
and `right`)
Makes a stereo audio clip in which the volume of left and right
is controlable
"""
funleft = (lambda t: left) if np.isscalar(left) else left
funright = (lambda t: right) if np.isscalar(right) else right

9 changes: 9 additions & 0 deletions moviepy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ def apply_to_audio(f, clip, *a, **k):
if hasattr(newclip, 'audio') and (newclip.audio != None):
newclip.audio = f(newclip.audio, *a, **k)
return newclip


@decorator.decorator
def add_mask_if_none(f, clip, *a, **k):
""" This decorator will apply the function f to the audio of
the clip created with f """
if clip.mask is None:
clip = clip.add_mask()
return f(clip, *a, **k)


@decorator.decorator
Expand Down
20 changes: 20 additions & 0 deletions moviepy/all.py → moviepy/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@
from moviepy.video.io.sliders import sliders
except:
pass

# The next loop transforms many effects into VideoClip methods so that
# they can be walled with myclip.resize(width=500) instead of
# myclip.fx( vfx.resize, width= 500)
for method in ["vfx.crop",
"vfx.resize",
"vfx.margin",
"vfx.fadein",
"vfx.fadeout",
"vfx.speedx",
"afx.volumex",
"afx.audio_fadein",
"afx.audio_fadeout",
"transfx.crossfadein",
"transfx.crossfadeout"]:
exec("VideoClip.%s = %s"%( method.split('.')[1], method))

VideoClip.crop = vfx.crop
VideoClip.resize = vfx.resize

2 changes: 1 addition & 1 deletion moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def on_color(self, size=None, color=(0, 0, 0), pos=None, col_opacity=None):
pos = 'center'
colorclip = ColorClip(size, color)
if col_opacity:
colorclip = colorclip.add_mask().set_opacity(col_opacity)
colorclip = colorclip.set_opacity(col_opacity)

return CompositeVideoClip([colorclip, self.set_pos(pos)],
transparent=(col_opacity != None))
Expand Down
10 changes: 6 additions & 4 deletions moviepy/video/compositing/transitions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Don't abuse transitions ! Here is the current catalogue. These are meant
to be used with clip.fx
Here is the current catalogue. These are meant
to be used with clip.fx. There are available as transfx.crossfadein etc.
if you load them with ``from moviepy.all import *``
"""

from moviepy.decorators import requires_duration

from moviepy.decorators import requires_duration, add_mask_if_none
from moviepy.video.fx import fadein, fadeout

@add_mask_if_none
def crossfadein(clip, duration):
"""
Makes the clip appear progressively, over ``duration`` seconds.
Expand All @@ -18,6 +19,7 @@ def crossfadein(clip, duration):


@requires_duration
@add_mask_if_none
def crossfadeout(clip, duration):
"""
Makes the clip disappear progressively, over ``duration`` seconds.
Expand Down
Loading

0 comments on commit a49b2fe

Please sign in to comment.