Video editing with Python
Update 'headblur' example, add chaplin.mp4, fix copy exception (#1414)
Álvaro Mondéjard0a204a656f2
diff --git a/examples/headblur.py b/examples/headblur.pyindex 93db0927..142ccb9d 100644--- a/examples/headblur.py+++ b/examples/headblur.py@@ -1,34 +1,29 @@-import pickle-from moviepy.editor import *-from moviepy.video.tools.tracking import manual_tracking, to_fxfy+from moviepy.video.tools.tracking import manual_tracking+from moviepy.video.tools.interpolators import Trajectory# LOAD THE CLIP (subclip 6'51 - 7'01 of a chaplin movie)-clip = VideoFileClip("../../videos/chaplin.mp4").subclip((6, 51.7), (7, 01.3))+clip = VideoFileClip("media/chaplin.mp4")# MANUAL TRACKING OF THE HEAD-# the three next lines are for the manual tracking and its saving+# the next line is for the manual tracking and its saving# to a file, it must be commented once the tracking has been done# (after the first run of the script for instance).-# Note that we save the list (ti,xi,yi), not the functions fx and fy-# (that we will need) because they have dependencies.+# Note that we save the list (ti, xi, yi), not the functions fx and fy-# txy, (fx,fy) = manual_tracking(clip, fps=6)-# with open("../../chaplin_txy.dat",'w+') as f:-# pickle.dump(txy)+# manual_tracking(clip, fps=6, savefile="blurred_trajectory.txt")# IF THE MANUAL TRACKING HAS BEEN PREVIOUSLY DONE,-# LOAD THE TRACKING DATA AND CONVERT IT TO FUNCTIONS x(t),fy(t)+# LOAD THE TRACKING DATA AND CONVERT IT TO TRAJECTORY INTERPOLATORS fx(t), fy(t)-with open("../../chaplin_txy.dat", "r") as file:- fx, fy = to_fxfy(pickle.load(file))+traj = Trajectory.from_file("blurred_trajectory.txt")-# BLUR CHAPLIN'S HEAD IN THE CLIP+# BLUR CHAPLIN'S HEAD IN THE CLIP PASSING xi(t) and yi(t) FUNCTIONS-clip_blurred = clip.fx(vfx.headblur, fx, fy, 25)+clip_blurred = clip.fx(vfx.headblur, traj.xi, traj.yi, 25)# Generate the text, put in on a grey background@@ -52,4 +47,4 @@ final = concatenate_videoclips([clip_blurred, txt.with_duration(3)]).with_audio(# We write the result to a file. Here we raise the bitrate so that# the final video is not too ugly.-final.write_videofile("../../blurredChaplin.avi", bitrate="3000k")+final.write_videofile("blurredChaplin.mp4")diff --git a/media/chaplin.mp4 b/media/chaplin.mp4new file mode 100644index 00000000..e4d109c4Binary files /dev/null and b/media/chaplin.mp4 differdiff --git a/moviepy/video/fx/headblur.py b/moviepy/video/fx/headblur.pyindex 64f7b48d..a3f5552e 100644--- a/moviepy/video/fx/headblur.py+++ b/moviepy/video/fx/headblur.py@@ -24,11 +24,10 @@ def headblur(clip, fx, fy, radius, intensity=None):"""if intensity is None:- intensity = 2 * radius / 3+ intensity = int(2 * radius / 3)def filter(gf, t):-- im = gf(t)+ im = gf(t).copy()h, w, d = im.shapex, y = int(fx(t)), int(fy(t))x1, x2 = max(0, x - radius), min(x + radius, w)