waggle-sensor / pywaggle

Python SDK for integrating plugins with Waggle.
Other
6 stars 8 forks source link

Question about Camera.snapshot with mp4 file #42

Closed alexandertuna closed 1 month ago

alexandertuna commented 1 month ago

Hi wagglers,

I have a question about using Camera with a mp4 file. If I provide a mp4 video file to Camera and call snapshot() multiple times, the first frame of the video is always returned. I want to confirm, is this the expected behavior?

Here's a gist of what I mean: https://gist.github.com/alexandertuna/4f7cbe186b4d2174b7d6beff0cb7165a

I'm reading the code, and I think I understand it's the expected behavior, I just want to check with you.

Thanks, Alex

cc @iperezx

seanshahkarami commented 1 month ago

Hi Alex. That answer is actually that both are possible depending on whether a Camera object is used in a with statement.

Option 1:

camera = Camera(Path("video.mp4"))

# this will reopen the video each time and fetch the first frame
camera.snapshot()

Option 2:

with Camera(Path("video.mp4")) as camera:
    # this will keep the video capture open inside the with block and will fetch new frames each time
    camera.snapshot()

Let me know if that works for you.

alexandertuna commented 1 month ago

Thanks @seanshahkarami. That's good to know. I think that works for us.