Skip to content

Commit

Permalink
Replace all 'nframes' by 'n_frames'
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Jan 19, 2021
1 parent 45c887e commit 83a187c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/examples/quick_recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ Getting the average frame of a video
clip = VideoFileClip("video.mp4")
fps = 1.0 # take one frame per second
total_image = sum(clip.iter_frames(fps, dtype=float, logger='bar'))
average_image = ImageClip(total_image / clip.nframes)
average_image = ImageClip(total_image / clip.n_frames)
average_image.save_frame("average_test.png")

6 changes: 3 additions & 3 deletions moviepy/audio/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def __init__(
self.infos = infos
self.proc = None

self.nframes = int(self.fps * self.duration)
self.buffersize = min(self.nframes + 1, buffersize)
self.n_frames = int(self.fps * self.duration)
self.buffersize = min(self.n_frames + 1, buffersize)
self.buffer = None
self.buffer_startframe = 1
self.initialize()
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_frame(self, tt):
else:

ind = int(self.fps * tt)
if ind < 0 or ind > self.nframes: # out of time: return 0
if ind < 0 or ind > self.n_frames: # out of time: return 0
return np.zeros(self.nchannels)

if not (0 <= (ind - self.buffer_startframe) < len(self.buffer)):
Expand Down
2 changes: 1 addition & 1 deletion moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def aspect_ratio(self):
@property
@requires_duration
@requires_fps
def nframes(self):
def n_frames(self):
return int(self.duration * self.fps)

def __copy__(self):
Expand Down
12 changes: 6 additions & 6 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(

self.duration = infos["video_duration"]
self.ffmpeg_duration = infos["duration"]
self.nframes = infos["video_nframes"]
self.n_frames = infos["video_n_frames"]
self.bitrate = infos["video_bitrate"]

self.infos = infos
Expand Down Expand Up @@ -155,7 +155,7 @@ def read_frame(self):
nbytes,
len(s),
self.pos,
self.nframes,
self.n_frames,
1.0 * self.pos / self.fps,
self.duration,
),
Expand Down Expand Up @@ -287,7 +287,7 @@ def ffmpeg_parse_infos(
"""Get file infos using ffmpeg.
Returns a dictionnary with the fields:
"video_found", "video_fps", "duration", "video_nframes",
"video_found", "video_fps", "duration", "video_n_frames",
"video_duration", "video_bitrate","audio_found", "audio_fps", "audio_bitrate"
"video_duration" is slightly smaller than "duration" to avoid
Expand Down Expand Up @@ -420,14 +420,14 @@ def get_fps():
result["video_fps"] = x * coef

if check_duration:
result["video_nframes"] = int(result["duration"] * result["video_fps"])
result["video_n_frames"] = int(result["duration"] * result["video_fps"])
result["video_duration"] = result["duration"]
else:
result["video_nframes"] = 1
result["video_n_frames"] = 1
result["video_duration"] = None
# We could have also recomputed the duration from the number
# of frames, as follows:
# >>> result['video_duration'] = result['video_nframes'] / result['video_fps']
# >>> result['video_duration'] = result['video_n_frames'] / result['video_fps']

# get the video rotation info.
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def test_ffmpeg_parse_infos():

def test_ffmpeg_parse_infos_duration():
infos = ffmpeg_parse_infos("media/big_buck_bunny_0_30.webm")
assert infos["video_nframes"] == 720
assert infos["video_n_frames"] == 720

infos = ffmpeg_parse_infos("media/bitmap.mp4")
assert infos["video_nframes"] == 5
assert infos["video_n_frames"] == 5


def test_ffmpeg_parse_infos_for_i926():
Expand Down

0 comments on commit 83a187c

Please sign in to comment.