Skip to content

Commit

Permalink
More PEP8 compliance (#712)
Browse files Browse the repository at this point in the history
PEP 8
  • Loading branch information
tburrows13 authored Feb 12, 2018
1 parent 515bc8c commit db9e5f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
48 changes: 22 additions & 26 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from copy import copy
import numpy as np

from moviepy.decorators import ( apply_to_mask,
apply_to_audio,
requires_duration,
outplace,
convert_to_seconds,
use_clip_fps_by_default)
from moviepy.decorators import (apply_to_mask,
apply_to_audio,
requires_duration,
outplace,
convert_to_seconds,
use_clip_fps_by_default)
from tqdm import tqdm


class Clip:

"""
Expand Down Expand Up @@ -53,9 +54,7 @@ def __init__(self):

self.memoize = False
self.memoized_t = None
self.memoize_frame = None


self.memoize_frame = None

def copy(self):
""" Shallow copy of the clip.
Expand Down Expand Up @@ -148,13 +147,11 @@ def fl(self, fun, apply_to=None, keep_duration=True):
if hasattr(newclip, attr):
a = getattr(newclip, attr)
if a is not None:
new_a = a.fl(fun, keep_duration=keep_duration)
new_a = a.fl(fun, keep_duration=keep_duration)
setattr(newclip, attr, new_a)

return newclip



def fl_time(self, t_func, apply_to=None, keep_duration=False):
"""
Returns a Clip instance playing the content of the current clip
Expand Down Expand Up @@ -190,9 +187,7 @@ def fl_time(self, t_func, apply_to=None, keep_duration=False):
apply_to = []

return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
keep_duration=keep_duration)


keep_duration=keep_duration)

def fx(self, func, *args, **kwargs):
"""
Expand Down Expand Up @@ -246,7 +241,7 @@ def set_start(self, t, change_end=True):
self.start = t
if (self.duration is not None) and change_end:
self.end = t + self.duration
elif (self.end is not None):
elif self.end is not None:
self.duration = self.end - self.start


Expand Down Expand Up @@ -348,7 +343,7 @@ def is_playing(self, t):

# If we arrive here, a part of t falls in the clip
result = 1 * (t >= self.start)
if (self.end is not None):
if self.end is not None:
result *= (t <= self.end)
return result

Expand Down Expand Up @@ -384,14 +379,15 @@ def subclip(self, t_start=0, t_end=None):
they exist.
"""

if t_start < 0: #make this more python like a negative value
#means to move backward from the end of the clip
t_start = self.duration + t_start #remeber t_start is negative
if t_start < 0:
# Make this more Python-like, a negative value means to move
# backward from the end of the clip
t_start = self.duration + t_start # Remember t_start is negative

if (self.duration is not None) and (t_start>self.duration):
raise ValueError("t_start (%.02f) "%t_start +
if (self.duration is not None) and (t_start > self.duration):
raise ValueError("t_start (%.02f) "% t_start +
"should be smaller than the clip's "+
"duration (%.02f)."%self.duration)
"duration (%.02f)."% self.duration)

newclip = self.fl_time(lambda t: t + t_start, apply_to=[])

Expand All @@ -403,14 +399,14 @@ def subclip(self, t_start=0, t_end=None):

if self.duration is None:

print ("Error: subclip with negative times (here %s)"%(str((t_start, t_end)))
+" can only be extracted from clips with a ``duration``")
print("Error: subclip with negative times (here %s)" % (str((t_start, t_end)))
+ " can only be extracted from clips with a ``duration``")

else:

t_end = self.duration + t_end

if (t_end is not None):
if t_end is not None:

newclip.duration = t_end - t_start
newclip.end = newclip.start + newclip.duration
Expand Down
19 changes: 10 additions & 9 deletions moviepy/video/io/VideoFileClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from moviepy.Clip import Clip
from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader


class VideoFileClip(VideoClip):

"""
Expand All @@ -14,7 +15,7 @@ class VideoFileClip(VideoClip):
>>> clip = VideoFileClip("myHolidays.mp4")
>>> clip.close()
>>> with VideoFileClip("myMaskVideo.avi") as clip2:
>>> pass # Implicit close called by contex manager.
>>> pass # Implicit close called by context manager.
Parameters
Expand Down Expand Up @@ -75,15 +76,15 @@ class VideoFileClip(VideoClip):
"""

def __init__(self, filename, has_mask=False,
audio=True, audio_buffersize = 200000,
audio=True, audio_buffersize=200000,
target_resolution=None, resize_algorithm='bicubic',
audio_fps=44100, audio_nbytes=2, verbose=False,
fps_source='tbr'):

VideoClip.__init__(self)

# Make a reader
pix_fmt= "rgba" if has_mask else "rgb24"
pix_fmt = "rgba" if has_mask else "rgb24"
self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
target_resolution=target_resolution,
resize_algo=resize_algorithm,
Expand All @@ -102,9 +103,9 @@ def __init__(self, filename, has_mask=False,
if has_mask:

self.make_frame = lambda t: self.reader.get_frame(t)[:,:,:3]
mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0
self.mask = (VideoClip(ismask = True, make_frame = mask_mf)
.set_duration(self.duration))
mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0
self.mask = (VideoClip(ismask=True, make_frame=mask_mf)
.set_duration(self.duration))
self.mask.fps = self.fps

else:
Expand All @@ -115,9 +116,9 @@ def __init__(self, filename, has_mask=False,
if audio and self.reader.infos['audio_found']:

self.audio = AudioFileClip(filename,
buffersize= audio_buffersize,
fps = audio_fps,
nbytes = audio_nbytes)
buffersize=audio_buffersize,
fps=audio_fps,
nbytes=audio_nbytes)

def close(self):
""" Close the internal reader. """
Expand Down

0 comments on commit db9e5f8

Please sign in to comment.