chrestomanci has asked for the wisdom of the Perl Monks concerning the following question:

Brothers, I seek your wisdom.

Is there a perl library, script or CPAN module that talks Picture Transfer Protocol (PTP) I have searched here, google and CPAN for both "Picture Transfer Protocol" and gPhoto2 and come up empty.

libgphoto2 is the linux library that implements the protocol, and is used by a number of linux GUI applications to talk to digital cameras.

Does anyone know of a project or library out there that I am missing?

Edit: To be clear, picture transfer protocol (PTP) is different from USB mass storage. Some cameras when you connect them to a PC, become USB mass storage devices for the contents to the memory card. Others don't talk mass storage, but instead talk PTP. I have two Nikon and two Cannon cameras at home, both the Nikon cameras talk mass storage when connected to a PC, but the Canon cameras talk PTP. I would need to remove the memory card from the camera and put it in a card reader in order to use mass storage, which would be less convenient.

libgphoto2 includes a shell gphoto2 that exposes most of the same functions as are available in the library. It gives you an idea of what can be done.

The reason that I am interested in reading the picture on my camera over PTP, is that the filesystem emulation provided by Ubuntu only lets me read complete files. There is no random access to files. I would like to read the Exif information of my photos (into Image::EXIF objects) without the overhead of transferring entire files. Using the shell I can read the Exif information of 300 pictures in about 8 seconds. If Ubuntu mounts the camera as a filesystem, then in order to read the Exif information from all those pictures, the filesystem emulator would first need to copy them to the local machine, and seeing as the total size is about a Gigabyte, that would take several minutes.

  • Comment on CPAN module for Picture Transfer Protocol ?

Replies are listed 'Best First'.
Re: CPAN module for Picture Transfer Protocol ?
by JavaFan (Canon) on May 01, 2011 at 22:41 UTC
    I'm not aware of any such Perl bindings, but I've to admit, I haven't searched hard enough. Calling gphoto2 for a Perl program (and having itself call another one using --hook-script) does the job for me.

    And calling external programs from Perl is actually very Perlish; Perl, after all, is a glue language. And since most of what you want to do with gphoto2 is I/O bound, the overhead of calling another program is insignificant.

Re: CPAN module for Picture Transfer Protocol ?
by zentara (Cardinal) on May 01, 2011 at 16:04 UTC
    I read the wiki article, and am not sure if you are asking your question correctly.

    Because of the usb filesystem, all you need to do is mount the camera as a mass storage device, to get at the images. The PTP aspect is transparent as the usb filesystem drivers handle that read.

    If, on the other hand you want actually manipulate the low level storage electronics in these PTP cameras or memory cards, Perl may be of use with pack and unpack

    Maybe look at the usb filesystem drivers that handle PTP?


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      I think you have miss-understood what PTP is. It is not the same as USB mass storage. Different cameras prefer one protocol over the other when they are connected to a PC.

      I have edited my original post to add some clarification.

      I don't need to to use low level access to the USB device using pack or suchlike, libgphoto2 provides an abstraction layer, but it is a C library. My question is are there perl bindings available for that library?

        My question is are there perl bindings available for that library?

        Searching for "libgphoto2 perl" brings up

        RPM Search Mandriva 2009 camdump-1.01-0.13mdv2008.1.i586.rpm Content of RPM : /etc/camdump /etc/dynamic/hooks/camdump.hook /usr/bin +/camdump /usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi/au +to/gphoto2_perl/libgphoto2_perl.so rpm.pbone.net/index.php3/stat/4/idpl/9472588/dir//com...
        So some bindings existed at some point. But i think, since there is a cli interface, there is no reason to bind :)