jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
357 stars 59 forks source link

rare error prevents further captures #119

Closed rwijtvliet closed 3 years ago

rwijtvliet commented 3 years ago

This page is for reporting problems with the Python interface to libgphoto2. If your question is about using libgphoto2 you should ask on the gphoto2 mailing list.

Your system Python 3.7.3, libgphoto2 2.5.22-3, Nikon D5600

Your problem Hey Jim,

I'm having an issue and am hoping you might have some insights. While doing timelapse photography, after several hours, there is a hickup and no further photos are taken. I've located the exact moment things go wrong, but I'm hoping to get help with the cause.

The loop I'm running is basically:


cam = gp.Camera()

def capture(path):
            logger.info(f"Taking an image to save to {path}.") # 1
            try:
                local = cam.capture(gp.GP_CAPTURE_IMAGE)
            except gp.GPhoto2Error as e:  # Assume camera can't focus; move on.
                logger.error(f"Couldn't take picture: {str(e)}") # 2
                return
            logger.info(f"Camera file path: {local.folder}/{local.name}") # 3
            file = cam.file_get(local.folder, local.name, gp.GP_FILE_TYPE_NORMAL)
            logger.info(f"Copying image to {path}") # 4
            file.save(path)

i= 0
while True:
    i += 1
    capture(f"/home/pi/{i}.jpg")
    sleep(120)

The exact moment that things break, line # 3 in the log says Camera file path: /store_00010001/DCIM/310D5600/DSC_0085.JPG, whereas all the times before it says something like Camera file path: //capt0161.jpg

After this has happened, every single attempt to take a picture fails with line # 2 Couldn't take picture: [-1] Unspecified error

Interestingly, there is a long time between line # 1 and line #2 - more or less 70 seconds for each time the function is called.

I hope this is the right location for this kind of question; many thanks

jim-easterbrook commented 3 years ago

It appears the camera is switching to storage on SD card instead of RAM - that would change the file path as you're seeing. I've never run my example time lapse script for that long.

Calling cam.exit() (before the fault occurs) might reset things and prevent the problem. I'm not sure it would help after the fault though.

rwijtvliet commented 3 years ago

I did indeed find the photo on the SD card. As a (probable) workaround, I've removed it (the card) from the camera for now.

jim-easterbrook commented 3 years ago

Another thought - are you deleting the image from RAM after copying it? Maybe your camera's memory is filling up.

rwijtvliet commented 3 years ago

Hmmm. That would make sense. Still, the error shows up after having taken several hundred images (of ~1MB each), and I don't think the camera's image RAM is that large (can't find any data on it).

On the other hand, I don't explicitly delete the images either (I assumed .file_get did this for images in RAM).

I'm running another test right now without an SD card and will let you know if the same issue arises.

rwijtvliet commented 3 years ago

It seems a full RAM was not the issue - the timelapse has now been running successfully for a lot longer than before, and the only change has been for me to remove the SD card 🤷‍♂️