Repository: Zulko/moviepy

Issue:
BitmapClip produces wrong output with fps != 1
BitmapClip only produces the correct output when `fps=1`. When `fps>1`, frames are duplicated and later frames cut off.

Works fine for `fps=1`:
```python
from moviepy.video.VideoClip import BitmapClip
clip=BitmapClip([["A"], ["B"], ["C"], ["D"]], fps=1)

In [18]: clip.to_bitmap()
Out[18]: [['A'], ['B'], ['C'], ['D']]
```

However, when you increase the fps, each frame is duplicated `fps` times, and later frames are cut off entirely. I suspect this is an issue within the creation of the bitmapclip, not with the `to_bitmap()` method, as `iter_frames()` returns a similar result.

#### Expected Behavior

```python
clip=BitmapClip([["A"], ["B"], ["C"], ["D"]], fps=2)

In [22]: clip.to_bitmap()
Out[22]: [['A'], ['B'], ['C'], ['D']]
```

#### Actual Behavior

```python
clip=BitmapClip([["A"], ["B"], ["C"], ["D"]], fps=2)

In [22]: clip.to_bitmap()
Out[22]: [['A'], ['A'], ['B'], ['B']]
```

#### Specifications

  - Python Version: 3.7.4
  - Moviepy Version: 2.0.0.dev1 (git master branch)
  - Platform Name: Ubuntu 16.04.4 (on WSL)


Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/33966099/badge)](https://coveralls.io/builds/33966099)

Coverage increased (+0.3%) to 67.838% when pulling **114a0fffc3122ac8251f46d355619d00c2aa896c on tburrows13:fix-BitmapClip** into **0e4bf6d1c1b448a477c9be49e49c97b104ba1830 on Zulko:master**.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c6298e..4729aa1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Removed <!-- for now removed features -->
 
 ### Fixed <!-- for any bug fixes -->
+- Fixed BitmapClip with fps != 1 not returning the correct frames or crashing [#1333]
 
 
 ## [v2.0.0.dev2](https://github.com/zulko/moviepy/tree/v2.0.0.dev2)
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 6c29ce3..3fcd92f 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -1411,7 +1411,7 @@ class BitmapClip(VideoClip):
 
         VideoClip.__init__(
             self,
-            make_frame=lambda t: frame_array[int(t)],
+            make_frame=lambda t: frame_array[int(t * fps)],
             ismask=ismask,
             duration=duration,
         )


Test patch:
diff --git a/tests/test_BitmapClip.py b/tests/test_BitmapClip.py
index b4eb2d8..527f3e9 100644
--- a/tests/test_BitmapClip.py
+++ b/tests/test_BitmapClip.py
@@ -45,5 +45,15 @@ def test_setting_duration():
     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()