Skip to content

Commit 5c6b98b

Browse files
committed
Fix: return None when no frame data is available in next_frame method
1 parent 1187cf4 commit 5c6b98b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/native/src/bindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ NB_MODULE(_viteo, m) {
4040
nb::gil_scoped_release release;
4141
frame_data = self.next_frame();
4242
}
43+
if (!frame_data) return nb::none();
4344
return create_mlx_array(frame_data, self.height(), self.width());
4445
},
4546
"Get next frame as MLX array (None when done)")

tests/test_viteo.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,38 @@ def test_iterator(sample_video):
123123
assert count == 10
124124

125125

126+
def test_run_to_end(sample_video):
127+
"""Test running through all frames to the end."""
128+
path = sample_video["path"]
129+
if not path.exists():
130+
pytest.skip(f"Test video not found: {path}")
131+
132+
with viteo.open(path) as video:
133+
frame_count = 0
134+
for frame in video:
135+
frame_count += 1
136+
137+
assert frame_count == video.total_frames
138+
139+
140+
def test_last_frame_is_none(sample_video):
141+
path = sample_video["path"]
142+
if not path.exists():
143+
pytest.skip(f"Test video not found: {path}")
144+
145+
i = 0
146+
with viteo.open(path) as video:
147+
while True:
148+
frame = video.next_frame()
149+
if not isinstance(frame, mx.array):
150+
break
151+
152+
i += 1
153+
154+
assert frame is None
155+
assert i == video.total_frames
156+
157+
126158
def test_reset(sample_video):
127159
"""Test reset functionality."""
128160
path = sample_video["path"]

0 commit comments

Comments
 (0)