Rename Pictures with DateTimeOriginal or FileModifyDate

Started by Spartacus, May 04, 2021, 04:39:58 PM

Previous topic - Next topic

Spartacus

Hi all,
I am struggling with some old photos fron 2003. Some of the files do not have the DateTimeOriginal. If I start my exiftool-command, the files with the missing " DateTimeOriginal"-tag will be ignored and not moved.
exiftool -fileOrder datetimeoriginal '-Filename<DateTimeOriginal' -d /mnt/OUTPUT/%Y/%m-%B/%d-%m-%Y/%Y%m%d%%-.2nc.%%le *.[jJ][pP][gG] -r -P /mnt/INPUT

The FileModifyDates of the remaining fotos look good and I would like to create and copy the date into the "non existing" DateTimeOriginal-Tag to have this date saved in a separate tag.

How can i recursive go to my completenfolderstructure and add the DateTimeOriginal - tag only on the files where the tag is missing. I will not overwrite any file, where the tag is ok.

This command must run first, because I also have to make sure, that the files will be sorted, renamed and numbered in the correct order based on the DateTimeOriginal-Information

How can I achieve this?

Regards,
Spartacus

StarGeek

Quote from: Spartacus on May 04, 2021, 04:39:58 PM
The FileModifyDates of the remaining fotos look good and I would like to create and copy the date into the "non existing" DateTimeOriginal-Tag to have this date saved in a separate tag.

Your command would be along these lines
exiftool -r -wm cg "-DateTimeOriginal<FileModifyDate" /path/to/files

The -wm (-writeMode) option with cg will only create new tags and not edit tags that already exist.

The -r (-recurse) option will recurse into subdirectories.

You might also want to include the -P (-preserve) option to preserve the FileModifyDate which would otherwise change when the file is edited.

This command creates backup files.  Add -Overwrite_Original to suppress the creation of backup files.
* 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).

Spartacus

#2
Hello StarGeek,
thank you so much for this command. It works perfect! But I got some minor Warnings and I don´t know exactly what this means. Do you have an idea?

Warning: [minor] Bad format (23828) for MakerNotes entry 8 - DSC00250.JPG

What about the auto numbering when I run my pervious command after I have updated the tags?  Will the new tags be taken for the correct order in this command?

exiftool -fileOrder datetimeoriginal '-Filename<DateTimeOriginal' -d /mnt/OUTPUT/%Y/%m-%B/%d-%m-%Y/%Y%m%d%%-.2nc.%%le *.[jJ][pP][gG] -r -P /mnt/INPUT


Addendum:
my Issue seems to be much more complex than I thought. Seems to be that the Dates in the tags are not correct. But I have stored all pictures of the specific date in a separate folder with the structure mm-dd-yyyy. All the pictures have a number in the filename which was created by the camara. DSC0001-DSC00nn

The idea is now to use the date from the folder in which the respective picture is for the DateTimeOriginal-Tag and the time should be created from from the running camera number to 0001-00nn to make sure the correct order will not be destroyed! Alternatively the running number should recorded in a tag (but what is the correct tagname and how can the number be extracted from the DSCnnnn)

Any ideas how to proceed?

Christian.

StarGeek

Quote from: Spartacus on May 05, 2021, 03:03:17 AMBut I got some minor Warnings and I don´t know exactly what this means. Do you have an idea?

Warning: [minor] Bad format (23828) for MakerNotes entry 8 - DSC00250.JPG

This is a minor warning which you can just ignore.  What is happening is that exiftool is finding a problem with the MakerNotes, proprietary data related to the camera's settings.  This can happen when a program that doesn't properly handle such data make edits to a file.  See FAQ #15, especially starting at the line "Other types of MakerNote errors".

QuoteWhat about the auto numbering when I run my pervious command after I have updated the tags?  Will the new tags be taken for the correct order in this command?

exiftool -fileOrder datetimeoriginal '-Filename<DateTimeOriginal' -d /mnt/OUTPUT/%Y/%m-%B/%d-%m-%Y/%Y%m%d%%-.2nc.%%le *.[jJ][pP][gG] -r -P /mnt/INPUT

The -FileOrder option will make sure the files are ordered by the DateTimeOriginal in this case, though if you think there may be images shot at the same timestamp (continuous shooting mode), you might want to use SubSecDateTimeOriginal instead, as that will take the subseconds into account.

Also, it's better practice to use the -ext (-extension) option when recursing with exiftool.  See details on the -r (-recurse) option and Common Mistake #2.

exiftool -fileOrder SubSecDateTimeOriginal'-Filename<DateTimeOriginal' -d /mnt/OUTPUT/%Y/%m-%B/%d-%m-%Y/%Y%m%d%%-.2nc.%%le . -ext jpg -r -P /mnt/INPUT

QuoteThe idea is now to use the date from the folder in which the respective picture is for the DateTimeOriginal-Tag and the time should be created from from the running camera number to 0001-00nn to make sure the correct order will not be destroyed! Alternatively the running number should recorded in a tag (but what is the correct tagname and how can the number be extracted from the DSCnnnn)

Any ideas how to proceed?

This sounds like it might be averted by using the SubSecDateTimeOriginal as I detailed above.  Otherwise you'll have to examine the files output to find the image number.  Use the command in FAQ #3 to make sure you get all the data, groups, and duplicate tag names.
* 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).

Spartacus

#4
Hi,
thank you very much for the reply. As mentioned , lots of Tags are missing, therfore also the SubSecDateTimeOriginal. I cannot use this for sorting the files. You can also see in the screenshot, that the LastModifyDate is also not in sync withe the corerct date (see Folder date).

