Saturday, December 22, 2018

Rename photos during download from camera - on Linux?


On Windows, I'm using this feature (right-hand text) of the excellent cam2pc software to download images&videos from my camera and rename them in the same step. I haven't found any software for Linux that does the same, or does it as good. Suggestions please?


Details and requirements:



  1. I am using Picasa for everything after the download and I want to keep using it.

  2. I want a better download functionality than what Picasa offers.

  3. I know that some tools can do batch renaming after the download, but that's limited to those inside one folder. I want to specify the renaming scheme before the download, in a one-step process.

  4. Must run on PCLinux 2009.2 (Mandriva variant with KDE).

  5. Should autodetect that the camera has been plugged into the pc.

  6. Must download JPG and AVI files.

  7. Must support a user-customizable pattern for the downloaded files, like
    path/year/year-month-day hour-min TOPIC serial#.lowercase-extension
    e.g. photos/2009/20091218 1214 Skiing with friends 001.jpg
    (In cam2pc, that would look like %Y%m%d %h%u %P %{num:3}.%{ext})


By the way, I'm new to Linux and not a programmer, so I am hoping that solutions already exist that aren't too technical, or well documented.


Answer



A custom solution requires a little programming -- I need to write a shell script:



  1. Use the find command to see if the newly mounted USB drive contains media files;
    if no media files are found, then abort the script.
    find "/media/disk/dcim" -iname "img*.*" -type f


  2. Use the read command to prompt for a topic. (Equals %P in the question.)


  3. Find the timestamp of the oldest media file.
    ls -GgtR --full-time --time-style +"%Y%m%d %H%M" *.png | tail -1 | cut -c21-34



    • Hints:
      -GgtR = hide group and owner, sort by time, list Recursively.
      tail = keep only the last 1 line of the output.
      cut = keep only the characters 21-34.


  4. Use mkdir to create a new folder based on that date and topic.


  5. Use the find command with the -execdir option to find all media files,
    then move (mv) each hit to the new folder,
    then use jhead to rename each hit according to each file's timestamp.


  6. Optional: Use the umount command to unmount the USB drive.


  7. Set up Linux to execute this script when an USB drive is mounted. The detection of the USB drive (or camera) varies depending on the Linux variant; refer to OS-specific documentation. Or just run the script manually...



I'll need to spend invest some hours in learning bash commands, and also in learning how Linux mounts drives.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...