Skip to content

Video editing with Python

linting

osaajani25b61eb9ea62
diff --git a/moviepy/audio/io/ffplay_audiopreviewer.py b/moviepy/audio/io/ffplay_audiopreviewer.py
index fbfcfcac..c7bdb251 100644
--- a/moviepy/audio/io/ffplay_audiopreviewer.py
+++ b/moviepy/audio/io/ffplay_audiopreviewer.py
@@ -7,6 +7,7 @@ from moviepy.decorators import requires_duration
from moviepy.tools import cross_platform_popen_params
from moviepy.video.io import ffmpeg_tools
+
class FFPLAY_AudioPreviewer:
"""
A class to preview an AudioClip.
@@ -45,12 +46,12 @@ class FFPLAY_AudioPreviewer:
# Adapt number of channels argument to ffplay version
ffplay_version = ffmpeg_tools.ffplay_version()[1]
- if int(ffplay_version.split('.')[0]) >= 7:
+ if int(ffplay_version.split(".")[0]) >= 7:
cmd += [
"-ch_layout",
"stereo" if nchannels == 2 else "mono",
]
- else :
+ else:
cmd += [
"-ac",
"%d" % nchannels,
@@ -75,7 +76,7 @@ class FFPLAY_AudioPreviewer:
_, ffplay_error = self.proc.communicate()
if ffplay_error is not None:
ffplay_error = ffplay_error.decode()
-
+
error = (
f"{err}\n\nMoviePy error: FFPLAY encountered the following error while "
f":\n\n {ffplay_error}"
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index 64cfc797..c9d073b6 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -476,12 +476,12 @@ class FFmpegInfosParser:
# for default streams, set their numbers globally, so it's
# easy to get without iterating all
if self._current_stream["default"]:
- self.result[
- f"default_{stream_type_lower}_input_number"
- ] = input_number
- self.result[
- f"default_{stream_type_lower}_stream_number"
- ] = stream_number
+ self.result[f"default_{stream_type_lower}_input_number"] = (
+ input_number
+ )
+ self.result[f"default_{stream_type_lower}_stream_number"] = (
+ stream_number
+ )
# exit chapter
if self._current_chapter:
@@ -788,14 +788,14 @@ class FFmpegInfosParser:
"""Cast needed video metadata fields to other types than the default str."""
if field == "rotate":
return (field, float(value))
-
+
elif field == "displaymatrix":
match = re.search(r"[-+]?\d+(\.\d+)?", value)
if match:
# We must multiply by -1 because displaymatrix return info
# about how to rotate to show video, not about video rotation
return (field, float(match.group()) * -1)
-
+
return (field, value)
diff --git a/moviepy/video/io/ffmpeg_tools.py b/moviepy/video/io/ffmpeg_tools.py
index 0da6921a..c154d9b5 100644
--- a/moviepy/video/io/ffmpeg_tools.py
+++ b/moviepy/video/io/ffmpeg_tools.py
@@ -1,10 +1,8 @@
"""Miscellaneous bindings to ffmpeg."""
import os
-
-import subprocess
-
import re
+import subprocess
from moviepy.config import FFMPEG_BINARY, FFPLAY_BINARY
from moviepy.decorators import convert_parameter_to_seconds, convert_path_to_string
@@ -217,9 +215,9 @@ def ffmpeg_version():
"""
Retrieve the FFmpeg version.
- This function retrieves both the full and numeric version of FFmpeg
- by executing the `ffmpeg -version` command. The full version includes
- additional details like build information, while the numeric version
+ This function retrieves both the full and numeric version of FFmpeg
+ by executing the `ffmpeg -version` command. The full version includes
+ additional details like build information, while the numeric version
contains only the version numbers (e.g., '7.0.2').
Return
@@ -242,15 +240,14 @@ def ffmpeg_version():
cmd = [
FFMPEG_BINARY,
"-version",
- "-v"
- "quiet",
+ "-v", "quiet",
]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
-
+
# Extract the version number from the first line of output
full_version = result.stdout.splitlines()[0].split()[2]
- numeric_version = re.match(r'^[0-9.]+', full_version).group(0)
+ numeric_version = re.match(r"^[0-9.]+", full_version).group(0)
return (full_version, numeric_version)
@@ -258,9 +255,9 @@ def ffplay_version():
"""
Retrieve the FFplay version.
- This function retrieves both the full and numeric version of FFplay
- by executing the `ffplay -version` command. The full version includes
- additional details like build information, while the numeric version
+ This function retrieves both the full and numeric version of FFplay
+ by executing the `ffplay -version` command. The full version includes
+ additional details like build information, while the numeric version
contains only the version numbers (e.g., '6.0.1').
Return
@@ -288,7 +285,5 @@ def ffplay_version():
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
# Extract the version number from the first line of output
full_version = result.stdout.splitlines()[0].split()[2]
- numeric_version = re.match(r'^[0-9.]+', full_version).group(0)
+ numeric_version = re.match(r"^[0-9.]+", full_version).group(0)
return (full_version, numeric_version)
-
-
diff --git a/tests/test_PR.py b/tests/test_PR.py
index 33ae5846..0acd3f68 100644
--- a/tests/test_PR.py
+++ b/tests/test_PR.py
@@ -69,7 +69,7 @@ def test_PR_528(util):
def test_PR_529():
- #print(ffmpeg_tools.ffplay_version())
+ # print(ffmpeg_tools.ffplay_version())
print(ffmpeg_tools.ffmpeg_version())
with VideoFileClip("media/fire2.mp4") as video_clip:
assert video_clip.rotation == 180
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index e28fd80b..4269616b 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -16,9 +16,7 @@ from moviepy.video.io.ffmpeg_reader import (
FFmpegInfosParser,
ffmpeg_parse_infos,
)
-from moviepy.video.io.ffmpeg_tools import (
- ffmpeg_version,
-)
+from moviepy.video.io.ffmpeg_tools import ffmpeg_version
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import BitmapClip, ColorClip
@@ -74,7 +72,7 @@ def test_ffmpeg_parse_infos_decode_file(decode_file, expected_duration):
d = ffmpeg_parse_infos("media/big_buck_bunny_0_30.webm", decode_file=decode_file)
# On old version of ffmpeg, duration and video duration was different
- if int(ffmpeg_version()[1].split('.')[0]) < 7:
+ if int(ffmpeg_version()[1].split(".")[0]) < 7:
expected_duration += 0.02
assert d["duration"] == expected_duration
diff --git a/tests/test_ffmpeg_tools.py b/tests/test_ffmpeg_tools.py
index 366d4bfe..af66de2e 100644
--- a/tests/test_ffmpeg_tools.py
+++ b/tests/test_ffmpeg_tools.py
@@ -9,7 +9,7 @@ from moviepy.video.io.ffmpeg_tools import (
ffmpeg_extract_subclip,
ffmpeg_resize,
ffmpeg_stabilize_video,
- ffmpeg_version
+ ffmpeg_version,
)
from moviepy.video.io.VideoFileClip import VideoFileClip
@@ -59,7 +59,7 @@ def test_ffmpeg_resize(util):
assert os.path.isfile(outputfile)
# overwrite file on old version of ffmpeg
- if int(ffmpeg_version()[1].split('.')[0]) < 7:
+ if int(ffmpeg_version()[1].split(".")[0]) < 7:
with pytest.raises(OSError):
ffmpeg_resize("media/bitmap.mp4", outputfile, expected_size, logger=None)
@@ -101,7 +101,7 @@ def test_ffmpeg_stabilize_video(util):
assert os.path.isfile(expected_filepath)
# don't overwrite file on old version of ffmpeg
- if int(ffmpeg_version()[1].split('.')[0]) < 7:
+ if int(ffmpeg_version()[1].split(".")[0]) < 7:
with pytest.raises(OSError):
ffmpeg_stabilize_video(
"media/bitmap.mp4",