Skip to content
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

Video object returns array of zeros on second call #454

Open
EricThomson opened this issue Sep 27, 2023 · 6 comments
Open

Video object returns array of zeros on second call #454

EricThomson opened this issue Sep 27, 2023 · 6 comments

Comments

@EricThomson
Copy link

EricThomson commented Sep 27, 2023

Thanks a lot for the useful package! Sorry if my question betrays a basic misunderstanding:

I have an avi file that I am reading and pims works great accessing individual frames, initially:

pims_movie = pims.Video('filename.avi')
for ind in range(10,12):
    movie_frame = pims_movie[ind]
    print("\n", ind)
    print(movie_frame[:5, :5, 0])

It prints out reasonable values:

10
[[ 85 87 89 90 93]
[ 87 89 90 92 96]
[ 88 89 91 93 97]
[ 89 92 93 94 97]
[ 92 94 96 98 102]]

11
[[ 86 88 90 90 91]
[ 90 89 90 93 95]
[ 90 90 91 95 96]
[ 91 93 95 96 98]
[ 94 96 97 99 102]]

But if I run the for loop again (without reloading the movie), I get arrays of zeros back:

10
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]

11
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]

Is this expected behavior? Am I supposed to be closing out the video and reloading it, or using a context manager, or something?

@pgunn
Copy link

pgunn commented Sep 27, 2023

It looks like there are a few more ways to confuse the pims handle:

>>> pimfh = pims.Video('/mnt/home/pgunn/caiman_data/example_movies/msCam13.avi')
>>> pimfh[100][100].max()
128
>>> pimfh[100][100].max()
128
>>> data = np.array(pimfh)[200:250,100:120,500:510,0]
>>> pimfh[100][100].max()
0

@pgunn
Copy link

pgunn commented Sep 27, 2023

The code I pasted above shows the issue with pims 0.6.1

@pgunn
Copy link

pgunn commented Sep 27, 2023

In case it's helpful, the data file I'm using is available here (it's a dataset used as part of a scientific software package):

https://caiman.flatironinstitute.org/~neuro/caiman_downloadables/msCam13.avi

@pgunn
Copy link

pgunn commented Sep 27, 2023

I found a very weird way to reset the pims handle back to a healthy state, which may hint as to what's going on:

>>> pimfh[100][100].max()
128
>>> data = np.array(pimfh)[200:250, 100:120, 500:510, 0]
>>> pimfh[100][100].max()
0
>>> _ = pimfh[1]
>>> pimfh[100][100].max()
0
>>> _ = pimfh[0]
>>> pimfh[100][100].max()
128

I'll still rely on the pims developers to fully understand (and ideally patch) it, but we may be able to workaround the bug for now.

@pgunn
Copy link

pgunn commented Sep 28, 2023

In digging into this, it's actually not pims' fault, as we've found a way to reproduce this using moviepy calls (which is the backend both of us are using).

>>> mph = moviepy.editor.VideoFileClip(fn)
>>> mph.size
[752, 480]
>>> mph.duration
50.0
>>> mph.fps
20.0
>>> np.array(mph.get_frame(0)).max()
173
>>> np.array(mph.get_frame(2)).max()
206
>>> np.array(mph.get_frame(1)).max()
0
>>> np.array(mph.get_frame(0)).max()
173
>>> np.array(mph.get_frame(1)).max()
188

We'll reach out to the moviepy project.

@pgunn
Copy link

pgunn commented Sep 28, 2023

Zulko/moviepy#2044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants