This is a little script I’ve written to correct all my image files since the EXIF timestamp information is one hour out of sync. The filenames have been renamed to comply to the EXIF information and has to be renamed again because of the one hour scew. The filename can look something like this 20080102-1201_DSC_0910.JPG where the name is built up like YYYYMMDD-HHMM_Original_Filename.JPG
Remember to backup your imagefiles before you continue. You have been warned!
This is the files we are going to rename
20080102-1201_DSC_0910.JPG 20080105-1923_DSC_1006.JPG 20080111-1220_DSC00189.JPG 20080122-0929_DSC00190.JPG
The mmv command is a command that lets you move/copy/append/link multiple files by wildcard patterns. It can be installed in Debian (or Debian based distributions like Ubuntu) by issuing the command
# aptitude install mmv
Now rename the files back to their original name
# mmv "*_DSC*" "DSC#2"
The result after this operation looks like this
DSC_0910.JPG DSC_1006.JPG DSC_1179.JPG DSC_1302.JPG DSC_1587.JPG
Next adjust the EXIF information stored in the image files to fix the one hour difference. This can be done using different EXIF tools like exiftool, but I will show you how it can be done using jhead and exiv2. The advantage with exiv2 is that it can also handle Nikon NEF files while jhead only can prosess JPG.
The current timestamp can be determined as follows
# exiftool DSC_0910.JPG | grep "File Mo"
The result in this case is
File Modification Date/Time : 2008:01:02 08:34:09
# exiftool -AllDates+=1 DSC_0910.JPG
# jhead -ta +1 DSC_0910.JPG
Install the jhead package using aptitude as mentioned earlier for the mmv package
# exiv2 ad -a 1 DSC_0910.JPG
It is now time to rename the files back to the YYYYMMDD-HHMM_Original_Filename.JPG format I used before this operation. This operation has been describe in a previous post named Rename image files according to EXIF date
exiv2 -r'%Y%m%d-%H%M_:basename:' rename $(ls D*)
#!/bin/bash -x # Needed software: # exiftool # exiv2 # mmv # Script tested on Nikon D80 and Sony Cybershot DSC-W12 files # Make a printout of how the files look like now ls -l > repair_name_and_exif_before.txt # Rename files to remove date formatting back to original name mmv "*_DSC*" "DSC#2" # Change EXIF info on JPG files (order is important) exiftool -overwrite_original -AllDates+=1 D*.JPG # Preserve date/time of original file when writing exiftool -overwrite_original '-DateTimeOriginal>FileModifyDate' D*.JPG # Change EXIF info on NEF files (order is important) exiftool -overwrite_original -AllDates+=1 '-DateTimeOriginal>FileModifyDate' D*.NEF # Preserve date/time of original file when writing exiftool -overwrite_original '-DateTimeOriginal>FileModifyDate' D*.NEF # Rename files back to date formatting (YYYYMMDD-HHMM_Filename) based on the new EXIF info exiv2 -r'%Y%m%d-%H%M_:basename:' rename $(ls D*) # Make a printout of how the files look like after conversion ls -l > repair_name_and_exif_after.txt
Tags: Debian, EXIF, exiv2, jhead, JPG, mmv, NEF, Nikon, rename, Sony
Posted by Hans-Henry Jakobsen
The Nikon D80 camera contains a EXIF tag value that counts the number shots taken
| Tag (hex) | Tag (dec) | IFD | Key | Type | Tag description |
|---|---|---|---|---|---|
| 0×00a7 | 167 | Makernote | Exif.Nikon3.ShutterCount | Long | Number of shots taken by camera |
This can be extracted by running the following command
exiv2 -pt picturename.JPG ... Exif.Nikon3.ShutterCount Long 1 5263
This example shows that there have been 5263 shots taken.
I guess this EXIF tag exists on Nikon D40x, D60 and D70 also, but this is not verified.
More Nikon specific EXIF tags can be found on http://www.exiv2.org/tags-nikon.html
Tags: D80, EXIF, exiv2, JPG, Nikon
Posted by Hans-Henry Jakobsen
Sometimes it’s a good idea to remove the hidden data a JPG file contains, like when you publish picures on the Internet.
An easy way to remove all EXIF-tags from your JPG files is to run the command using jhead
jhead -purejpg *.jpg
Posted by Hans-Henry Jakobsen
The script below will take a filename eg: DSCN0001.JPG, extract the “Image Created” metadata and rename the original file to something like 2006-03-23_DSCN00001.JPG and it will do it automatically for you.
#! /bin/shfunction usage() {
if [ $# -ne 1 ]; then
echo "ExifDater - version 0.1 - March 23 2006"
echo "El-Lotso ”
echo “This is free software; see the source for copying conditions.”
echo “There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR”
echo “A PARTICULAR PURPOSE.”
echo
echo “ExifDater utilises the exiftags( http://johnst.org/sw/exiftags/)”
echo “program to sequentially extract the image creation date from”
echo “JPEG EXIF headers.”
echo
echo “Usage:”
echo “$0 /path/to/jpg/directory”
exit 0
fi
}
function exiftimexist(){
which exiftime > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo
echo “Unable to locate exiftime binary”
echo “Please make sure it is installed and is in your path.”
echo
exit 0
fi
}
function gotodir(){
cd $1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo
echo “Directory does not exists”
echo “Please try again.”
echo
exit 0
fi
}
function jpgexist(){
find . -iname “*.jpg” -type f >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo
echo “There are no JPEG pictures in this directory”
echo “Please try again.”
echo
exit 0
fi
}
function myexifdater(){
for i in *.jpg
do
create_date=`exiftime “$i” 2>&1 | grep -i image created | cut -d” ” -f3 | sed -e ’s/:/-/g’`
if [ “$create_date” == “” ]; then
echo -e “SKIPPING IMAGE $i \t\t\t [NO EXIF DATA FOUND]”
continue
fi
echo -n Processing Image $i Created on $create_date
do_rename=$( echo $i | sed -e ’s/(.*)/mv “&” “‘$create_date’_1″/g’|sh)
echo -e \t[DONE]
done
}
usage $1
exiftimexist
gotodir $1
jpgexist
myexifdater
Usage: ExifDater /your/picture/path
Download the ExifDater script.
There is also a Windows version of a program that’s called ExifDater for those who need that :)
Source: http://lotso.livejournal.com/2006/03/23/
Tags: bash, EXIF, exiftime, JPG, sed
Posted by Hans-Henry Jakobsen
Automatic rotation of JPG images (inclusive EXIF thumbnail) can be performed by using jhead.exe and jpegtran.exe in Windows.
jhead -ft -autorot *.JPG
All JPG-files in that folder will be rotated and file time (time and date of exposure) will be set according to the EXIF info.
(more…)
Tags: EXIF, jhead, jpegtran, orientation
Posted by Hans-Henry Jakobsen