Skip to content

Commit

Permalink
add ImageSequenceClip image size exception (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
bearney74 committed Apr 19, 2017
1 parent ec9959a commit b67972d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
15 changes: 15 additions & 0 deletions moviepy/video/io/ImageSequenceClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ def __init__(self, sequence, fps=None, durations=None, with_mask=True,
sequence = sorted([os.path.join(sequence, f)
for f in os.listdir(sequence)])


#check that all the images are of the same size
if isinstance(sequence[0], str):
size = imread(sequence[0]).shape
else:
size = sequence[0].shape

for image in sequence:
image1=image
if isinstance(image, str):
image1=imread(image)
if size != image1.shape:
raise Exception("Moviepy: ImageSequenceClip requires all images to be the same size")


self.fps = fps
if fps is not None:
durations = [1.0/fps for image in sequence]
Expand Down
18 changes: 17 additions & 1 deletion tests/test_ImageSequenceClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,31 @@ def test_download_media(capsys):
def test_1():
images=[]
durations=[]

for i in range(5):
durations.append(i)
images.append("media/python_logo.png")
durations.append(i)
images.append("media/matplotlib_demo1.png")
images.append("media/python_logo.png")
#images.append("media/matplotlib_demo1.png")

clip = ImageSequenceClip(images, durations=durations)
assert clip.duration == sum(durations)
clip.write_videofile("/tmp/ImageSequenceClip1.mp4", fps=30)

def test_2():
images=[]
durations=[]

durations.append(1)
images.append("media/python_logo.png")
durations.append(2)
images.append("media/matplotlib_demo1.png")

#images are not the same size..
with pytest.raises(Exception, message='Expecting Exception'):
ImageSequenceClip(images, durations=durations)


if __name__ == '__main__':
pytest.main()
21 changes: 12 additions & 9 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def test_issue_145():
with pytest.raises(Exception, message='Expecting Exception'):
concatenate_videoclips([video], method='composite')

def test_issue_190():
#from PIL import Image
#Image.new('L', (800,600), 'white').save(os.path.join(TMP_DIR, "issue_190.png"))

#from imageio import imread
#image = imread(os.path.join(TMP_DIR, "issue_190.png"))

#clip = ImageSequenceClip([image, image], fps=1)
#clip.write_videofile(os.path.join(TMP_DIR, "issue_190.mp4"))
pass

def test_issue_285():

clip_1, clip_2, clip_3 = ImageClip('media/python_logo.png', duration=10), \
Expand Down Expand Up @@ -227,15 +238,6 @@ def test_issue_417():
CompositeVideoClip([myclip], size=(1280, 720))
#final.set_duration(7).write_videofile("test.mp4", fps=30)

def test_issue_464():
import numpy as np
original_frames = [i*np.ones((32, 32, 3), dtype=np.uint8) for i in range(50)]
clip = ImageSequenceClip(original_frames, fps=30)
for original_frame, clip_frame in zip(original_frames, clip.iter_frames()):
# The retrieved frames should be equal to the original ones
# Since the frames are constant color, it suffices to compare one pixel
assert original_frame[0,0,0] == clip_frame[0,0,0]

def test_issue_467():
cad = 'media/python_logo.png'
clip = ImageClip(cad)
Expand Down Expand Up @@ -263,5 +265,6 @@ def test_audio_reader():
subclip.write_audiofile(os.path.join(TMP_DIR, 'issue_246.wav'),
write_logfile=True)


if __name__ == '__main__':
pytest.main()

0 comments on commit b67972d

Please sign in to comment.