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

Issue with movie_event example: Py5Image objects have no fields or methods named "read" #576

Open
epsln opened this issue Dec 23, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@epsln
Copy link

epsln commented Dec 23, 2024

Using py5 0.10.3a1

When trying to load a video and playing it using the code given in the tutorial

from processing.video import Movie


def setup():
    py5.size(500, 500)
    global movie_player
    movie_player = Movie(py5.get_current_sketch(), "movie.mov")
    movie_player.loop()


def movie_event(m):
    m.read()


def draw():
    if movie_player.isPlaying():
        py5.image(movie_player, 0, 0)


def exiting():
    movie_player.stop()


py5.run_sketch()

The movie_event function raises the following error:

    12   def movie_event(m): 
       m.read()                                
    ..................................................
     m.read = # AttributeError   
          m = Py5Image(width=0, height=0)  
    .................................................. 
AttributeError: Py5Image objects have no fields or methods named "read"  

It seems that the callback is called with an empty Py5Image (with 0 height and 0 width).

@villares
Copy link
Collaborator

Cheers, @epsln !

Thank you for opening this issue. I had some trouble making the Processing Video library work and then decided to use OpenCV playing capabilities as a workaround, as discussed at #266 (it could be the same issue!)

Could you perhaps try and see if something like using movie.available() helps?

def draw():
    if movie.available():
        movie.read() 

@hx2A
Copy link
Collaborator

hx2A commented Dec 23, 2024

Hi @epsln ! Thank you for opening this issue. I see what is causing this problem and I have two possible solutions in mind.

In addition to @villares 's workaround, can you try this:

def movie_event(m):
    m._instance.read()

I hope to do a release at the end of this week. I need to think about this issue before proceeding with a fix, so it won't be in the upcoming release, but I'll aim to take care of it in the first release in 2025.

@epsln
Copy link
Author

epsln commented Dec 23, 2024

Thanks for the quick responses. Both suggestions works and the video plays fine. While waiting for a fix, I'd suggest updating the documentation. Are you going to keep handling movies with an event and stick to Processing way of handling movies (like @hx2A response) or use openCV with a if statement on each frame (like in @villares response) ?

Excellent project by the way, I'll be keeping an eye on it !

@villares
Copy link
Collaborator

or use openCV with a if statement on each frame (like in @villares response)

My if movie.available() idea was something that I used also with Processing's Video library, but I think I got in trouble with Processing 4.X on some platforms (like on some student's Windows computer maybe?) so I moved to OpenCV for a while, and then didn't work with video for a long time! OpenCV might be a good option to have in your sleeve.

@hx2A
Copy link
Collaborator

hx2A commented Dec 23, 2024

@epsln , OpenCV is a good Python option for reading movie files, and is also a good thing to learn about in general, as it is applicable elsewhere in the Python world, outside of py5. However, the Processing way of handling movies and your code should work with py5. I believe it will be a relatively easy fix, I just need to think a bit before implementing it.

I agree, I will update the documentation to make a note of this problem.

@hx2A
Copy link
Collaborator

hx2A commented Dec 31, 2024

OK, I have updated the documentation so nobody else gets caught by this.

Hopefully an upcoming release will fix this problem and I'll change the documentation back.

@hx2A hx2A added the bug Something isn't working label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants