Last updated: 2023-05-04 Thu 15:59

Exiftool
Snippets for everyday photo/video metadata editing

Table of Contents

1. Exiftool

1.1. Installation on Kapsi shared hosting

As per Exitool unix instructions:

$ wget https://exiftool.org/Image-ExifTool-12.25.tar.gz

$ tar xvf Image-ExifTool-12.25.tar.gz

$ cd Image-ExifTool-12.21

$ perl Makefile.PL

$ make test

$ mv exiftool lib/ ~/bin/

Note: If above is not done after version upgrade, a warning is displayed:

~$ exiftool -ver
12.25 [Warning: Library version is 12.21]

Finally, make sure that ~/.profile has:

if [ -d "$HOME/bin" ] ; then
     PATH="$HOME/bin:$PATH"
fi

Then logout and ssh back in for ~/.profile changes to take effect. Exiftool is installed:

$ type exiftool
exiftool is /home/users/pyyhttu/bin/exiftool

1.2. NEXT Upgrading on Kapsi shared hosting

1.3. Installation on debian instance with su access

$ sudo aptitude install libimage-exiftool-perl

1.4. Overview of mass tagging and organizing photos

To achieve with minimal amount of work a tagged and organized file structure.

  1. Move photos to one Upload directory. Doesn't matter if photos are scattered around in subdirectories in it.
  2. Update with Exiftool FileModifyDate using CreateDate that has it.

Those that don't, are reported with Warning: No writable tags set, and can be left behind for the second run:
$ exiftool -m -r '-FileModifyDate<CreateDate' -overwrite_original Upload/:

$ exiftool -m -r '-FileModifyDate<CreateDate' -overwrite_original Upload/
  10 directories scanned
  19 image files updated
  1. Rename with Exiftool every photo based on their CreateDate tag:
    $ exiftool -m -r -ext jpg -ext jpeg -ext png -ext bmp -ext eps -ext nef -ext heic '-filename<${createdate}_$filename' -d 'Photo_%Y-%m-%d' Upload/ && exiftool -m -r -ext mov -ext mp4 -ext wmv -ext avi -ext wmv '-filename<${createdate}_$filename' -d 'Video_%Y-%m-%d' Upload/
$ exiftool -m -r -ext jpg -ext jpeg -ext png -ext bmp -ext eps
'-filename<${createdate}_$filename' -d 'Photo_%Y-%m-%d' Upload/ && exiftool -m -r -ext mov -ext mp4 -ext wmv -ext avi -ext wmv
'-filename<${createdate}_$filename' -d 'Video_%Y-%m-%d' Upload/
   10 directories scanned
   19 image files updated
   10 directories scanned
    0 image files read
  1. Move with Exiftool every photo to their respective year and month directories:
    $ exiftool -m -r '-Directory<CreateDate' -d %Y/%m Upload/
$ exiftool -m -r '-Directory<CreateDate' -d %Y/%m Upload/
Error: '2022/06/Photo_2022-06-05_DSC_0001.JPG' already exists - Upload/2021/02/Photo_2022-06-05_DSC_0001.JPG
   10 directories scanned
    2 directories created
   18 image files updated
    1 files weren't updated due to errors

Note: If the command does not move images, it is an indication there are duplicates in the destination, and exiftool refuses to overwrite them.

  1. For second pass, run update in Upload directory for those that weren't updated with CreateDate but use DateTimeOriginal:
    $ exiftool -m -r '-FileModifyDate<DateTimeOriginal' -overwrite_original Upload/
  2. Rename based on DateTimeOriginal:
    $ exiftool -m -r -ext jpg -ext jpeg -ext png -ext bmp -ext eps -ext nef -ext heic '-filename<${createdate}_$filename' -d 'Photo_%Y-%m-%d' Upload/ && exiftool -m -r -ext mov -ext mp4 -ext wmv -ext avi -ext wmv '-filename<${createdate}_$filename' -d 'Video_%Y-%m-%d' Upload/
  3. Move based on DateTimeOriginal
    $ exiftool -m -r '-Directory<DateTimeOriginal' -d %Y/%m Upload/
  4. If no hits (xxx image files unchanged), then run third run and create CreateDate from FileModifyDate:
    $ exiftool -m -r '-CreateDate<FileModifyDate' -overwrite_original Upload/ && exiftool -m -r '-FileModifyDate<CreateDate' -overwrite_original Upload/
  5. Rerun steps 3. (Rename) and 4 (Move).
  6. Finally, while working in __groupfolders/2/Photos/, merge all year 2000 directories to their correct place

$ cp -r --interactive --preserve=all 20* ~/siilo/sites/pyyhttu-siilo.kapsi.fi/www/nextcloud/data/Heidi/files/Photos/

1.5. Single file usage

1.5.1. List all time metadata

$ exiftool -time:all -a -G0:1 image.jpg

