how to set tag from filename

Started by gnorf, December 05, 2021, 05:41:11 AM

Previous topic - Next topic

gnorf

Hello,

ich have a big collection of fotos and videos.
The media have all the same nameformat.
YYYYMMDD_HHMMSS.ss_Collection.Ext

for example:
20200821_153211.00_England.MP4
20200902_163434.48_England.JPG

The two numbers after the point are the subsec of a foto. All videos ar set to zero.

Some videos and fotos have a wrong filecreation date. the date is set to date if it was moved to my NAS.
I fixed it with the following command:
exiftool . -r -ext mp4 -ext mov -ext jpg "-FileCreateDate<CreateDate" -if "$FileCreateDate ge '2020:09:06'" -if "$CreateDate ge '1900'"


So i changed all FileCreateDates to the CreateDate if the date is in this example after the travel (when i moved the files to my NAS).
And only the files with have a set CreateDate.

Now i want to fix the not set CreateDate to the date/time of the filename.

it tried this:
exiftool . -r -ext mp4 -ext mov -ext jpg "-CreateDate<FileName" -if "$CreateDate le '1900'"


But it wont work because the .00_England.MP4 irritates the exiftool.

i tried also the option -s %YYYYMMDD_HHMMSS. but it wont work, too.

How can i ignore the text with the dot an the part behind to set the CreatDate Tag?
can anyone help me with the comandline option to solve thiis problem?

Edit:
Before opening this thread i searched the forum and found nothing.
After posting i found several threads.
this one for example:
https://exiftool.org/forum/index.php?topic=13035.0
I tried to modify the filter an it seems to work fine. But i didn't understand the filter and i suppose it is not really poor modified an can make problems in the future

Now it seems to work. But i think it is not perfect.
now i tested this command(s):
exiftool . *.mp4 "-alldates<filename" -api "filter=s/^(\d{6})00/${1}01/;s/(.{18}).*/$1/;$_"
exiftool . *.mp4 "-fileCreateDate<createDate" "-fileModifyDate<createDate"


the second command seems to work. but i have an offset of two hours:
======== ./20200829_184557.12_England.mov
File Creation Date/Time         : 2020:08:29 18:45:57+02:00
File Modification Date/Time     : 2020:08:29 18:45:57+02:00
File Name                       : 20200829_184557.12_England.mov
Date/Time Original              : 2020:08:29 18:45:57.12
Create Date                     : 2020:08:29 18:45:57.12
Modify Date                     : 2020:08:29 18:45:57.12
    1 directories scanned
    7 image files read


How can i modify the actual Date with the correct timezone?

StarGeek

Quote from: gnorf on December 05, 2021, 05:41:11 AM
it tried this:
exiftool . -r -ext mp4 -ext mov -ext jpg "-CreateDate<FileName" -if "$CreateDate le '1900'"

But it wont work because the .00_England.MP4 irritates the exiftool.

In what way does it "irritate" exiftool?  It works correctly here
C:\>exiftool -P -overwrite_original "-CreateDate<Filename" Y:\!temp\aa\bbb\20200821_153211.00_England.MP4
    1 image files updated

C:\>exiftool -g1 -a -s -CreateDate Y:\!temp\aa\bbb\20200821_153211.00_England.MP4
---- QuickTime ----
CreateDate                      : 2020:08:21 15:32:11
---- XMP-xmp ----
CreateDate                      : 2020:08:21 15:32:11


Quote
I tried to modify the filter an it seems to work fine. But i didn't understand the filter and i suppose it is not really poor modified an can make problems in the future

Now it seems to work. But i think it is not perfect.
now i tested this command(s):
exiftool . *.mp4 "-alldates<filename" -api "filter=s/^(\d{6})00/${1}01/;s/(.{18}).*/$1/;$_"
exiftool . *.mp4 "-fileCreateDate<createDate" "-fileModifyDate<createDate"

For the filename example you give, that filter doesn't do much.  The first substitution s/^(\d{6})00/${1}01/ doesn't do anything and the second one s/(.{18}).*/$1/ removes anything after the first 18 characters.    You can test it by using that filter to display the filename with that filter
C:\>exiftool -filename -api "filter=s/^(\d{6})00/${1}01/;s/(.{18}).*/$1/;$_" Y:\!temp\aa\bbb\20200829_184557.12_England.MP4
File Name                       : 20200829_184557.12

All it does is keep the numbers, including the sub-seconds.  But the part that is removed shouldn't affect copying the filename into the date anyway, see FAQ #5, third paragraph.

Quotethe second command seems to work. but i have an offset of two hours:
======== ./20200829_184557.12_England.mov
File Creation Date/Time         : 2020:08:29 18:45:57+02:00
File Modification Date/Time     : 2020:08:29 18:45:57+02:00
File Name                       : 20200829_184557.12_England.mov
Date/Time Original              : 2020:08:29 18:45:57.12
Create Date                     : 2020:08:29 18:45:57.12
Modify Date                     : 2020:08:29 18:45:57.12
    1 directories scanned
    7 image files read


