Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
osaajani committed Jan 22, 2025
1 parent f12ee5a commit 25b61eb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
7 changes: 4 additions & 3 deletions moviepy/audio/io/ffplay_audiopreviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from moviepy.tools import cross_platform_popen_params
from moviepy.video.io import ffmpeg_tools


class FFPLAY_AudioPreviewer:
"""
A class to preview an AudioClip.
Expand Down Expand Up @@ -45,12 +46,12 @@ def __init__(

# 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,
Expand All @@ -75,7 +76,7 @@ def write_frames(self, frames_array):
_, 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}"
Expand Down
16 changes: 8 additions & 8 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ def parse(self):
# 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:
Expand Down Expand Up @@ -788,14 +788,14 @@ def video_metadata_type_casting(self, field, value):
"""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)


Expand Down
27 changes: 11 additions & 16 deletions moviepy/video/io/ffmpeg_tools.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -242,25 +240,24 @@ 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)


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
Expand Down Expand Up @@ -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)


2 changes: 1 addition & 1 deletion tests/test_PR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/test_ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ffmpeg_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ffmpeg_extract_subclip,
ffmpeg_resize,
ffmpeg_stabilize_video,
ffmpeg_version
ffmpeg_version,
)
from moviepy.video.io.VideoFileClip import VideoFileClip

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 25b61eb

Please sign in to comment.