1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
"""BitmapClip tests."""
import numpy as np
import pytest
from moviepy.video.VideoClip import BitmapClip
def test_clip_generation():
bitmap = [["RR", "RR"], ["RB", "RB"]]
expected_frame_array = np.array(
[
np.array([[(255, 0, 0), (255, 0, 0)], [(255, 0, 0), (255, 0, 0)]]),
np.array([[(255, 0, 0), (0, 0, 255)], [(255, 0, 0), (0, 0, 255)]]),
]
)
unexpected_frame_array = np.array(
[
np.array([[(255, 0, 0), (255, 0, 0)], [(255, 0, 0), (255, 0, 1)]]),
np.array([[(255, 0, 0), (0, 0, 255)], [(255, 0, 0), (0, 0, 255)]]),
]
)
clip = BitmapClip(bitmap, fps=1)
frame_array = np.array(list(clip.iter_frames()))
# Check that frame_list == expected_frame_list
assert np.array_equal(frame_array, expected_frame_array)
# Check that frame_list != unexpected_frame_list
assert not np.array_equal(frame_array, unexpected_frame_array)
def test_setting_fps():
bitmap = [["R"], ["R"], ["B"], ["B"], ["G"], ["G"]]
clip = BitmapClip(bitmap, fps=1)
assert clip.fps == 1
assert clip.duration == 6
def test_setting_duration():
bitmap = [["R"], ["R"], ["B"], ["B"], ["G"], ["G"]]
clip = BitmapClip(bitmap, duration=6)
assert clip.fps == 1
assert clip.duration == 6
def test_to_bitmap():
bitmap = [["R"], ["R"], ["B"], ["B"], ["G"], ["G"]]
clip1 = BitmapClip(bitmap, fps=0.345)
clip2 = BitmapClip(bitmap, fps=1)
clip3 = BitmapClip(bitmap, fps=3.12345)
assert bitmap == clip1.to_bitmap()
assert bitmap == clip2.to_bitmap()
assert bitmap == clip3.to_bitmap()
if __name__ == "__main__":
pytest.main()
|