How to make ExifTool ignore empty tags?

Started by vicmarto, February 23, 2019, 11:47:58 PM

Previous topic - Next topic

vicmarto

Hello!

Sorry, I tried to found the answer to this question, but finally couldn't...  :-[

Please, is there a way to make ExifTool ignore empty tags? What I want to do is rename my photos using DateTimeOriginal and SubSecTimeDigitized, but only 4 of the 9 files have the SubSecTimeDigitized tag. How can the SubSecTimeDigitized tag be ignored and use only DateTimeOriginal?

$ ls -lT
total 136248
-rw-r--r-- 1 user  group   1111021 27 dic 22:14:32 2002 a.jpg
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 b.jpg
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 c.jpg
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 d.nef
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 e.nef
-rw-r--r-- 1 user  group  27328928 16 oct 12:44:02 2010 f.dng
-rw-r--r-- 1 user  group  15346696  2 oct 12:37:19 2010 g.dng
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 h.avi
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 i.avi


$ exiftool -d '%Y-%m-%d %H.%M.%S' '-FileName<${DateTimeOriginal}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' .
Warning: [minor] Bad IDC_IFD SubDirectory start - ./f.dng
Warning: No writable tags set from ./f.dng
Warning: [minor] Tag 'SubSecTimeDigitized' not defined - ./g.dng
Warning: No writable tags set from ./g.dng
Warning: [minor] Tag 'SubSecTimeDigitized' not defined - ./a.jpg
Warning: No writable tags set from ./a.jpg
    1 directories scanned
    4 image files updated
    3 image files unchanged


$ ls -lT
total 136248
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32.33-1.nef
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32.33.nef
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19.855-1.jpg
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19.855.jpg
-rw-r--r-- 1 user  group   1111021 27 dic 22:14:32 2002 a.jpg
-rw-r--r-- 1 user  group  27328928 16 oct 12:44:02 2010 f.dng
-rw-r--r-- 1 user  group  15346696  2 oct 12:37:19 2010 g.dng
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 h.avi
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 i.avi


Maybe using the ^ modifier? But I couldn't figure how!

This is using macOS.

Thanks in advance. And congratulations for such excellent program!

StarGeek

You can do multiple assignments on the same line and the last valid one will be executed. 

So when you use
exiftool -d '%Y-%m-%d %H.%M.%S' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' .

For files that have SubSecTimeDigitized defined, then -FileName<${DateTimeOriginal}.${SubSecTimeDigitized}%-c.${FileTypeExtension} will be executed.  For files that don't have SubSecTimeDigitized defined (the ones that return Warning: No writable tags set ...), then -FileName<${DateTimeOriginal}%-c.${FileTypeExtension} be used as that is the last valid assignment.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

vicmarto

#2
Thanks for your answer. Yes, I knew about this option, but tried to not use it because the ExifTool command would be extremely large. But seems there is no other solution.


My idea is to automatically rename my photos to the shooting time and date. But, this is not so easy in practice, there are different ways to do it. My problem is that, over the years, I have accumulated photos from many different cameras. And each camera, especially the old ones, keep the shooting time and date in different tags:

· Sometimes on DateTimeOriginal
· Sometimes in CreateDate
· Sometimes in ModifyDate
· Sometimes in two or all of them

But sometimes also in stranger tags like MetadataDate! But can be even worse, without any time and date and must fallback to FileModifyDate.

Therefore, it seems that the only solution to my photos is something like:

exiftool \
-ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' \
-d '%Y-%m-%d %H.%M.%S' \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' \
'-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \ -overwrite_original DIR


But now, there is another problem: photos in burst. It would be great to be able to use the SubSec for them. But this has another problem, there are three tags for the subseconds!!: SubSecTimeDigitized, SubSecTimeOriginal and SubSecTime. So, what is the best way to solve this then? Triplicating the previous command?!!:

exiftool \
-ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' \
-d '%Y-%m-%d %H.%M.%S' \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' \
'-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
'-FileName<${MetadataDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' \
'-FileName<${MetadataDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' \
'-FileName<${MetadataDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTime}%-c.${FileTypeExtension}' \
-overwrite_original DIR


Such a long command is crazy.


Fortunately, it seems that:
· Photos that have SubSecTimeDigitized always have also CreateDate
· Photos that have SubSecTimeOriginal always have also DateTimeOriginal
· Photos that have SubSecTime always have also ModifyDate

With that, using several conditions, a shorter command can be made (and more efficient?):


