Skip to content

Commit

Permalink
Apply black (#1923)
Browse files Browse the repository at this point in the history
Co-authored-by: zalgo3 <[email protected]>
See #1923
  • Loading branch information
keikoro authored Feb 22, 2023
1 parent 99a9657 commit 9ebabda
Show file tree
Hide file tree
Showing 25 changed files with 4 additions and 59 deletions.
6 changes: 0 additions & 6 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Clip:
_TEMP_FILES_PREFIX = "TEMP_MPY_"

def __init__(self):

self.start = 0
self.end = None
self.duration = None
Expand Down Expand Up @@ -375,7 +374,6 @@ def is_playing(self, t):
return result

else:

return (t >= self.start) and ((self.end is None) or (t < self.end))

@convert_parameter_to_seconds(["start_time", "end_time"])
Expand Down Expand Up @@ -424,11 +422,9 @@ def subclip(self, start_time=0, end_time=None):
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.duration

elif (end_time is not None) and (end_time < 0):

if self.duration is None:
raise ValueError(
(
Expand All @@ -439,11 +435,9 @@ def subclip(self, start_time=0, end_time=None):
)

else:

end_time = self.duration + end_time

if end_time is not None:

new_clip.duration = end_time - start_time
new_clip.end = new_clip.start + new_clip.duration

Expand Down
1 change: 0 additions & 1 deletion moviepy/audio/AudioClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ class AudioArrayClip(AudioClip):
"""

def __init__(self, array, fps):

Clip.__init__(self)
self.array = array
self.fps = fps
Expand Down
1 change: 0 additions & 1 deletion moviepy/audio/io/AudioFileClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = filename
Expand Down
1 change: 0 additions & 1 deletion moviepy/audio/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def get_frame(self, tt):
return result

else:

ind = int(self.fps * tt)
if ind < 0 or ind > self.n_frames: # out of time: return 0
return np.zeros(self.nchannels)
Expand Down
1 change: 0 additions & 1 deletion moviepy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def try_cmd(cmd):
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]:
Expand Down
3 changes: 0 additions & 3 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ def write_videofile(
logger = proglog.default_bar_logger(logger)

if codec is None:

try:
codec = extensions_dict[ext]["codec"][0]
except KeyError:
Expand Down Expand Up @@ -1044,7 +1043,6 @@ def __init__(
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
Expand Down Expand Up @@ -1244,7 +1242,6 @@ def __init__(
remove_temp=True,
print_cmd=False,
):

if text is not None:
if temptxt is None:
temptxt_fd, temptxt = tempfile.mkstemp(suffix=".txt")
Expand Down
1 change: 0 additions & 1 deletion moviepy/video/compositing/CompositeVideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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].size

Expand Down
2 changes: 0 additions & 2 deletions moviepy/video/fx/freeze_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = region
freeze = (
clip.fx(crop, *region)
Expand All @@ -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_region
animated_region = clip.fx(crop, *outside_region).with_position((x1, y1))
freeze = clip.to_ImageClip(t=t).with_duration(clip.duration)
Expand Down
2 changes: 0 additions & 2 deletions moviepy/video/fx/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def filter(get_frame, t):
new_size = translate_new_size(new_size)

elif height is not None:

if hasattr(height, "__call__"):

def func(t):
Expand All @@ -203,7 +202,6 @@ def func(t):
new_size = [w * height / h, height]

elif width is not None:

if hasattr(width, "__call__"):

def func(t):
Expand Down
7 changes: 0 additions & 7 deletions moviepy/video/io/ImageSequenceClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(
is_mask=False,
load_images=False,
):

# CODE WRITTEN AS IT CAME, MAY BE IMPROVED IN THE FUTURE

if (fps is None) and (durations is None):
Expand Down Expand Up @@ -111,12 +110,10 @@ def find_image_index(t):
)

if fromfiles:

self.last_index = None
self.last_image = None

def make_frame(t):

index = find_image_index(t)

if index != self.last_index:
Expand All @@ -126,13 +123,11 @@ def make_frame(t):
return self.last_image

if with_mask and (imread(self.sequence[0]).shape[2] == 4):

self.mask = VideoClip(is_mask=True)
self.mask.last_index = None
self.mask.last_image = None

def mask_make_frame(t):

index = find_image_index(t)
if index != self.mask.last_index:
frame = imread(self.sequence[index])[:, :, 3]
Expand All @@ -147,12 +142,10 @@ def mask_make_frame(t):
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):
Expand Down
4 changes: 0 additions & 4 deletions moviepy/video/io/VideoFileClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(
fps_source="fps",
pixel_format=None,
):

VideoClip.__init__(self)

# Make a reader
Expand All @@ -122,7 +121,6 @@ def __init__(
self.filename = filename

if has_mask:

self.make_frame = lambda t: self.reader.get_frame(t)[:, :, :3]

def mask_make_frame(t):
Expand All @@ -134,12 +132,10 @@ def mask_make_frame(t):
self.mask.fps = self.fps

else:

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,
Expand Down
2 changes: 0 additions & 2 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(
resize_algo="bicubic",
fps_source="fps",
):

self.filename = filename
self.proc = None
infos = ffmpeg_parse_infos(
Expand Down Expand Up @@ -577,7 +576,6 @@ def parse(self):

# not default audio found, assume first audio stream is the default
if self.result["audio_found"] and not self.result.get("audio_bitrate"):

self.result["audio_bitrate"] = None
for streams_input in self.result["inputs"]:
for stream in streams_input["streams"]:
Expand Down
2 changes: 0 additions & 2 deletions moviepy/video/io/ffmpeg_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,12 @@ def write_frame(self, img_array):
)

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"
Expand Down
7 changes: 0 additions & 7 deletions moviepy/video/io/gif_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -335,7 +333,6 @@ def write_gif(
**popen_params,
)
else:

popen_params["stdin"] = sp.PIPE
popen_params["stdout"] = sp.PIPE

Expand All @@ -344,7 +341,6 @@ def write_gif(
)

if program == "ImageMagick":

cmd2 = [
IMAGEMAGICK_BINARY,
"-delay",
Expand All @@ -368,7 +364,6 @@ def write_gif(
proc2 = sp.Popen(cmd2 + ["gif:-"], **popen_params)

if opt:

cmd3 = (
[
IMAGEMAGICK_BINARY,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
1 change: 0 additions & 1 deletion moviepy/video/io/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 3 additions & 5 deletions moviepy/video/tools/cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ def distance(t1, t2):

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)
Expand Down Expand Up @@ -359,15 +358,14 @@ def select_scenes(
nomatch_threshold = match_threshold

dict_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])

result = []
min_start = 0
for start, ends_distances in starts_ends:

if start < min_start:
continue

Expand Down Expand Up @@ -445,7 +443,7 @@ def write_gifs(self, clip, gifs_dir, **kwargs):
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)

Expand Down
2 changes: 0 additions & 2 deletions moviepy/video/tools/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion moviepy/video/tools/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions moviepy/video/tools/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ def manual_tracking(clip, t1=None, t2=None, fps=None, n_objects=1, savefile=None
txy_list = []

def gatherClicks(t):

imdisplay(clip.get_frame(t), screen)
objects_to_click = n_objects
clicks = []
while objects_to_click:

for event in pg.event.get():

if event.type == pg.KEYDOWN:
if event.key == pg.K_BACKSLASH:
return "return"
Expand All @@ -122,7 +119,6 @@ def gatherClicks(t):
return clicks

while t < t2:

clicks = gatherClicks(t)
if clicks == "return":
txy_list.pop()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_VideoFileClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == observed
video.close()
Expand Down
Loading

0 comments on commit 9ebabda

Please sign in to comment.