Video editing with Python
Apply black
zalgo334516a6dccf8
diff --git a/moviepy/Clip.py b/moviepy/Clip.pyindex 69eb0d81..73ebdfad 100644--- a/moviepy/Clip.py+++ b/moviepy/Clip.py@@ -43,7 +43,6 @@ class Clip:_TEMP_FILES_PREFIX = "TEMP_MPY_"def __init__(self):-self.start = 0self.end = Noneself.duration = None@@ -375,7 +374,6 @@ class Clip:return resultelse:-return (t >= self.start) and ((self.end is None) or (t < self.end))@convert_parameter_to_seconds(["start_time", "end_time"])@@ -424,11 +422,9 @@ class Clip:new_clip = self.time_transform(lambda t: t + start_time, apply_to=[])if (end_time is None) and (self.duration is not None):-end_time = self.durationelif (end_time is not None) and (end_time < 0):-if self.duration is None:raise ValueError((@@ -439,11 +435,9 @@ class Clip:)else:-end_time = self.duration + end_timeif end_time is not None:-new_clip.duration = end_time - start_timenew_clip.end = new_clip.start + new_clip.durationdiff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.pyindex b3110984..e36cebde 100644--- a/moviepy/audio/AudioClip.py+++ b/moviepy/audio/AudioClip.py@@ -279,7 +279,6 @@ class AudioArrayClip(AudioClip):"""def __init__(self, array, fps):-Clip.__init__(self)self.array = arrayself.fps = fpsdiff --git a/moviepy/audio/io/AudioFileClip.py b/moviepy/audio/io/AudioFileClip.pyindex 4ab79b40..dd241f84 100644--- a/moviepy/audio/io/AudioFileClip.py+++ b/moviepy/audio/io/AudioFileClip.py@@ -57,7 +57,6 @@ class AudioFileClip(AudioClip):def __init__(self, filename, decode_file=False, buffersize=200000, nbytes=2, fps=44100):-AudioClip.__init__(self)self.filename = filenamediff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.pyindex c714c69d..4f60efb4 100644--- a/moviepy/audio/io/readers.py+++ b/moviepy/audio/io/readers.py@@ -216,7 +216,6 @@ class FFMPEG_AudioReader:return resultelse:-ind = int(self.fps * tt)if ind < 0 or ind > self.n_frames: # out of time: return 0return np.zeros(self.nchannels)diff --git a/moviepy/config.py b/moviepy/config.pyindex 90d9282d..1ba214f1 100644--- a/moviepy/config.py+++ b/moviepy/config.py@@ -44,7 +44,6 @@ if FFMPEG_BINARY == "ffmpeg-imageio":FFMPEG_BINARY = get_exe()elif FFMPEG_BINARY == "auto-detect":-if try_cmd(["ffmpeg"])[0]:FFMPEG_BINARY = "ffmpeg"elif not IS_POSIX_OS and try_cmd(["ffmpeg.exe"])[0]:diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 8b3a68e2..89af5c55 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -327,7 +327,6 @@ class VideoClip(Clip):logger = proglog.default_bar_logger(logger)if codec is None:-try:codec = extensions_dict[ext]["codec"][0]except KeyError:@@ -1048,7 +1047,6 @@ class ImageClip(VideoClip):img = imread(img)if len(img.shape) == 3: # img is (now) a RGB(a) numpy array-if img.shape[2] == 4:if fromalpha:img = 1.0 * img[:, :, 3] / 255@@ -1248,7 +1246,6 @@ class TextClip(ImageClip):remove_temp=True,print_cmd=False,):-if text is not None:if temptxt is None:temptxt_fd, temptxt = tempfile.mkstemp(suffix=".txt")diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.pyindex cb3c6b71..fec0b0d2 100644--- a/moviepy/video/compositing/CompositeVideoClip.py+++ b/moviepy/video/compositing/CompositeVideoClip.py@@ -54,7 +54,6 @@ class CompositeVideoClip(VideoClip):def __init__(self, clips, size=None, bg_color=None, use_bgclip=False, is_mask=False):-if size is None:size = clips[0].sizediff --git a/moviepy/video/fx/freeze_region.py b/moviepy/video/fx/freeze_region.pyindex 6726c4c0..a067ccfe 100644--- a/moviepy/video/fx/freeze_region.py+++ b/moviepy/video/fx/freeze_region.py@@ -29,7 +29,6 @@ def freeze_region(clip, t=0, region=None, outside_region=None, mask=None):"""if region is not None:-x1, y1, x2, y2 = regionfreeze = (clip.fx(crop, *region)@@ -40,7 +39,6 @@ def freeze_region(clip, t=0, region=None, outside_region=None, mask=None):return CompositeVideoClip([clip, freeze])elif outside_region is not None:-x1, y1, x2, y2 = outside_regionanimated_region = clip.fx(crop, *outside_region).with_position((x1, y1))freeze = clip.to_ImageClip(t=t).with_duration(clip.duration)diff --git a/moviepy/video/fx/resize.py b/moviepy/video/fx/resize.pyindex 843472cd..1476fbb7 100644--- a/moviepy/video/fx/resize.py+++ b/moviepy/video/fx/resize.py@@ -191,7 +191,6 @@ def resize(clip, new_size=None, height=None, width=None, apply_to_mask=True):new_size = translate_new_size(new_size)elif height is not None:-if hasattr(height, "__call__"):def func(t):@@ -203,7 +202,6 @@ def resize(clip, new_size=None, height=None, width=None, apply_to_mask=True):new_size = [w * height / h, height]elif width is not None:-if hasattr(width, "__call__"):def func(t):diff --git a/moviepy/video/io/ImageSequenceClip.py b/moviepy/video/io/ImageSequenceClip.pyindex fd939c49..930a6fef 100644--- a/moviepy/video/io/ImageSequenceClip.py+++ b/moviepy/video/io/ImageSequenceClip.py@@ -49,7 +49,6 @@ class ImageSequenceClip(VideoClip):is_mask=False,load_images=False,):-# CODE WRITTEN AS IT CAME, MAY BE IMPROVED IN THE FUTUREif (fps is None) and (durations is None):@@ -111,12 +110,10 @@ class ImageSequenceClip(VideoClip):)if fromfiles:-self.last_index = Noneself.last_image = Nonedef make_frame(t):-index = find_image_index(t)if index != self.last_index:@@ -126,13 +123,11 @@ class ImageSequenceClip(VideoClip):return self.last_imageif with_mask and (imread(self.sequence[0]).shape[2] == 4):-self.mask = VideoClip(is_mask=True)self.mask.last_index = Noneself.mask.last_image = Nonedef mask_make_frame(t):-index = find_image_index(t)if index != self.mask.last_index:frame = imread(self.sequence[index])[:, :, 3]@@ -147,12 +142,10 @@ class ImageSequenceClip(VideoClip):else:def make_frame(t):-index = find_image_index(t)return self.sequence[index][:, :, :3]if with_mask and (self.sequence[0].shape[2] == 4):-self.mask = VideoClip(is_mask=True)def mask_make_frame(t):diff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.pyindex 1be47cb4..f18cff61 100644--- a/moviepy/video/io/VideoFileClip.py+++ b/moviepy/video/io/VideoFileClip.py@@ -96,7 +96,6 @@ class VideoFileClip(VideoClip):fps_source="fps",pixel_format=None,):-VideoClip.__init__(self)# Make a reader@@ -122,7 +121,6 @@ class VideoFileClip(VideoClip):self.filename = filenameif has_mask:-self.make_frame = lambda t: self.reader.get_frame(t)[:, :, :3]def mask_make_frame(t):@@ -134,12 +132,10 @@ class VideoFileClip(VideoClip):self.mask.fps = self.fpselse:-self.make_frame = lambda t: self.reader.get_frame(t)# Make a reader for the audio, if any.if audio and self.reader.infos["audio_found"]:-self.audio = AudioFileClip(filename,buffersize=audio_buffersize,diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.pyindex 616deff6..b7be9717 100644--- a/moviepy/video/io/ffmpeg_reader.py+++ b/moviepy/video/io/ffmpeg_reader.py@@ -25,7 +25,6 @@ class FFMPEG_VideoReader:resize_algo="bicubic",fps_source="fps",):-self.filename = filenameself.proc = Noneinfos = ffmpeg_parse_infos(@@ -577,7 +576,6 @@ class FFmpegInfosParser:# not default audio found, assume first audio stream is the defaultif self.result["audio_found"] and not self.result.get("audio_bitrate"):-self.result["audio_bitrate"] = Nonefor streams_input in self.result["inputs"]:for stream in streams_input["streams"]:diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.pyindex cff303ad..827724cd 100644--- a/moviepy/video/io/ffmpeg_writer.py+++ b/moviepy/video/io/ffmpeg_writer.py@@ -190,14 +190,12 @@ class FFMPEG_VideoWriter:)elif "bitrate not specified" in ffmpeg_error:-error += ("\n\nThe video export failed, possibly because the bitrate ""specified was too high or too low for the video codec.")elif "Invalid encoder type" in ffmpeg_error:-error += ("\n\nThe video export failed because the codec ""or file extension you provided is not suitable for video"diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.pyindex b052bcec..f4240139 100644--- a/moviepy/video/io/gif_writers.py+++ b/moviepy/video/io/gif_writers.py@@ -101,7 +101,6 @@ def write_gif_with_tempfiles(logger(message="MoviePy - - Generating GIF frames")for i, t in logger.iter_bar(t=list(enumerate(tt))):-name = "%s_GIFTEMP%04d.png" % (file_root, i + 1)tempfiles.append(name)clip.save_frame(name, t, with_mask=True)@@ -167,7 +166,6 @@ def write_gif_with_tempfiles(logger(message="MoviePy - GIF ready: %s." % filename)except (IOError, OSError) as err:-error = ("MoviePy Error: creation of %s failed because ""of the following error:\n\n%s.\n\n." % (filename, str(err))@@ -335,7 +333,6 @@ def write_gif(**popen_params,)else:-popen_params["stdin"] = sp.PIPEpopen_params["stdout"] = sp.PIPE@@ -344,7 +341,6 @@ def write_gif()if program == "ImageMagick":-cmd2 = [IMAGEMAGICK_BINARY,"-delay",@@ -368,7 +364,6 @@ def write_gif(proc2 = sp.Popen(cmd2 + ["gif:-"], **popen_params)if opt:-cmd3 = ([IMAGEMAGICK_BINARY,@@ -399,7 +394,6 @@ def write_gif(proc1.stdin.write(frame.tobytes())except IOError as err:-error = ("[MoviePy] Error: creation of %s failed because ""of the following error:\n\n%s.\n\n." % (filename, str(err))@@ -450,5 +444,4 @@ def write_gif_with_image_io(logger(message="MoviePy - Building file %s with imageio." % filename)for frame in clip.iter_frames(fps=fps, logger=logger, dtype="uint8"):-writer.append_data(frame)diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.pyindex 30ac4c42..c936726f 100644--- a/moviepy/video/io/preview.py+++ b/moviepy/video/io/preview.py@@ -159,7 +159,6 @@ def preview(t0 = time.time()for t in np.arange(1.0 / fps, clip.duration - 0.001, 1.0 / fps):-img = clip.get_frame(t)for event in pg.event.get():diff --git a/moviepy/video/tools/cuts.py b/moviepy/video/tools/cuts.pyindex 40ff5fca..1bf4e6cc 100644--- a/moviepy/video/tools/cuts.py+++ b/moviepy/video/tools/cuts.py@@ -253,8 +253,7 @@ class FramesMatches(list):matching_frames = [] # the final result.- for (t, frame) in clip.iter_frames(with_times=True, logger=logger):-+ for t, frame in clip.iter_frames(with_times=True, logger=logger):flat_frame = 1.0 * frame.flatten()F_norm_sq = dot_product(flat_frame, flat_frame)F_norm = np.sqrt(F_norm_sq)@@ -359,7 +358,7 @@ class FramesMatches(list):nomatch_threshold = match_thresholddict_starts = defaultdict(lambda: [])- for (start, end, min_distance, max_distance) in self:+ for start, end, min_distance, max_distance in self:dict_starts[start].append([end, min_distance, max_distance])starts_ends = sorted(dict_starts.items(), key=lambda k: k[0])@@ -367,7 +366,6 @@ class FramesMatches(list):result = []min_start = 0for start, ends_distances in starts_ends:-if start < min_start:continue@@ -445,7 +443,7 @@ class FramesMatches(list):MoviePy - Building file foo/00000128_00000372.gif with imageio.MoviePy - Building file foo/00000140_00000360.gif with imageio."""- for (start, end, _, _) in self:+ for start, end, _, _ in self:name = "%s/%08d_%08d.gif" % (gifs_dir, 100 * start, 100 * end)clip.subclip(start, end).write_gif(name, **kwargs)diff --git a/moviepy/video/tools/interpolators.py b/moviepy/video/tools/interpolators.pyindex 83db3be3..268ad3a6 100644--- a/moviepy/video/tools/interpolators.py+++ b/moviepy/video/tools/interpolators.py@@ -38,7 +38,6 @@ class Interpolator:"""def __init__(self, tt=None, ss=None, ttss=None, left=None, right=None):-if ttss is not None:tt, ss = zip(*ttss)@@ -88,7 +87,6 @@ class Trajectory:"""def __init__(self, tt, xx, yy):-self.tt = 1.0 * np.array(tt)self.xx = np.array(xx)self.yy = np.array(yy)diff --git a/moviepy/video/tools/subtitles.py b/moviepy/video/tools/subtitles.pyindex b2a9b841..0b676d6e 100644--- a/moviepy/video/tools/subtitles.py+++ b/moviepy/video/tools/subtitles.py@@ -43,7 +43,6 @@ class SubtitlesClip(VideoClip):"""def __init__(self, subtitles, make_textclip=None, encoding=None):-VideoClip.__init__(self, has_constant_size=False)if not isinstance(subtitles, list):diff --git a/moviepy/video/tools/tracking.py b/moviepy/video/tools/tracking.pyindex 8546074b..ab0df233 100644--- a/moviepy/video/tools/tracking.py+++ b/moviepy/video/tools/tracking.py@@ -100,14 +100,11 @@ def manual_tracking(clip, t1=None, t2=None, fps=None, n_objects=1, savefile=Nonetxy_list = []def gatherClicks(t):-imdisplay(clip.get_frame(t), screen)objects_to_click = n_objectsclicks = []while objects_to_click:-for event in pg.event.get():-if event.type == pg.KEYDOWN:if event.key == pg.K_BACKSLASH:return "return"@@ -122,7 +119,6 @@ def manual_tracking(clip, t1=None, t2=None, fps=None, n_objects=1, savefile=Nonereturn clickswhile t < t2:-clicks = gatherClicks(t)if clicks == "return":txy_list.pop()diff --git a/tests/test_VideoFileClip.py b/tests/test_VideoFileClip.pyindex 3fca0ec6..e92f78e0 100644--- a/tests/test_VideoFileClip.py+++ b/tests/test_VideoFileClip.py@@ -37,7 +37,7 @@ def test_ffmpeg_resizing():for target_resolution in target_resolutions:video = VideoFileClip(video_file, target_resolution=target_resolution)frame = video.get_frame(0)- for (target, observed) in zip(target_resolution[::-1], frame.shape):+ for target, observed in zip(target_resolution[::-1], frame.shape):if target is not None:assert target == observedvideo.close()diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex e566bc55..f01127b7 100644--- a/tests/test_ffmpeg_reader.py+++ b/tests/test_ffmpeg_reader.py@@ -727,7 +727,6 @@ def test_failure_to_release_file(util):# Repeat this so we can see that the problems escalate:for i in range(5):-# Create a random video file.red = ColorClip((256, 200), color=(255, 0, 0))green = ColorClip((256, 200), color=(0, 255, 0))diff --git a/tests/test_ffmpeg_writer.py b/tests/test_ffmpeg_writer.pyindex 23025a2c..89ee48e9 100644--- a/tests/test_ffmpeg_writer.py+++ b/tests/test_ffmpeg_writer.py@@ -238,7 +238,6 @@ def test_write_gif(util, clip_class, opt, loop, with_mask, pixel_format):)if pixel_format != "invalid":-final_clip = VideoFileClip(filename)r, g, b = final_clip.get_frame(0)[0][0]diff --git a/tests/test_fx.py b/tests/test_fx.pyindex 23a646d9..0f499030 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -1486,7 +1486,6 @@ def test_audio_delay(stereo_wave, duration, offset, n_repeats, decay):decayments = np.linspace(1, max(0, decay), n_repeats)for i in range(n_repeats + 1): # first clip, is not part of the repeated ones-if i == n_repeats:# the delay ends in sound, so last muted chunk does not existsbreakdiff --git a/tests/test_issues.py b/tests/test_issues.pyindex 1abcedc6..449dc418 100644--- a/tests/test_issues.py+++ b/tests/test_issues.py@@ -245,7 +245,6 @@ def test_issue_334(util):def test_issue_354():with ImageClip("media/python_logo.png") as clip:-clip.duration = 10crosstime = 1diff --git a/tests/test_videotools.py b/tests/test_videotools.pyindex 8d126dbb..94ba0a7f 100644--- a/tests/test_videotools.py+++ b/tests/test_videotools.py@@ -654,7 +654,6 @@ def test_color_gradient(assert np.array_equal(result, expected_result)if shape == "radial":-circle_result = circle(size,p1,