How can i modify the actual Date with the correct timezone?

The timezone part of the FileCreateDate/FileModifyDate dates are set by the location that your computer has been set to.  On that date, in your computer's location, the time zone was +02:00.  This cannot be changed, nor should it.  If the location where the video was taken was not in a +02:00 timezone, then that needs to be accounted for when writing the data and that will require a more complex command.  Your computer will automatically adjust that time stamp to your current time zone.

I'm guessing that you are in CET timezone (CEST at the time of the video) and the video was taken in WET (WEST at the time of the video)?

As an additional problem, the timestamps in video files are supposed to be set to UTC and Windows/Mac will automatically adjust the time zone when you look at the properties.  See the fourth paragraph on the Quicktime tags page.  So these tags also need to be adjusted in order to be correct.  This can be done using the -api QuickTimeUTC option.

I would suggest this as the command to use, assuming video was taken in a +01:00 time zone
exiftool -api QuickTimeUTC  "-AllDates<${Filename;m/^(\d+_\d+)/;$_=$1} +01:00" "-FileCreateDate<${Filename;m/^(\d+_\d+)/;$_=$1} +01:00" "-FileModifyDate<${Filename;m/^(\d+_\d+)/;$_=$1} +01:00" /path/to/files/

For files taken in non-Summertime time zones, you would need to adjust the time zone appropriately.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

gnorf

Ok,

it seems that i dont understand anything ;-)

So i start at the beginning:

now i tried
exiftool "-filename" -api "filter=s/^(\d{8}\d{6})/${1}/;s/(.{15}).*/$1/;$_" d:\exiftool\20200824_165453.00_England.MP4

it seems it does the job.
i checked it with the following line:
exiftool "-ModifyDate" "-createDate" "-FileCreateDate" "-fileModifyDate" d:\exiftool\20200824_165453.00_England.MP4

i get the following result.
Modify Date                     : 2020:08:24 16:54:53.00
Create Date                     : 2020:08:24 16:54:53.00
File Creation Date/Time         : 2020:08:24 16:54:53+02:00
File Modification Date/Time     : 2020:08:24 16:54:53+02:00


that looks fine.

My problem now ist that i don't understand the filter.
I need only a filter with cut of the part with starts with the point to removes .00_England.MP4 from 20200824_165453.00_England.MP4

exiftool "-filename" -api "filter=s/^(\d{8}.\d{6})/${1}/;s/(.{15}).*/$1/;$_" d:\exiftool\20200824_165453.00_England.MP4 seems to do the Job but i do not understand why.

the first part may matches 8 numbers followed by any char followed by 6 numbers.
i don't know with does the ${1}
the ;s/(.{15}).*/$1/ seems to cuts the result at the 15th char.
the /$1/;$_ seems to be needed.

That too much "seems"

i only need a filter with checks eight numbers followed by 6Numbers witch is seperated by the underscore and cuts the rest. So i can move it to the four Tags.

Then i can delete all file with mp4_original extension

Can you please fix/modify my filter or explain it to me, please???
I tried several times to understand the regex filters. But i understand only some little parts of the whole filter.


Today i tried  five hours and don't understand anything.
Maybe https://perldoc.perl.org/perlre should explain it well. But i really don't understand the whole regex


Phil Harvey

Quote from: gnorf on December 05, 2021, 04:18:29 PM
exiftool "-filename" -api "filter=s/^(\d{8}\d{6})/${1}/;s/(.{15}).*/$1/;$_" d:\exiftool\20200824_165453.00_England.MP4

QuoteI need only a filter with cut of the part with starts with the point to removes .00_England.MP4 from 20200824_165453.00_England.MP4

-api "filter=s/\..*//" will remove the "." and everything after it.

Quoteexiftool "-filename" -api "filter=s/^(\d{8}.\d{6})/${1}/;s/(.{15}).*/$1/;$_" d:\exiftool\20200824_165453.00_England.MP4 seems to do the Job but i do not understand why.

s/(.{15}).*/$1/ removes everything after the first 15 characters.

Quotethe first part may matches 8 numbers followed by any char followed by 6 numbers.
i don't know with does the ${1}

$1 (or ${1}) represents everything that matched in the first set of brackets.  So s/^(\d{8}.\d{6})/${1}/ is replacing the first 8 digits + 1 character + 6 digits with the same string.  ie) it is doing nothing.

- 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 ($).

gnorf

Quote from: Phil Harvey on December 06, 2021, 08:53:18 AM
-api "filter=s/\..*//" will remove the "." and everything after it.

thanks, for the support. It does a perfect job :)

The other solution with s/(.{15}).*/$1/ won't work. I dont know why