1.5.2. Check tag names on a file

$ exiftool -s FILE

1.5.3. Change single tag's value

$ exiftool -exif:dateTimeOriginal='2017:12:22 12:00:01' -overwrite_original IMG_6446.JPG

Or, if a e.g. an mp4 file then:

$ exiftool -all:CreateDate='2019:07:28 15:00:01' -overwrite_original Ropecon-2019.mp4

1.5.4. Rename a file

$ exiftool '-filename<${datetimeoriginal}_$filename' -d 'Video_%Y-%m-%d' FILE

1.6. Mass tagging in detail

1.6.1. NEXT Bring FileModifyDate in sync with CreateDate, inspect images have this

This is done, because Nextcloud photos sorts pictures per file's modification time stamp –> I get pictures displayed in correct timeline.

1.6.2. NEXT DateTimeOriginal as master instead of CreateDate?

Instead of DateTimeOriginal, I consider CreateDate to be the master, as it's more common among video files. Additional difference between them two here.

$ exiftool -m -r '-FileModifyDate<CreateDate' -overwrite_original 2018/

However, since DateTimeOriginal is considered as master by dupeGuru (see this), then make sure you also copy CreateDate to DateTimeOriginal.

Note: Not every file type is writable, e.g. .wmv. See supported files types.

1.6.3. Verify tagging

Result per directory (2018 in this case) is something along the lines 156 image files updated. Verify that number matches with output of ls 2018/ | wc -l.

1.7. Mass renaming in detail

1.7.1. Rename images from their original DSC05240.jpg to Photo_2018-12-24_DSC05240.jpg

$ exiftool -r '-filename<${createdate}_$filename' -d 'Photo_%Y-%m-%d' Upload/

1.7.2. Rename also .avi videos in addition to writable files to Video_2018-12-24_DSC05240.AVI

$ exiftool -r -ext+ AVI '-filename<${datetimeoriginal}_$filename' -d 'Video_%Y-%m-%d' 2018/

1.7.3. Rename only .avi videos to Video_2018-12-24_DSC05240.AVI

$ exiftool -r -ext AVI '-filename<${datetimeoriginal}_$filename' -d 'Video_%Y-%m-%d' 2018/

1.7.4. Rename with vimv

$ vimv Photo_2014-03-04-*.mov

Changing extension to MOV in vim:

  1. Visual select mov ctrl-v
  2. Press on selection shift-c
  3. Type MOV, press esc
  4. Save and exit :wq

1.8. Moving

1.8.1. Move images and .AVI files from directory 2018/ into a directory structure of 2018/01/, 2018/02/, etc.

As per: https://exiftool.org/faq.html#Q16.

$ exiftool -r -ext+ AVI '-Directory<CreateDate' -d %Y/%m Upload/

1.8.2. Merge all directories from current directory to their place

$ cp -r preserve=all * ../

1.9. Finding

1.9.1. Find from a directory Pictures all Thumbs.db and remove them

$ find "Pictures/" -name Thumbs.db -exec rm -rf '{}' +

1.9.2. Find directories that are empty

$ find "/home/pyyhttu/temp/Pics/Yhtfilet/" -type d -exec bash -c 'shopt -s nullglob; shopt -s dotglob; files=("$1"/*); [[ ${files[@]} ]] || echo "$1"' -- {} \;~

1.9.3. Find and remove directories that are empty

$ find "/home/pyyhttu/temp/Pics/Yhtfilet/" -type d -exec bash -c 'shopt -s nullglob; shopt -s dotglob; files=("$1"/*); [[ ${files[@]} ]] || rmdir -v "$1"' -- {} \;

For more information on finding and removing, see stackexchange post.

1.9.4. NEXT Find and delete duplicates

  • Exiftool isn't really indented to find duplicates.
  • Also, comparing duplicates from a cmd line output and to make an informed decision without seeing the deleted image, isn't effective.
  • Much better way is to install dedicated tool for duplicates, e.g. dupeGuru on a user's laptop and operate it in tandem with Nextcloud Desktop sync client.
  • Then the user can point dupeGuru to scan one's Nextcloud photo directory residing on local filesystem, delete the duplicates, and synchronize changes (deletions) back to Nextcloud server side (master).

1.10. Tips

1.10.1. Subtract one year in date from all images (with date/time otherwise preserved):

$ exiftool -alldates-='1:0:0 0' *.jpg

1.10.2. Add one year in date on all images (with date/time otherwise preserved):

$ exiftool -alldates+='1:0:0 0'

1.10.3. Convert all Sony raw image files to high quality jpegs in a directory:

$ ufraw-batch *.ARW --out-type=jpeg --compression=99

1.10.4. Erase duplicates from whatsapp messages inside family, use either fdupes or FSlint

Tuomas Pyyhtiä / Validate Vim 8.2 (vim-orgmode 0.6.0)