Update date/time tags only if not empty

Started by aab203, June 07, 2018, 12:07:40 PM

Previous topic - Next topic

aab203

Hello,

First a big thanks for this super useful tool!  I am a novice at using the Terminal (macOS) but I have been messing around with this for the last few days as part of cleaning up 6+ years of photos :).

One area I have come unstuck on is the ability to rename only the already-populate date/time tags for an mp4 file.  The filename contains the correct date in it but for whatever reason all the metadata is incorrect.

This is what I get if I do: exiftool -time:all -g0:1 dst.mp4

---- File:System ----
File Modification Date/Time     : 2018:05:21 16:19:08+01:00
File Access Date/Time           : 2018:06:07 16:54:30+01:00
File Inode Change Date/Time     : 2018:06:07 16:36:11+01:00
---- QuickTime ----
Create Date                     : 2018:05:21 15:19:07
Modify Date                     : 2018:05:21 15:19:08
---- QuickTime:Track1 ----
Track Create Date               : 2018:05:21 15:19:07
Track Modify Date               : 2018:05:21 15:19:08
---- QuickTime:Track2 ----
Media Create Date               : 2018:05:21 15:19:07
Media Modify Date               : 2018:05:21 15:19:08


If I then do exiftool -time:all-= -time:all='2017:11:28 16:13:02' dst.mp4 in the hope of just targetting the non-empty date/time tags, I end up inserting the date/time into all tags.

I'm sure I am missing something obvious!  Any help with the correct command will be greatly appreciated.


On a separate but related query, how can I take part of the filename and use this to populate the date/time fields?  Say my filename is VID_20171128_161302, what's the best way to extract the date/time info?

Many thanks in advance!

StarGeek

Try the -wm (writemode) option with w argument (Write existing tags) e.g. -wm w.

Quote from: aab203 on June 07, 2018, 12:07:40 PM
On a separate but related query, how can I take part of the filename and use this to populate the date/time fields?  Say my filename is VID_20171128_161302, what's the best way to extract the date/time info?

When the filename has all the numbers in the proper order (year month day hour etc), you can just use Filename without having to extract the numbers.  See third paragraph of FAQ #5.
* 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

StarGeek's suggestion about using -wm w is the thing to do.

Your original command was targeting all date/time tags that were missing or empty, which is the opposite of what you wanted.

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

aab203

Thanks both for the super speedy responses!  I had just come across how flexible 'filename' was :)

I tried to incorporate both suggestions, so created a new command, exiftool -wm w '-time:all<filename' ./1-2\ years/VID_20171128_161302.mp4

This hasn't quite worked:


Warning: No writable tags set from ./1-2 years/VID_20171128_161302.mp4
    0 image files updated
    1 image files unchanged


Any ideas?

EDIT: Nevermind, I got the syntax wrong.  I changed to this exiftool -wm w '-time:all<${filename}' ./1-2\ years/VID_20171128_161302.mp4 and it worked :).  It did throw up a warning / suggestion to install Xcode lol - is there a way to bypass that (if not I can live with clicking a button each time!)

Phil Harvey

If you add -v3 you will see the problem:

Sorry, time:FileName doesn't exist or isn't writable

which is true.

The problem is that values are copied to a tag with the same name as the source tag when "all" is used as the destination, which unfortunately isn't what you want.

Maybe try this:

exiftool -wm w '-*date*<filename' DIR

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

aab203

That did the trick, many thanks!  I wish I understood better the subtlety of all these options!  I am learning more each time I mess around though and appreciate the power of this tool.

As a more general query; an area that I typically trip up on is the syntax.  Is someone able to briefly explain why in some cases;


  • The whole tag argument needs a ' wrapped around it, but sometimes not - e.g. -time:all=2017:08:15 19:25:09' vs just -time:all (is this how to differentiate between reading and writing?)
  • When using another tag to populate a tag, sometimes it needs the $ in front of it.  Other times not - e.g. -createDate<fileModifyDate vs -time:all<${filename}
  • Sometimes the use of curly brackets is needed but I'm not sure why

It usually takes me about 2-3 attempts to see what syntax errors I've made before a command finally works (and I'm super grateful for the auto backup of modified files :) )

Phil Harvey

Quote from: aab203 on June 07, 2018, 01:05:52 PM
The whole tag argument needs a ' wrapped around it, but sometimes not - e.g. -time:all=2017:08:15 19:25:09' vs just -time:all (is this how to differentiate between reading and writing?)

This isn't and ExifTool thing.  It is a requirement of the command shell you are using.  If you are on Mac, then you are probably using a bash shell, and "$" and spaces are special characters that need quoting or escaping.  In bash, space can be quoted with either single or double quotes, but "$" must be quoted with single quotes.

QuoteWhen using another tag to populate a tag, sometimes it needs the $ in front of it.  Other times not - e.g. -createDate<fileModifyDate vs -time:all<${filename}

Actually, it isn't necessary in either case (see common mistake 5b).  The $TAG is used for interpolating at tag value within a string.  (the same as "$" is used in bash, which is why it needs to be quoted specially)

QuoteSometimes the use of curly brackets is needed but I'm not sure why

They are only needed to separate the tag name if it is followed immediately by a letter, number, - or _.  Otherwise these would be taken as part of the tag name.

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

aab203