Skip to content

Video editing with Python

Flake8 formatting cleanup (#1151)

Tom Burrows8d14ef94b384
diff --git a/.travis.yml b/.travis.yml
index 045243ee..a076c0f4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,7 +21,7 @@ before_install:
- pip install --upgrade pytest-cov
- pip install flake8
- # modify ImageMagick policy file so that Textclips work correctly.
+ # Modify ImageMagick policy file so that Textclips work correctly.
# `| sudo tee` replaces `>` so that it can have root permissions
- cat /etc/ImageMagick-6/policy.xml | sed 's/none/read,write/g' | sudo tee /etc/ImageMagick-6/policy.xml
@@ -29,10 +29,23 @@ install:
- pip install .[test]
before_script:
- # stop the build if there are Python syntax errors or undefined names
- - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics --exit-zero
- # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- - flake8 . --count --max-complexity=10 --max-line-length=127 --statistics --exit-zero
+ # Stop the build if there are Python syntax errors or undefined names
+ - flake8 . --count --select=E901,E999,F821,F822,F823,W605 --show-source --statistics
+ # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide.
+ # Some warning codes are ignored because they conflict with black's formatting, or are
+ # incompatible with MoviePy's structure
+ # E203: whitespace before ':'
+ # E302: expected 2 blank lines, found 0
+ # E402: module level import not at top of file
+ # W291: trailing whitespace
+ # W293: blank line contains whitespace
+ # W503: line break before binary operator
+ - flake8 moviepy --ignore=E203,E302,E402,W291,W293,W503 --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero
+ # Check examples and tests with slightly relaxed rules to allow 'star' imports
+ # F403 'from moviepy.editor import *' used; unable to detect undefined names
+ # F405 'name' may be undefined, or defined from star imports: moviepy.editor
+ - flake8 . --ignore=E203,E302,E402,W291,W293,W503,F403,F405 --exclude moviepy/ --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero
+
script:
- pytest tests/ --doctest-modules -v --cov moviepy --cov-report term-missing
diff --git a/docs/conf.py b/docs/conf.py
index d04c0e2f..f822fb66 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -189,11 +189,11 @@ htmlhelp_basename = "MoviePydoc"
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
- #'papersize': 'letterpaper',
+ # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
- #'pointsize': '10pt',
+ # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
- #'preamble': '',
+ # 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
diff --git a/ez_setup.py b/ez_setup.py
index 29bbd6d0..704f6ea1 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -13,14 +13,13 @@ the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
+import optparse
import os
import shutil
+import subprocess
import sys
-import tempfile
import tarfile
-import optparse
-import subprocess
-
+import tempfile
from distutils import log
try:
diff --git a/find_latest_imagemagick_version.py b/find_latest_imagemagick_version.py
index 0d0f8904..0cafba98 100644
--- a/find_latest_imagemagick_version.py
+++ b/find_latest_imagemagick_version.py
@@ -1,5 +1,5 @@
-from urllib import request
import re
+from urllib import request
url = "https://legacy.imagemagick.org/script/index.php"
@@ -10,8 +10,8 @@ git repository
"""
response = request.urlopen(url)
-html = response.read().decode("utf-8")
-r = re.compile("6\.9\.[0-9]+\-[0-9]+")
+html = response.read().decode(r"utf-8")
+r = re.compile(r"6\.9\.[0-9]+-[0-9]+")
version = r.findall(html)
if len(version) == 0:
raise ValueError(
diff --git a/moviepy/Clip.py b/moviepy/Clip.py
index 51ec1397..7e7483a0 100644
--- a/moviepy/Clip.py
+++ b/moviepy/Clip.py
@@ -427,8 +427,7 @@ class Clip:
if they exist.
"""
- fl = lambda t: t + (t >= ta) * (tb - ta)
- newclip = self.fl_time(fl)
+ newclip = self.fl_time(lambda t: t + (t >= ta) * (tb - ta))
if self.duration is not None:
diff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.py
index a15624a8..a2ee0c11 100644
--- a/moviepy/audio/AudioClip.py
+++ b/moviepy/audio/AudioClip.py
@@ -5,7 +5,7 @@ import proglog
from moviepy.audio.io.ffmpeg_audiowriter import ffmpeg_audiowrite
from moviepy.Clip import Clip
-from moviepy.decorators import requires_duration, convert_path_to_string
+from moviepy.decorators import convert_path_to_string, requires_duration
from moviepy.tools import extensions_dict
@@ -289,7 +289,6 @@ class AudioArrayClip(AudioClip):
class CompositeAudioClip(AudioClip):
-
""" Clip made by composing several AudioClips.
An audio clip made by putting together several audio clips.
diff --git a/moviepy/audio/fx/audio_loop.py b/moviepy/audio/fx/audio_loop.py
index ec4add87..10b862ab 100644
--- a/moviepy/audio/fx/audio_loop.py
+++ b/moviepy/audio/fx/audio_loop.py
@@ -9,7 +9,7 @@ def audio_loop(audioclip, nloops=None, duration=None):
Examples
========
-
+
>>> from moviepy.editor import *
>>> videoclip = VideoFileClip('myvideo.mp4')
>>> music = AudioFileClip('music.ogg')
diff --git a/moviepy/audio/io/preview.py b/moviepy/audio/io/preview.py
index 5376e0ed..170d21e3 100644
--- a/moviepy/audio/io/preview.py
+++ b/moviepy/audio/io/preview.py
@@ -13,30 +13,30 @@ pg.display.set_caption("MoviePy")
def preview(clip, fps=22050, buffersize=4000, nbytes=2, audioFlag=None, videoFlag=None):
"""
Plays the sound clip with pygame.
-
+
Parameters
-----------
-
+
fps
Frame rate of the sound. 44100 gives top quality, but may cause
problems if your computer is not fast enough and your clip is
complicated. If the sound jumps during the preview, lower it
(11025 is still fine, 5000 is tolerable).
-
+
buffersize
The sound is not generated all at once, but rather made by bunches
of frames (chunks). ``buffersize`` is the size of such a chunk.
Try varying it if you meet audio problems (but you shouldn't
have to).
-
+
nbytes:
Number of bytes to encode the sound: 1 for 8bit sound, 2 for
16bit, 4 for 32bit sound. 2 bytes is fine.
-
+
audioFlag, videoFlag:
Instances of class threading events that are used to synchronize
video and audio during ``VideoClip.preview()``.
-
+
"""
pg.mixer.quit()
diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.py
index 304af72b..6c1ae3bb 100644
--- a/moviepy/audio/io/readers.py
+++ b/moviepy/audio/io/readers.py
@@ -162,8 +162,6 @@ class FFMPEG_AudioReader:
self.proc = None
def get_frame(self, tt):
-
- buffersize = self.buffersize
if isinstance(tt, np.ndarray):
# lazy implementation, but should not cause problems in
# 99.99 % of the cases
diff --git a/moviepy/config.py b/moviepy/config.py
index 13d6e92f..98488d9c 100644
--- a/moviepy/config.py
+++ b/moviepy/config.py
@@ -50,7 +50,7 @@ if IMAGEMAGICK_BINARY == "auto-detect":
key = wr.OpenKey(wr.HKEY_LOCAL_MACHINE, "SOFTWARE\\ImageMagick\\Current")
IMAGEMAGICK_BINARY = wr.QueryValueEx(key, "BinPath")[0] + r"\convert.exe"
key.Close()
- except:
+ except Exception:
IMAGEMAGICK_BINARY = "unset"
elif try_cmd(["convert"])[0]:
IMAGEMAGICK_BINARY = "convert"
diff --git a/moviepy/config_defaults.py b/moviepy/config_defaults.py
index 71d8e6f8..248f710c 100644
--- a/moviepy/config_defaults.py
+++ b/moviepy/config_defaults.py
@@ -1,4 +1,4 @@
-"""
+r"""
Configuration of MoviePy
diff --git a/moviepy/utils.py b/moviepy/utils.py
index 0a596272..24327637 100644
--- a/moviepy/utils.py
+++ b/moviepy/utils.py
@@ -2,7 +2,6 @@ from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ImageClip
-
CLIP_TYPES = {
"audio": AudioFileClip,
"video": VideoFileClip,
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 4444a117..2355030e 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -7,7 +7,6 @@ main subclasses:
import os
import subprocess as sp
import tempfile
-import warnings
import numpy as np
import proglog
@@ -19,17 +18,13 @@ from moviepy.decorators import (
add_mask_if_none,
apply_to_mask,
convert_masks_to_RGB,
+ convert_path_to_string,
convert_to_seconds,
outplace,
requires_duration,
use_clip_fps_by_default,
- convert_path_to_string,
-)
-from moviepy.tools import (
- extensions_dict,
- find_extension,
- subprocess_call,
)
+from moviepy.tools import extensions_dict, find_extension, subprocess_call
from moviepy.video.io.ffmpeg_writer import ffmpeg_write_video
from moviepy.video.io.gif_writers import (
write_gif,
@@ -301,7 +296,7 @@ class VideoClip(Clip):
audiofile = audio if isinstance(audio, str) else None
make_audio = (
- (audiofile is None) and (audio == True) and (self.audio is not None)
+ (audiofile is None) and (audio is True) and (self.audio is not None)
)
if make_audio and temp_audiofile:
@@ -642,7 +637,10 @@ class VideoClip(Clip):
mask = ColorClip(self.size, 1.0, ismask=True)
return self.set_mask(mask.set_duration(self.duration))
else:
- make_frame = lambda t: np.ones(self.get_frame(t).shape[:2], dtype=float)
+
+ def make_frame(t):
+ return np.ones(self.get_frame(t).shape[:2], dtype=float)
+
mask = VideoClip(ismask=True, make_frame=make_frame)
return self.set_mask(mask.set_duration(self.duration))
@@ -798,8 +796,9 @@ class VideoClip(Clip):
def to_RGB(self):
"""Return a non-mask video clip made from the mask video clip."""
if self.ismask:
- f = lambda pic: np.dstack(3 * [255 * pic]).astype("uint8")
- newclip = self.fl_image(f)
+ newclip = self.fl_image(
+ lambda pic: np.dstack(3 * [255 * pic]).astype("uint8")
+ )
newclip.ismask = False
return newclip
else:
@@ -851,7 +850,10 @@ class DataVideoClip(VideoClip):
self.data = data
self.data_to_frame = data_to_frame
self.fps = fps
- make_frame = lambda t: self.data_to_frame(self.data[int(self.fps * t)])
+
+ def make_frame(t):
+ return self.data_to_frame(self.data[int(self.fps * t)])
+
VideoClip.__init__(
self,
make_frame,
diff --git a/moviepy/video/compositing/concatenate.py b/moviepy/video/compositing/concatenate.py
index e3c99736..ee15a2d2 100644
--- a/moviepy/video/compositing/concatenate.py
+++ b/moviepy/video/compositing/concatenate.py
@@ -1,6 +1,7 @@
-import numpy as np
from functools import reduce
+import numpy as np
+
from moviepy.audio.AudioClip import CompositeAudioClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.VideoClip import ColorClip, VideoClip
@@ -59,8 +60,8 @@ def concatenate_videoclips(
"""
if transition is not None:
- l = [[v, transition] for v in clips[:-1]]
- clips = reduce(lambda x, y: x + y, l) + [clips[-1]]
+ clip_transition_pairs = [[v, transition] for v in clips[:-1]]
+ clips = reduce(lambda x, y: x + y, clip_transition_pairs) + [clips[-1]]
transition = None
tt = np.cumsum([0] + [c.duration for c in clips])
diff --git a/moviepy/video/fx/accel_decel.py b/moviepy/video/fx/accel_decel.py
index 955b46b5..75d85526 100644
--- a/moviepy/video/fx/accel_decel.py
+++ b/moviepy/video/fx/accel_decel.py
@@ -1,4 +1,4 @@
-def f_accel_decel(t, old_d, new_d, abruptness=1, soonness=1.0):
+def f_accel_decel(t, old_d, new_d, abruptness=1.0, soonness=1.0):
"""
abruptness
negative abruptness (>-1): speed up down up
@@ -13,8 +13,12 @@ def f_accel_decel(t, old_d, new_d, abruptness=1, soonness=1.0):
a = 1.0 + abruptness
def _f(t):
- f1 = lambda t: (0.5) ** (1 - a) * (t ** a)
- f2 = lambda t: (1 - f1(1 - t))
+ def f1(t):
+ return (0.5) ** (1 - a) * (t ** a)
+
+ def f2(t):
+ return 1 - f1(1 - t)
+
return (t < 0.5) * f1(t) + (t >= 0.5) * f2(t)
return old_d * _f((t / new_d) ** soonness)
@@ -39,6 +43,6 @@ def accel_decel(clip, new_duration=None, abruptness=1.0, soonness=1.0):
if new_duration is None:
new_duration = clip.duration
- fl = lambda t: f_accel_decel(t, clip.duration, new_duration, abruptness, soonness)
-
- return clip.fl_time(fl).set_duration(new_duration)
+ return clip.fl_time(
+ lambda t: f_accel_decel(t, clip.duration, new_duration, abruptness, soonness)
+ ).set_duration(new_duration)
diff --git a/moviepy/video/fx/even_size.py b/moviepy/video/fx/even_size.py
index 99812595..ae5274f6 100644
--- a/moviepy/video/fx/even_size.py
+++ b/moviepy/video/fx/even_size.py
@@ -13,10 +13,18 @@ def even_size(clip):
return clip
if not w_even and not h_even:
- fl_image = lambda a: a[:-1, :-1, :]
+
+ def fl_image(a):
+ return a[:-1, :-1, :]
+
elif w_even:
- fl_image = lambda a: a[:, :-1, :]
+
+ def fl_image(a):
+ return a[:, :-1, :]
+
else:
- fl_image = lambda a: a[:-1, :, :]
+
+ def fl_image(a):
+ return a[:-1, :, :]
return clip.fl_image(fl_image)
diff --git a/moviepy/video/fx/headblur.py b/moviepy/video/fx/headblur.py
index e1e31412..3726148a 100644
--- a/moviepy/video/fx/headblur.py
+++ b/moviepy/video/fx/headblur.py
@@ -7,7 +7,7 @@ try:
headblur_possible = True
if cv2.__version__ >= "3.0.0":
cv2.CV_AA = cv2.LINE_AA
-except:
+except Exception:
headblur_possible = False
# -----------------------------------------------------------------------
diff --git a/moviepy/video/fx/painting.py b/moviepy/video/fx/painting.py
index 538618f1..d0053d1b 100644
--- a/moviepy/video/fx/painting.py
+++ b/moviepy/video/fx/painting.py
@@ -2,10 +2,10 @@
painting_possible = True
try:
from skimage.filter import sobel
-except:
+except Exception:
try:
from scipy.ndimage.filters import sobel
- except:
+ except Exception:
painting_possible = False
# -----------------------------------------------------------------------
diff --git a/moviepy/video/fx/resize.py b/moviepy/video/fx/resize.py
index bb7b178f..3bdcfdcb 100644
--- a/moviepy/video/fx/resize.py
+++ b/moviepy/video/fx/resize.py
@@ -46,16 +46,15 @@ except ImportError:
try:
from scipy.misc import imresize
- resizer = lambda pic, newsize: imresize(pic, map(int, newsize[::-1]))
+ def resizer(pic, newsize):
+ return imresize(pic, map(int, newsize[::-1]))
+
resizer.origin = "Scipy"
except ImportError:
resize_possible = False
-from moviepy.decorators import apply_to_mask
-
-
def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True):
"""
Returns a video clip that is a resized version of the clip.
@@ -100,16 +99,20 @@ def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True):
if hasattr(newsize, "__call__"):
- newsize2 = lambda t: trans_newsize(newsize(t))
+ def newsize2(t):
+ return trans_newsize(newsize(t))
if clip.ismask:
- fun = lambda gf, t: (
- 1.0 * resizer((255 * gf(t)).astype("uint8"), newsize2(t)) / 255
- )
+ def fun(gf, t):
+ return (
+ 1.0 * resizer((255 * gf(t)).astype("uint8"), newsize2(t)) / 255
+ )
+
else:
- fun = lambda gf, t: resizer(gf(t).astype("uint8"), newsize2(t))
+ def fun(gf, t):
+ return resizer(gf(t).astype("uint8"), newsize2(t))
return clip.fl(
fun, keep_duration=True, apply_to=(["mask"] if apply_to_mask else [])
@@ -122,7 +125,10 @@ def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True):
elif height is not None:
if hasattr(height, "__call__"):
- fun = lambda t: 1.0 * int(height(t)) / h
+
+ def fun(t):
+ return 1.0 * int(height(t)) / h
+
return resize(clip, fun)
else:
@@ -132,7 +138,10 @@ def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True):
elif width is not None:
if hasattr(width, "__call__"):
- fun = lambda t: 1.0 * width(t) / w
+
+ def fun(t):
+ return 1.0 * width(t) / w
+
return resize(clip, fun)
newsize = [width, h * width / w]
@@ -140,10 +149,14 @@ def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True):
# From here, the resizing is constant (not a function of time), size=newsize
if clip.ismask:
- fl = lambda pic: 1.0 * resizer((255 * pic).astype("uint8"), newsize) / 255.0
+
+ def fl(pic):
+ return 1.0 * resizer((255 * pic).astype("uint8"), newsize) / 255.0
else:
- fl = lambda pic: resizer(pic.astype("uint8"), newsize)
+
+ def fl(pic):
+ return resizer(pic.astype("uint8"), newsize)
newclip = clip.fl_image(fl)
diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.py
index 3aeddba3..51c36c34 100644
--- a/moviepy/video/fx/rotate.py
+++ b/moviepy/video/fx/rotate.py
@@ -56,7 +56,9 @@ def rotate(clip, angle, unit="deg", resample="bicubic", expand=True):
if not hasattr(angle, "__call__"):
# if angle is a constant, convert to a constant function
a = +angle
- angle = lambda t: a
+
+ def angle(t):
+ return a
transpo = [1, 0] if clip.ismask else [1, 0, 2]
diff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.py
index db9b9a00..5a331a86 100644
--- a/moviepy/video/io/VideoFileClip.py
+++ b/moviepy/video/io/VideoFileClip.py
@@ -1,7 +1,4 @@
-import os
-
from moviepy.audio.io.AudioFileClip import AudioFileClip
-from moviepy.Clip import Clip
from moviepy.decorators import convert_path_to_string
from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader
from moviepy.video.VideoClip import VideoClip
@@ -116,7 +113,10 @@ class VideoFileClip(VideoClip):
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
+
+ def mask_mf(t):
+ return self.reader.get_frame(t)[:, :, 3] / 255.0
+
self.mask = VideoClip(ismask=True, make_frame=mask_mf).set_duration(
self.duration
)
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index 0fe7f34b..d4aa2a2e 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -310,7 +310,7 @@ def ffmpeg_parse_infos(
line = [l for l in lines if keyword in l][index]
match = re.findall("([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])", line)[0]
result["duration"] = cvsecs(match)
- except:
+ except Exception:
raise IOError(
(
"MoviePy error: failed to read the duration of file %s.\n"
@@ -320,7 +320,7 @@ def ffmpeg_parse_infos(
)
# get the output line that speaks about video
- lines_video = [l for l in lines if " Video: " in l and re.search("\d+x\d+", l)]
+ lines_video = [l for l in lines if " Video: " in l and re.search(r"\d+x\d+", l)]
result["video_found"] = lines_video != []
@@ -332,7 +332,7 @@ def ffmpeg_parse_infos(
match = re.search(" [0-9]*x[0-9]*(,| )", line)
s = list(map(int, line[match.start() : match.end() - 1].split("x")))
result["video_size"] = s
- except:
+ except Exception:
raise IOError(
(
"MoviePy error: failed to read video dimensions in file %s.\n"
@@ -368,13 +368,13 @@ def ffmpeg_parse_infos(
if fps_source == "tbr":
try:
result["video_fps"] = get_tbr()
- except:
+ except Exception:
result["video_fps"] = get_fps()
elif fps_source == "fps":
try:
result["video_fps"] = get_fps()
- except:
+ except Exception:
result["video_fps"] = get_tbr()
# It is known that a fps of 24 is often written as 24000/1001
@@ -398,17 +398,17 @@ def ffmpeg_parse_infos(
# get the video rotation info.
try:
rotation_lines = [
- l for l in lines if "rotate :" in l and re.search("\d+$", l)
+ l for l in lines if "rotate :" in l and re.search(r"\d+$", l)
]
if len(rotation_lines):
rotation_line = rotation_lines[0]
- match = re.search("\d+$", rotation_line)
+ match = re.search(r"\d+$", rotation_line)
result["video_rotation"] = int(
rotation_line[match.start() : match.end()]
)
else:
result["video_rotation"] = 0
- except:
+ except Exception:
raise IOError(
(
"MoviePy error: failed to read video rotation in file %s.\n"
@@ -429,7 +429,7 @@ def ffmpeg_parse_infos(
match.start() + 1 : match.end() - 3
] # Removes the 'hz' from the end
result["audio_fps"] = int(hz_string)
- except:
+ except Exception:
result["audio_fps"] = "unknown"
return result
diff --git a/moviepy/video/io/ffmpeg_tools.py b/moviepy/video/io/ffmpeg_tools.py
index 29806f37..b5b78866 100644
--- a/moviepy/video/io/ffmpeg_tools.py
+++ b/moviepy/video/io/ffmpeg_tools.py
@@ -1,8 +1,6 @@
""" Misc. bindings to ffmpeg and ImageMagick."""
import os
-import subprocess as sp
-import sys
from moviepy.config import get_setting
from moviepy.decorators import convert_path_to_string
diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.py
index 13ab5b20..0ef4c5b7 100644
--- a/moviepy/video/io/ffmpeg_writer.py
+++ b/moviepy/video/io/ffmpeg_writer.py
@@ -108,9 +108,7 @@ class FFMPEG_VideoWriter:
]
if audiofile is not None:
cmd.extend(["-i", audiofile, "-acodec", "copy"])
- cmd.extend(
- ["-vcodec", codec, "-preset", preset,]
- )
+ cmd.extend(["-vcodec", codec, "-preset", preset])
if ffmpeg_params is not None:
cmd.extend(ffmpeg_params)
if bitrate is not None:
diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.py
index e8761578..2992b55c 100644
--- a/moviepy/video/io/html_tools.py
+++ b/moviepy/video/io/html_tools.py
@@ -146,7 +146,7 @@ def html_embed(
allowed_exts = " ".join(exts_htmltype.keys())
try:
ext = exts_htmltype[ext]
- except:
+ except Exception:
raise ValueError(
"This video extension cannot be displayed in the "
"IPython Notebook. Allowed extensions: " + allowed_exts
diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.py
index 846f762d..652c0b82 100644
--- a/moviepy/video/io/preview.py
+++ b/moviepy/video/io/preview.py
@@ -80,23 +80,23 @@ def preview(
than normal, but it cannot avoid the clip to be played slower
than normal if the computations are complex. In this case, try
reducing the ``fps``.
-
+
Parameters
------------
-
+
fps
Number of frames per seconds in the displayed video.
-
+
audio
``True`` (default) if you want the clip's audio be played during
the preview.
-
+
audio_fps
The frames per second to use when generating the audio sound.
-
+
fullscreen
``True`` if you want the preview to be displayed fullscreen.
-
+
"""
if fullscreen:
flags = pg.FULLSCREEN
diff --git a/moviepy/video/io/sliders.py b/moviepy/video/io/sliders.py
index f83bfd05..3a388ea5 100644
--- a/moviepy/video/io/sliders.py
+++ b/moviepy/video/io/sliders.py
@@ -1,5 +1,5 @@
import matplotlib.pyplot as plt
-from matplotlib.widgets import Button, Slider
+from matplotlib.widgets import Slider
def sliders(f, sliders_properties, wait_for_validation=False):
@@ -55,7 +55,7 @@ def sliders(f, sliders_properties, wait_for_validation=False):
print(res)
def on_key_press(event):
- if event.key is "enter":
+ if event.key == "enter":
on_changed(event)
figure.canvas.mpl_connect("key_press_event", on_key_press)
diff --git a/moviepy/video/tools/cuts.py b/moviepy/video/tools/cuts.py
index 066d2e36..1eae98bc 100644
--- a/moviepy/video/tools/cuts.py
+++ b/moviepy/video/tools/cuts.py
@@ -12,7 +12,9 @@ from moviepy.decorators import use_clip_fps_by_default
def find_video_period(clip, fps=None, tmin=0.3):
""" Finds the period of a video based on frames correlation """
- frame = lambda t: clip.get_frame(t).flatten()
+ def frame(t):
+ return clip.get_frame(t).flatten()
+
tt = np.arange(tmin, clip.duration, 1.0 / fps)[1:]
ref = frame(0)
corrs = [np.corrcoef(ref, frame(t))[0, 1] for t in tt]
@@ -148,7 +150,10 @@ class FramesMatches(list):
"""
N_pixels = clip.w * clip.h * 3
- dot_product = lambda F1, F2: (F1 * F2).sum() / N_pixels
+
+ def dot_product(F1, F2):
+ return (F1 * F2).sum() / N_pixels
+
F = {} # will store the frames and their mutual distances
def distance(t1, t2):
diff --git a/moviepy/video/tools/segmenting.py b/moviepy/video/tools/segmenting.py
index 8ddea0ac..41260753 100644
--- a/moviepy/video/tools/segmenting.py
+++ b/moviepy/video/tools/segmenting.py
@@ -1,6 +1,6 @@
import numpy as np
-
import scipy.ndimage as ndi
+
from moviepy.video.VideoClip import ImageClip
diff --git a/moviepy/video/tools/subtitles.py b/moviepy/video/tools/subtitles.py
index 9ec857d7..fad32005 100644
--- a/moviepy/video/tools/subtitles.py
+++ b/moviepy/video/tools/subtitles.py
@@ -53,14 +53,16 @@ class SubtitlesClip(VideoClip):
self.textclips = dict()
if make_textclip is None:
- make_textclip = lambda txt: TextClip(
- txt,
- font="Georgia-Bold",
- fontsize=24,
- color="white",
- stroke_color="black",
- stroke_width=0.5,
- )
+
+ def make_textclip(txt):
+ return TextClip(
+ txt,
+ font="Georgia-Bold",
+ fontsize=24,
+ color="white",
+ stroke_color="black",
+ stroke_width=0.5,
+ )
self.make_textclip = make_textclip
self.start = 0
@@ -110,13 +112,13 @@ class SubtitlesClip(VideoClip):
def is_in_subclip(t1, t2):
try:
return (t_start <= t1 < t_end) or (t_start < t2 <= t_end)
- except:
+ except Exception:
return False
def try_cropping(t1, t2):
try:
return (max(t1, t_start), min(t2, t_end))
- except:
+ except Exception:
return (t1, t2)
return [
diff --git a/moviepy/video/tools/tracking.py b/moviepy/video/tools/tracking.py
index 5c1aff48..64723aeb 100644
--- a/moviepy/video/tools/tracking.py
+++ b/moviepy/video/tools/tracking.py
@@ -19,7 +19,7 @@ try:
import cv2
autotracking_possible = True
-except:
+except Exception:
# Note: this will be later fixed with scipy/skimage replacements
# but for the moment OpenCV is mandatory, so...
autotracking_possible = False
diff --git a/tests/test_AudioClips.py b/tests/test_AudioClips.py
index 3e1d4ea2..88f646e7 100644
--- a/tests/test_AudioClips.py
+++ b/tests/test_AudioClips.py
@@ -6,14 +6,10 @@ import sys
import pytest
from numpy import pi, sin
-from moviepy.audio.AudioClip import (
- AudioClip,
- CompositeAudioClip,
- concatenate_audioclips,
-)
+from moviepy.audio.AudioClip import AudioClip, concatenate_audioclips
from moviepy.audio.io.AudioFileClip import AudioFileClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
skip_if_windows = pytest.mark.skipif(
sys.platform.startswith("win"),
diff --git a/tests/test_ImageSequenceClip.py b/tests/test_ImageSequenceClip.py
index a2fc91e7..a998ff5f 100644
--- a/tests/test_ImageSequenceClip.py
+++ b/tests/test_ImageSequenceClip.py
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
"""Image sequencing clip tests meant to be run with pytest."""
import os
-import sys
import pytest
from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_1():
diff --git a/tests/test_PR.py b/tests/test_PR.py
index 4dd8ef5f..972df4b1 100644
--- a/tests/test_PR.py
+++ b/tests/test_PR.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Pull request tests meant to be run with pytest."""
import os
-import sys
from pathlib import Path
import pytest
@@ -12,10 +11,10 @@ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.fx.scroll import scroll
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.tools.interpolators import Trajectory
-from moviepy.video.VideoClip import ColorClip, ImageClip, TextClip
from moviepy.video.tools.subtitles import SubtitlesClip
+from moviepy.video.VideoClip import ColorClip, ImageClip, TextClip
-from .test_helper import FONT, TMP_DIR
+from tests.test_helper import FONT, TMP_DIR
def test_PR_306():
diff --git a/tests/test_TextClip.py b/tests/test_TextClip.py
index 58407e7e..d1d9ac10 100644
--- a/tests/test_TextClip.py
+++ b/tests/test_TextClip.py
@@ -1,12 +1,10 @@
-import sys
-
import pytest
from moviepy.utils import close_all_clips
from moviepy.video.fx.blink import blink
from moviepy.video.VideoClip import TextClip
-from .test_helper import FONT
+from tests.test_helper import FONT
def test_list():
diff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.py
index a9b56830..21d681dc 100644
--- a/tests/test_VideoClip.py
+++ b/tests/test_VideoClip.py
@@ -1,5 +1,4 @@
import os
-import sys
import pytest
from numpy import pi, sin
@@ -11,7 +10,7 @@ from moviepy.video.fx.speedx import speedx
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ColorClip, VideoClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_check_codec():
diff --git a/tests/test_VideoFileClip.py b/tests/test_VideoFileClip.py
index 3a2fc7bf..17fe242f 100644
--- a/tests/test_VideoFileClip.py
+++ b/tests/test_VideoFileClip.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Video file clip tests meant to be run with pytest."""
import os
-import sys
import pytest
@@ -10,7 +9,7 @@ from moviepy.video.compositing.CompositeVideoClip import clips_array
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ColorClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_setup():
diff --git a/tests/test_Videos.py b/tests/test_Videos.py
index 0fa73985..183fae13 100644
--- a/tests/test_Videos.py
+++ b/tests/test_Videos.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Video tests meant to be run with pytest."""
import os
-import sys
import pytest
@@ -9,7 +8,7 @@ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.fx.mask_color import mask_color
from moviepy.video.VideoClip import ColorClip, ImageClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_afterimage():
diff --git a/tests/test_compositing.py b/tests/test_compositing.py
index 50949d5a..2f049548 100644
--- a/tests/test_compositing.py
+++ b/tests/test_compositing.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""Compositing tests for use with pytest."""
-import sys
from os.path import join
import pytest
@@ -8,7 +7,7 @@ import pytest
from moviepy.editor import *
from moviepy.utils import close_all_clips
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_clips_array():
diff --git a/tests/test_examples.py b/tests/test_examples.py
index 1443ee34..4e516198 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -1,16 +1,18 @@
# -*- coding: utf-8 -*-
import os
-import pytest
import numpy as np
+import pytest
+
+from moviepy.video.io.bindings import mplfig_to_npimage
+from moviepy.video.VideoClip import VideoClip
+
+from tests.test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS
try:
import matplotlib
except ImportError:
matplotlib = None
-from moviepy.video.io.bindings import mplfig_to_npimage
-from moviepy.video.VideoClip import VideoClip
-from .test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS
@pytest.mark.skipif(not matplotlib, reason="no mpl")
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index 8b93b338..28482f29 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""FFmpeg reader tests meant to be run with pytest."""
-import sys
-
import pytest
from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
diff --git a/tests/test_fx.py b/tests/test_fx.py
index 8de4b6d2..f09c56ab 100644
--- a/tests/test_fx.py
+++ b/tests/test_fx.py
@@ -1,15 +1,12 @@
import os
-import sys
import pytest
from moviepy.audio.fx.audio_normalize import audio_normalize
from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.utils import close_all_clips
-from moviepy.video.VideoClip import ColorClip
from moviepy.video.fx.blackwhite import blackwhite
-
-# from moviepy.video.fx.blink import blink
+from moviepy.video.fx.blink import blink
from moviepy.video.fx.colorx import colorx
from moviepy.video.fx.crop import crop
from moviepy.video.fx.fadein import fadein
@@ -27,8 +24,9 @@ from moviepy.video.fx.speedx import speedx
from moviepy.video.fx.time_mirror import time_mirror
from moviepy.video.fx.time_symmetrize import time_symmetrize
from moviepy.video.io.VideoFileClip import VideoFileClip
+from moviepy.video.VideoClip import ColorClip
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def get_test_video():
diff --git a/tests/test_issues.py b/tests/test_issues.py
index 9b048da4..aa4ec31f 100644
--- a/tests/test_issues.py
+++ b/tests/test_issues.py
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
"""Issue tests meant to be run with pytest."""
-import os
-import sys
-
import pytest
from moviepy.editor import *
@@ -10,7 +7,7 @@ from moviepy.utils import close_all_clips
from moviepy.video.fx.blink import blink
from moviepy.video.fx.resize import resize
-from .test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS
+from tests.test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS
def test_issue_145():
@@ -329,7 +326,7 @@ def test_issue_416():
# ColorClip has no fps attribute.
green = ColorClip((640, 480), color=(0, 255, 0)).set_duration(2)
video1 = concatenate_videoclips([green])
- assert video1.fps == None
+ assert video1.fps is None
def test_issue_417():
@@ -388,7 +385,7 @@ def test_issue_547():
def test_issue_636():
with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 11) as video:
- with video.subclip(0, 1) as subclip:
+ with video.subclip(0, 1) as _:
pass
@@ -396,7 +393,7 @@ def test_issue_655():
video_file = "media/fire2.mp4"
for subclip in [(0, 2), (1, 2), (2, 3)]:
with VideoFileClip(video_file) as v:
- with v.subclip(1, 2) as s:
+ with v.subclip(1, 2) as _:
pass
next(v.subclip(*subclip).iter_frames())
assert True
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 10c31ff2..0210c139 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -1,5 +1,4 @@
import os
-import sys
import pytest
@@ -11,7 +10,7 @@ from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitles
from moviepy.video.VideoClip import ColorClip, TextClip
-from .test_helper import FONT, TMP_DIR
+from tests.test_helper import FONT, TMP_DIR
def test_cuts1():
diff --git a/tests/test_resourcerelease.py b/tests/test_resourcerelease.py
index 4103f748..b2f78a8d 100644
--- a/tests/test_resourcerelease.py
+++ b/tests/test_resourcerelease.py
@@ -7,7 +7,6 @@
Note: Platform dependent test. Will only fail on Windows > NT. """
-import subprocess as sp
import time
from os import remove
from os.path import join
@@ -16,8 +15,7 @@ from moviepy.video.compositing.CompositeVideoClip import clips_array
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ColorClip
-# from tempfile import NamedTemporaryFile
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
def test_release_of_file_via_close():
diff --git a/tests/test_resourcereleasedemo.py b/tests/test_resourcereleasedemo.py
index ea158d67..74091413 100644
--- a/tests/test_resourcereleasedemo.py
+++ b/tests/test_resourcereleasedemo.py
@@ -7,7 +7,6 @@
Note: Platform dependent test. Will only fail on Windows > NT. """
-import subprocess as sp
import time
from os import remove
from os.path import join
@@ -17,7 +16,7 @@ from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ColorClip
# from tempfile import NamedTemporaryFile
-from .test_helper import TMP_DIR
+from tests.test_helper import TMP_DIR
# import pytest
diff --git a/tests/test_videotools.py b/tests/test_videotools.py
index 0ed9dda3..0f55d3e3 100644
--- a/tests/test_videotools.py
+++ b/tests/test_videotools.py
@@ -2,12 +2,12 @@
"""Video file clip tests meant to be run with pytest."""
import os
-from moviepy.video.VideoClip import ColorClip
from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.video.tools.credits import credits1
from moviepy.video.tools.cuts import detect_scenes
+from moviepy.video.VideoClip import ColorClip
-from .test_helper import TMP_DIR, FONT
+from tests.test_helper import FONT, TMP_DIR
def test_credits():