exiftool \
-if '(not $SubSecTimeDigitized) and (not $SubSecTimeOriginal) and (not $SubSecTime)' \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
-execute \
-if '($SubSecTimeDigitized)' \
'-FileName<${FileModifyDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' \
-execute \
-if '($SubSecTimeOriginal)' \
'-FileName<${FileModifyDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' \
-execute \
-if '($SubSecTime)' \
'-FileName<${FileModifyDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTime}%-c.${FileTypeExtension}' \
-common_args -ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' -d '%Y-%m-%d %H.%M.%S' -overwrite_original DIR


But using this approach I think that the photos with all three SubSec tags would be renamed three times..



Which command is preferable?

And more importantly: Is this the correct way to approach this problem? There is a better way?

THANKS IN ADVANCE!

Phil Harvey

Using -if conditions is not the way to do it.

As you have observed, the subsec tags each relate to one of the other EXIF date/time tags.  So the arguments don't have to be triplicated, just duplicated.  The first technique of using multiple arguments to all set FileName is the way to do it.  I would use the -@ option to read all of the arguments from a file when the argument list gets long like this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

vicmarto

Thanks Phil for your answer!

First technique then, I forget the about the -if conditions    :)

But, I don't get something, why just duplicated?

I would need:

· One line for the files without any type of SubSec:
'-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}'

· Another one for the files with SubSecTimeDigitized:
'-FileName<${MetadataDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeDigitized}%-c.${FileTypeExtension}'

· Another one for the files with SubSecTimeOriginal:
'-FileName<${MetadataDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTimeOriginal}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTimeOriginal}%-c.${FileTypeExtension}'

· And finally, another one for the files with SubSecTime:
'-FileName<${MetadataDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${ModifyDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${CreateDate}.${SubSecTime}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}.${SubSecTime}%-c.${FileTypeExtension}'

Sorry, don't get it  :o

;D

Phil Harvey

Something like this:

exiftool -@ my.args DIR

with this my.args file:

-d
<some date formatting code>
-FileName<${MetadataDate}%-c.${FileTypeExtension}
-FileName<${ModifyDate}%-c.${FileTypeExtension}
-FileName<${CreateDate}%-c.${FileTypeExtension}
-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}
-FileName<${MetadataDate}.${SubSecTime}%-c.${FileTypeExtension}
-FileName<${ModifyDate}.${SubSecTime}%-c.${FileTypeExtension}
-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}
-FileName<${DateTimeOriginal}.${SubSecTimeOriginal}%-c.${FileTypeExtension}


because as you pointed out, SubSecTimeOriginal should only exist if DateTimeOriginal exists, etc.  See the SubSec tags in the EXIF Tags documentation for these relationships.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Phil, there's no % date code for subsec values to allow the use of the composite SubSecCreateDate, SubSecDateTimeOriginal, and SubSecModifyDate, correct?

Would creating a shortcut and using -sep "." be viable?  Something like
MySubSecCreateDate=> ['CreateDate','SubSecTimeDigitized'],

I faintly recall previously doing something like that, but not for a date type tag.

Edit: Found it.  Required the addition of the -m (ignoreMinorErrors) option
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Quote from: StarGeek on February 24, 2019, 12:48:39 PM
Phil, there's no % date code for subsec values to allow the use of the composite SubSecCreateDate, SubSecDateTimeOriginal, and SubSecModifyDate, correct?

Right.

QuoteWould creating a shortcut and using -sep "." be viable?  Something like
MySubSecCreateDate=> ['CreateDate','SubSecTimeDigitized'],

Interesting.  Yes, this could be done but it involves using a config file which isn't very convenient, and I don't think it simplifies the situation very much.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

vicmarto

Quote from: Phil Harvey on February 24, 2019, 11:11:38 AM
Something like this:

exiftool -@ my.args DIR

with this my.args file:

-d
<some date formatting code>
-FileName<${MetadataDate}%-c.${FileTypeExtension}
-FileName<${ModifyDate}%-c.${FileTypeExtension}
-FileName<${CreateDate}%-c.${FileTypeExtension}
-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}
-FileName<${MetadataDate}.${SubSecTime}%-c.${FileTypeExtension}
-FileName<${ModifyDate}.${SubSecTime}%-c.${FileTypeExtension}
-FileName<${CreateDate}.${SubSecTimeDigitized}%-c.${FileTypeExtension}
-FileName<${DateTimeOriginal}.${SubSecTimeOriginal}%-c.${FileTypeExtension}


because as you pointed out, SubSecTimeOriginal should only exist if DateTimeOriginal exists, etc.  See the SubSec tags in the EXIF Tags documentation for these relationships.

- Phil

Thanks Phil! Worked perfectly, very grateful to you.