-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add iterator interface to VideoReader objects #261
Add iterator interface to VideoReader objects #261
Conversation
I have added an iterator interface to the `VideoReader` type, making collecting all frames of a video as simple as `f = openvideo(fname); imgs = collect(f)`. The iterator returns a new array for each frame, as I think mutating the same array on subsequent calls to `iterate` would be surprising and lead to strange behavior when calling functions such as `collect`. Note that the VideoReader iterator is mutable, like Channel or Stateful iterators in Julia, and will resume iteration where it was last stopped, instead of at the beginning. I have added some text in the documentation explaining this behavior, and also added some tests.
I'm confused by these testing errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice addition. The test errors look to be out of memory related. The suggested change shouldn't be needed really, but may help on the more memory-limited CI machines?
test/avio.jl
Outdated
@test length(collect(v)) == VideoIO.TestVideos.videofiles[name].numframes | ||
@test length(collect(v)) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@test length(collect(v)) == VideoIO.TestVideos.videofiles[name].numframes | |
@test length(collect(v)) == 0 | |
imgstack = collect(v) | |
@test length(imgstack) == VideoIO.TestVideos.videofiles[name].numframes | |
imgstack = nothing | |
@test length(collect(v)) == 0 | |
GC.gc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good points... if CI is memory limited I probably should not be using collect
at all. I'll do some other test of the iterator interface that doesn't require storing all of the frames in memory at the same time.
Instead of collecting all frames into memory with `collect` to test the `VideoReader` interface, I am instead testing the iterator interface with a simple for loop. This should reduce the memory requirement for CI, and avoid memory-related test errors on low memory CI VMs.
Instead of looping over the iterator to test that there are zero elements remaining, it is simpler to just see if `iterate` returns `nothing`.
I have added a test to verify that frames returned by the `VideoReader` iterator interface have distinct storage.
Codecov Report
@@ Coverage Diff @@
## master #261 +/- ##
==========================================
- Coverage 77.13% 73.94% -3.20%
==========================================
Files 14 14
Lines 608 614 +6
==========================================
- Hits 469 454 -15
- Misses 139 160 +21
Continue to review full report at Codecov.
|
Looks good now. Shall we merge? |
Fine by me! |
I have added an iterator interface to the
VideoReader
type, making collecting all frames of a video as simple as:The iterator returns a new array for each frame, as I think mutating the same array on subsequent calls to
iterate
would be surprising and lead to strange behavior when calling functions such ascollect
. Note that the VideoReader iterator is mutable, like Channel or Stateful iterators in Julia, and will resume iteration where it was last stopped, instead of at the beginning. I have added some text in the documentation explaining this behavior, and also added some tests.