0

For a bunch of jpg photos, I have this (simplified) script to be able to extract the original date when the photo was taken (if different of 0000:00:00, not relevant for this case)

for f in *.jpg;
do 
    echo -n $f "  >>  " ;
    /usr/bin/exiv2 -P E  pr $f  | grep 'Exif.Photo.DateTimeOriginal';
done

But the pipe from exiv2 to grep sometimes retrieves the info present in the metadata of photos, sometimes not. The file list test set is:

$ ls
sany0070.jpg  sany0071.jpg  sany0072.jpg  sany0073.jpg  sany0074.jpg

What I get from this, is an inconsistent result, such as:

$ for f in *.jpg; do echo -n $f "  >>  " ; /usr/bin/exiv2 -P E  pr $f  | grep 'Exif.Photo.DateTimeOriginal'; done
sany0070.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0071.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0072.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0073.jpg   >>  Binary file (standard input) matches
sany0074.jpg   >>  Binary file (standard input) matches

A second time (the script was able to grep as expected):

$ for f in *.jpg; do echo -n $f "  >>  " ; /usr/bin/exiv2 -P E  pr $f  | grep 'Exif.Photo.DateTimeOriginal'; done
sany0070.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0071.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0072.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0073.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0074.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00

A third time (not able to grep the info asked, although it was different from the first attempt:

$ for f in *.jpg; do echo -n $f "  >>  " ; /usr/bin/exiv2 -P E  pr $f  | grep 'Exif.Photo.DateTimeOriginal'; done
sany0070.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0071.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0072.jpg   >>  Binary file (standard input) matches
sany0073.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00
sany0074.jpg   >>  Exif.Photo.DateTimeOriginal                  Ascii      20  0000:00:00 00:00:00

And so on.

I'm running Slackware64 14.2 Linux with:

$ grep -V
grep (GNU grep) 2.25

$ exiv2 --version
exiv2 0.25 001900 (64 bit build)

I'd like to know why this is happening and how to deal with this.

Edit: This happens to this set of files (five in the example as a sample of the 76 of the original directory), but has not happened to hundreds of other ones in dozens of directories I applied it with no problems.

0

Luis, your last edit explains it all. It’s not your code that’s broken; it’s the metadata for certain specific jpeg files. I’m not sure how to fix that but at least I can tell you that you need to look for the answer in the jpeg files themselves. I thing Gimp and ImageMagick will let you fix those kind of things but you would have to read the manuals in order to find out how to change the metadata with those apps. Hope that helps.

  • The last edit doesn't "explain it all"; it doesn't explain why he's getting inconsistent results for certain specific JPEG files. – G-Man Jul 9 '16 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.