Quantcast
Channel: geekoverdose
Viewing all articles
Browse latest Browse all 70

Batch rename pictures of multiple recording devices to show date and time in filenames

$
0
0

Similar to sorting images into folders named after their date, we’re going to look at automatically renaming pictures – so that their names are based on timestamps they’ve been taken. This enables sorting pictures chronologically in pretty much all software that’s out there (as sorting alphabetically implies chronological sorting then).

The problem

Imagine a group event with multiple people taking pictures using multiple cams. Usually, naming schemes of cameras are different, such as

IMG_1234.JPG
DCM_5678.jpg
...

If people later share images they could either put all into the same folder, or separate them by folders – we’re going to focus on the first case here. If these images get sorted alphabetically, they are not automatically sorted by their timestamps for the reason of using different naming schemes. On the one hand, for file explorers this can often be changed by sorting after image timestamps. On the other hand, this is not applicable for all cases: e.g. image viewers/galleries also need to feature sorting after timestamps for switching to the “next” picture. Panoramas created from multiple images also frequently do not contain timestamps any more, therefore sorting by timestamps causes panoramas to be on top/bottom of the list.

Renaming pictures – to contain timestamps in names

For those reasons we tend to automatically rename all images to fit a uniform naming scheme such as

yyyy_mm_dd-hh_mm_ss_number_person.jpg

  • date and time are first in filenames – this automatically causes chronological sorting when sorting alphabetically (pretty much every program can sort files alphabetically)
  • number is the original sequential number of the image (contained in the new name to not lose any information)
  • person is an identifier of who and/or with which device the picture was taken

The snippet

match_whitecards="IMG*JPG"          # wildcards of which files to match
oldname_regex="s/IMG_//;s/.JPG//"   # regex of how to modify the old filename before adding it to the new filename
newname_postfix="_FsCam"            # your personal name postfix

for filepath_old in `find . -iname "$match_whitecards"`
do 
    filename_old=`basename $filepath_old`
    filename_new=`exif -t 0x9003 -m $filepath_old | sed "s/:/_/g;s/ /-/g"`_`echo $filename_old | sed $oldname_regex`$newname_postfix.jpg
    rename -n -v "s/`echo $filename_old`/`echo $filename_new/`" $filepath_old
done
  • match_whitecards: defines which files you want to match
  • oldname_regex: defines how old filenames should be modified and preserved in new filenames
  • newname_postfix: identifier added to filenames (to identify person and device)

Finally, you might take care of the following before starting taking pictures:

  • Ensure clock synchronization over all devices taking pictures (cameras, mobile phones, …). Otherwise you may experience “lag” effects (when looking through the pictures it seems like some person was a bit ahead or behind always)
  • If you want to sort videos too: take care of used time zones. Cameras usually encode the current device timestamps to the picture (the time shown on the device) – independent of the set time zone. In contrast, many mp4-recorders (like mobile phones) encode UTC timestamps instead of the time shown on the device. If you would use both types of timestamps without intermediate correction, “lags” might occur again.


Viewing all articles
Browse latest Browse all 70

Trending Articles