The only option I see is to use the number (DSC00071)  and the folder name (06-16-03)  in which the respective file  is located to fix the tags.  I would like to extract the filenumber from the filename and the date from the foldername in order to write the data as meta-data into the file. After that, I use the commad above to rename all files including the files with correct metadata.

Do you think exiftool supports this? I do not have a clue how this can work!
Spartacus

StarGeek

Quote from: Spartacus on May 05, 2021, 02:21:19 PM
As mentioned , lots of Tags are missing, therfore also the SubSecDateTimeOriginal. I cannot use this for sorting the files. You can also see in the screenshot, that the LastModifyDate is also not in sync withe the corerct date (see Folder date).

I was going off the assumption that the files had been fixed with the previous copy from FileModifyDate.  I must have misunderstood.

QuoteThe only option I see is to use the number (DSC00071)  and the folder name (06-16-03)  in which the respective file  is located to fix the tags.  I would like to extract the filenumber from the filename and the date from the foldername in order to write the data as meta-data into the file. After that, I use the commad above to rename all files including the files with correct metadata.

You can extract the number by using this at the location you want the use the number
${Filename;m/(\d+)/;$_=$1}
and extracting the date from the directory name
${Directory;m/(\d\d)-(\d\d)-(\d\d)/;$_="20$3:$1:$2"}

But I'm not understanding how you want to use the number from the file as part of the data.  71 cannot be used for any part of a date/time value, unless you use it to represent 1971, which obvious isn't the case.

Maybe this is what you want?  First set the base date
exiftool '-DateTimeOriginal<${Directory;m/(\d\d)-(\d\d)-(\d\d)/;$_="20$3:$1:$2"} 00:00:00' /path/to/files/

Then a second command to increment the time for each additional image.  The #2 point there will increment by one minute per image.  This StackExchange answer is an example of incrementing by 10 seconds per image.
* 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).

Spartacus

Hi StarGeek,
thank you very much for our support. I will test the commands tomorrow! (I do not really understand exactly what you are doing here, but this is due to lack of knowledge from my side  :) ) Maybe I misunderstood, but isn´t it possible to write custom tags into the files?

Regards,
Spartacus

StarGeek

I guess I don't understand what you want.  It's possible to create custom tags (see example.config file), but I don't recommend it in most cases.  Why make up a tag when the only thing that will read it is exiftool?
* 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).

Spartacus

Hi,
hm! I thought custom tags can also be red from all other tools including Windows. If not, it makes no sense to add it! I will test it and come back very soon!
Spartacus


Spartacus

Hi StarGeek,
so, I think I know what you mean with the custom tags. I missed the fact, that tags are predefined and that you cannot define whatever you want...

But I think I found a way to get my issues solved:

Step1:
copy Folder Name into DateTimeOriginal, if not exists
exiftool -Overwrite_Original -P -r -wm cg  '-DateTimeOriginal<${Directory;m/(\d\d)-(\d\d)-(\d\d)/;$_="20$3:$1:$2"} 00:00:00' /mnt/INPUT

Step 2:
increment time (e.g. 10s) for all tags where not time is set (00:00:00)
exiftool -Overwrite_Original -P -r -fileOrder Filename '-datetimeoriginal+<0:0:${filesequence;$_*=10}' /mnt/INPUT

Step 3:
move files into the respective folder-structure in OUTPUT based on DateTimeOriginal) and rename files due to existing filename-order (DSC001, DSC002...DSCnnnn)

exiftool -fileOrder Filename '-Filename<DateTimeOriginal' -d /mnt/OUTPUT/%Y/%m-%B/%d-%m-%Y/%Y%m%d%%-.2nc.%%le *.[jJ][pP][gG] -r -P /mnt/INPUT

If I will use the DateTimeOriginal for the correct order, it will not run because some of the original images will have a correct timestamp in DateTimeOriginal. So the orer must be defines by the old filenmae. Otherwise you have to interpolate between two files with the correct timestamp.

DSC0001 10:00:00 -> correct timestamp
DSC0002 00:00:10 -> set by exiftool
DSC0003 00:00:20 -> set by exiftool
DSC0004 11:53:47 -> correct timestamp


Is it correct, or do you see any issues in the workaround above..
Spartacus


StarGeek

Damn, I didn't realize that the files timestamps were so messed up.  Files with and without timestamps mixed together, in sequence like that wouldn't even cross my mind.

I don't see any way to automate that with just exiftool.  That would require something outside of exiftool.

Ok, here's what I would do.  I'd list all the files into a CSV file with this
exiftool -DateTimeOriginal /mnt/INPUT >Temp.csv

Load this CSV into a spreadsheet like Excel or LibreOffice.  The latter is free if you don't already have a spreadsheet program.

For any files that don't already have timestamps, drag the previous cell so that the spreadsheet program will increment the timestamps.  Ignore the filename column in this quicky example


Save the altered spreadsheet.  Make sure it's a CSV using comma, not semicolon, as a separator.

Import the new data into the files.
exiftool -Overwrite_Original -P -r -wm cg -CSV=Temp.csv /mnt/INPUT

That will write the new data into all the files, skipping those that already have data due to the -wm cg.
* 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).

Spartacus

Hi StarGeek,
this is a very good idea! I have exprted the tags and imported the file in Excel. 2003 has round about 3,000 lines with lots of emty dates! Its a great work for the upcomming weekend!

I will come back to you soon!
Soartacus