News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

How to copy filenames into .jpg metadata?

Started by hanso5, October 23, 2017, 04:32:31 PM

Previous topic - Next topic

hanso5

Hello everyone,

im new here and a newbie regarding exiftool. I hope you can help me out with a little problem that i got and that should not be a problem for you at all.
I'm using Windows 10 right now and like to sort my photos within the windows explorer and filling the metadata of the .jpgs over the details pane. Right now I'm looking for a way to copy the filenames of files within a folder into the "title" property/metadata of the files, but without the .jpg extension in an easy to use way. For example:

Filename: London123.jpg -> Title: London123

I've found three lines of code that worked well in this forum, posted by Phil Harvey. Those three are:

exiftool "-title<${filename;s/\..*?$//}"

exiftool "-title<${filename;s/^.{11}(.*)\..*$/$1/}"
exiftool "-title<${filename;$_=substr($_,11);s/\..*?$//}"



The last two do the same and are handy to substract characters from the filename that gets copied into "title". For example (11 characters in this case):

Filename: 7382904821_London.jpg -> Title: London

Thats all good till here, but now here come my questions.

1: How can i substract backwards with he last two code lines, meaning if the filename was London_7382904821, it wouldnt delete me the first 11 but the last 11 characters?
What do the many Symbols at the end of each code mean by the way? Deleting the extension?

2: I want an easy way to drag and drop files or whole folders onto either the .exe or batch file. I tried doing a .bat file with code someone suggested that looked like that, but didnt work:

He wrote: "Put this in a .bat file and replace "echo" with your command:"

:LOOP
if "%~1"=="" goto :END
echo %1
shift
goto :LOOP
:END


I've tried to replace "echo" with and without the "exiftool" part and nothing worked. It only created a "exiftool" file with 0 bytes. Can someone write me a batch file, fix this one or tell me a way to make drag and drop onto the exiftool.exe work? It would be good to have the substract code parts from above in it, so i can replace the number of characters manually in the batch when i want to change it.

3.1: Right now i want copy Filename to Title. I might want to replace the properties from time to time found in this table from StarGeek: https://exiftool.org/forum/index.php/topic,6591.msg32875.html#msg32875
Do i understand correctly that if I write "Title<" instead of "XPTitle<", I change the XMP Format instead of the EXIF Format? Does it matter at all? Can a .jpg file have several metadata formats (EXIF,XMP,IPTC) at the same time at all? Like I said, im a new to this. I explain it now (you have to check the linked table):

3.2: I expermented a bit with the "Title" property and found also that the priority of the metadata tags is important (like the table says).
For example, when i used "-XPTitle<${filename" on photos (named "a (1).jpg", "a (2).jpg" etc) without any Title metadata, it copied the filename into the Title metadata (the one seen by the Windows detail pane) without problem. Then i used "-Title<${filename" on the same files that had now the XPTitle metadata embedded (i renamed the files before of course to "b (1).jpg" etc, otherwise you wouldnt see the difference) and they also changed their Title to "b (1)" etc. Am I right that at this point the file has two Title metadata embedded at the same time, one XMP:Title, the other EXIF:XPTitle? Because if i would start from top of the priority chain (First XMP:Title then EXIF:XPTitle) with also fresh files without metadata, it didnt change the Title in the Windows Detail Pane from "a (1)" to "b (2)" after executing exiftool but it seems that XPTitle got embedded into the file anyway. Is that the case, but because of the priority chain Windows is showing me only the Format with the highest priority. In this case XMP:Title?

3.3: When looking at the "Comments" Windows property in the linked table, how do i know which metadata format is used when i replace the code with "-UserComment<${filename;s/\..*?$//}"? The EXIF and XMP are both named "UserComment"?

I think thats all for now, i hope you can follow me. It would be good if you could answer in the numbered way i asked the questions. Questions 1: and 2: are the most important, the others not so much. Thanks

StarGeek

Ok, there's a lot to work with here, so if I skip something or mess something up, make sure to bring it up.

Quote from: hanso5 on October 23, 2017, 04:32:31 PM
Right now I'm looking for a way to copy the filenames of files within a folder into the "title" property/metadata of the files, but without the .jpg extension in an easy to use way.

If you just wanted to remove the extension, there is also the option of downloading and installing the example config file.  That creates a new tag called BaseName which is the filename without the extension.

Quote1: How can i substract backwards with he last two code lines, meaning if the filename was London_7382904821, it wouldnt delete me the first 11 but the last 11 characters?

To delete the last 11, you could use ${filename;s/^(.*).{11}\..*$/$1/}".  As you can see, I've swapped the (.*) and .{11}.

QuoteWhat do the many Symbols at the end of each code mean by the way? Deleting the extension?

All of those symbols are a complicated and very power programming tool know as Regular Expressions (RegEx).  RegEx isn't that easy to learn, but it can be very use in programming and in using exiftool.  You can check this site (Regex101.com) where I've already placed the regex above into it and you can see the step by step breakdown of every symbol.  You can either mouse over each symbol in the top text box or read the long explanation in the upper right.

RegEx is too big of a subject to teach here, but if you want I can post some links or you can google up some sites.

Quote2: I want an easy way to drag and drop files or whole folders onto either the .exe or batch file. I tried doing a .bat file with code someone suggested that looked like that, but didnt work:

This actually leads to Common Mistake 3 and wouldn't be the fastest way.

You can simply make a bat file with just your exiftool command in it instead of a filename, use %*.  You can then drag and drop files and/or directories onto the bat file.  If you include any percent signs in the exiftool command, you do have to double them (but not the %* part).

In the case of copying filename to title, a bat file could simply be (just add your own filename edits)
exiftool -P -overwrite_original "-title<Filename" %*

Quote3.1:Do i understand correctly that if I write "Title<" instead of "XPTitle<", I change the XMP Format instead of the EXIF Format?  Does it matter at all? Can a .jpg file have several metadata formats (EXIF,XMP,IPTC) at the same time at all?

You don't change the format, you add a different tag.  EXIF, IPTC, and XMP are the three major groups of tags.  There are many others, see Phil's tag names page. The tag groups aren't exclusive.  You can have (and often do) have EXIF, IPTC, and XMP tags all in the same file.  Some of them even have the same name.  For example, Headline can be both an IPTC tag and an XMP tag and both types can be in the same tag without conflict.  They can even hold different data, though that leads to a problem with reconciliation. 

Quote3.2: I expermented a bit with the "Title" property and found also that the priority of the metadata tags is important (like the table says).
For example, when i used "-XPTitle<${filename" on photos (named "a (1).jpg", "a (2).jpg" etc) without any Title metadata, it copied the filename into the Title metadata (the one seen by the Windows detail pane) without problem. Then i used "-Title<${filename" on the same files that had now the XPTitle metadata embedded (i renamed the files before of course to "b (1).jpg" etc, otherwise you wouldnt see the difference) and they also changed their Title to "b (1)" etc. Am I right that at this point the file has two Title metadata embedded at the same time, one XMP:Title, the other EXIF:XPTitle? Because if i would start from top of the priority chain (First XMP:Title then EXIF:XPTitle) with also fresh files without metadata, it didnt change the Title in the Windows Detail Pane from "a (1)" to "b (2)" after executing exiftool but it seems that XPTitle got embedded into the file anyway. Is that the case, but because of the priority chain Windows is showing me only the Format with the highest priority. In this case XMP:Title?

You're losing me a bit, so correct me if I'm wrong.  You're starting with file "a (1).jpg", then coping the filename into XMP:Title.  You then rename it to "b (1).jpg", and then copy filename into XPTitle.  And then when you check Windows properties, you only see "a (1).jpg". 

Now the file (renamed to "b (1).jpg") has an XMP:Title with a value of "a (1).jpg" and an XPTitle with a value of "b (1).jpg".  Windows will show "a (1).jpg" under properties.  If you run the command exiftool -XMP:Title= "b (1).jpg", this will remove the XMP:Title tag.  If you check under Windows properties now, it will show a value of "b (1).jpg" since that's the next available tag that Windows uses to file the Title Property.

This is actually how I test this.  I have a file with over a thousand tags filled out with unique data (often the full tag name).  I then check to see what a program, or in this case, Windows, fills the data from.  I take note of the result, then remove that tag and check again until it doesn't show any data.

One problem I've run across, though, is that the metadata isn't necessarily in a certain order in the image file and some programs will fill their details with whatever it encounters first or last.  Windows definitely has a priority to each item so that was a relief.

Quote3.3: When looking at the "Comments" Windows property in the linked table, how do i know which metadata format is used when i replace the code with "-UserComment<${filename;s/\..*?$//}"? The EXIF and XMP are both named "UserComment"?

From the docs on writing tags:
" If no group name is specified, the tag is created in the preferred group, and updated in any other location where a same-named tag already exists. The preferred group is the first group in the following list where TAG is valid: 1) EXIF, 2) IPTC, 3) XMP."

So in the case of UserComment, it will be written to EXIF:UserComment and if XMP:UserComment exists, it will also be updated.  If you wanted to be specific, you could write specifically to each tag and even fill them with different data:
exiftool -XMP:UserComment="One Comment" -EXIF:UserComment="Different Comment" "a (1).jpg"
Windows, in this case, would only show "Different Comment" under Properties
* 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

(wow, stargeek.  You should be careful not to spend too much time on these long answers)

- 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

I was tempted to post "Wait, I'm typing" or split each answer up into a separate post. 
* 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).

hanso5

#4
Thank you alot for your lenghty reply! I think you answered most i wanted to know. Maybe some other questions arose now. I will mark them bold.

QuoteIf you just wanted to remove the extension, there is also the option of downloading and installing the example config file.  That creates a new tag called BaseName which is the filename without the extension.

I keep that in mind, but right now i will stick to the other Code you and Phil provided.

QuoteTo delete the last 11, you could use ${filename;s/^(.*).{11}\..*$/$1/}".  As you can see, I've swapped the (.*) and .{11}.

Awesome, it works very well. Thanks.

QuoteAll of those symbols are a complicated and very power programming tool know as Regular Expressions (RegEx).  RegEx isn't that easy to learn, but it can be very use in programming and in using exiftool.  You can check this site (Regex101.com) where I've already placed the regex above into it and you can see the step by step breakdown of every symbol.  You can either mouse over each symbol in the top text box or read the long explanation in the upper right.

RegEx is too big of a subject to teach here, but if you want I can post some links or you can google up some sites.

Thank you. If i want to learn more i will google it. I also put the site into my bookmarks. I think I understand the regex you have placed there, but there are some symbols missing like the starting "s/" or the ending "/S1/". And if i put them into regex101 it displays an error. I guess those are parts of the exiftool language, that cant be read by regex101 right?
The 3 code lines from my first post end also differently, two of them with "\..*?$//" , one time with "\..*$/$1/". The results of both are the same so i guess those are just different ways of writing the part that deletes the extension?

QuoteThis actually leads to Common Mistake 3 and wouldn't be the fastest way.

You can simply make a bat file with just your exiftool command in it instead of a filename, use %*.  You can then drag and drop files and/or directories onto the bat file.  If you include any percent signs in the exiftool command, you do have to double them (but not the %* part).

In the case of copying filename to title, a bat file could simply be (just add your own filename edits)
exiftool -P -overwrite_original "-title<Filename" %*

Oh my god i was so close to finding it out already. I didnt mention it because i thought i was heading in the wrong direction anyway. I only had to change "%1" to your "%*". Ok, i didnt had the "-P -overwrite_original" part there too. Im going to borrow them  ;) . But first, what does the "-P" command/option do?
I have tested all out and im very happy with the results now. Thanks alot.



QuoteYou're losing me a bit, so correct me if I'm wrong.  You're starting with file "a (1).jpg", then coping the filename into XMP:Title.  You then rename it to "b (1).jpg", and then copy filename into XPTitle.  And then when you check Windows properties, you only see "a (1).jpg". 

Now the file (renamed to "b (1).jpg") has an XMP:Title with a value of "a (1).jpg" and an XPTitle with a value of "b (1).jpg".  Windows will show "a (1).jpg" under properties.  If you run the command exiftool -XMP:Title= "b (1).jpg", this will remove the XMP:Title tag.  If you check under Windows properties now, it will show a value of "b (1).jpg" since that's the next available tag that Windows uses to file the Title Property.

This is actually how I test this.  I have a file with over a thousand tags filled out with unique data (often the full tag name).  I then check to see what a program, or in this case, Windows, fills the data from.  I take note of the result, then remove that tag and check again until it doesn't show any data.

One problem I've run across, though, is that the metadata isn't necessarily in a certain order in the image file and some programs will fill their details with whatever it encounters first or last.  Windows definitely has a priority to each item so that was a relief.

Yes that is exactly what i meant, you summarized it correctly. Thanks for the clarification. I even wanted to ask for a command that deletes individual format tags like your code here, but my questions became too many :P.  I tried your code to remove the XMP:Title and it indeed works like i thought also. So it seems that the best way is to use the tags with the highest priority when using Windows, since that would avoid problems like the "a (1)"/ "b (1)" stuff, even if the chances arent that high, at least in the way i manage my photos.
I also just found out that when you make an entry into the Title property directly in the Windows Detail Pane of a file that has no metadata yet, it adds tags to 4 of the 5 Tags shown in the table, except the "IPTC:Caption-Abstract" one. Till now i thought for no apparent reason that it just adds the EXIF:XPTitle tag (maybe because the XP* tags are Windows specific) . That means if you would execute exiftool "-XPTitle<Filename..." the files that got an entry previously through the Windows Detail Pane wouldn't show the new tag in Windows, since the XMP:Title tag is still there. If i don't have an error in my thinking.

QuoteFrom the docs on writing tags:
" If no group name is specified, the tag is created in the preferred group, and updated in any other location where a same-named tag already exists. The preferred group is the first group in the following list where TAG is valid: 1) EXIF, 2) IPTC, 3) XMP."

So in the case of UserComment, it will be written to EXIF:UserComment and if XMP:UserComment exists, it will also be updated.  If you wanted to be specific, you could write specifically to each tag and even fill them with different data:
exiftool -XMP:UserComment="One Comment" -EXIF:UserComment="Different Comment" "a (1).jpg"
Windows, in this case, would only show "Different Comment" under Properties

Thats good to know. But how comes that exiftool(-k).exe doesn't show the -XMP:UserComment entry there? I wanted to check if both are shown there, but it's not the case. It's well hidden and Windows Search is also not aware of the tag by the way, which isnt that of a problem. But when I deleted the EXIF:UserComment tag with exiftool, it revealed the XMP:UserComment entry in Windows indeed.

I got a last question here: Is it possible to do the same filename to metadata stuff with .mp4 files? I checked the Tag Table Index for MPEG and H264, but i can't find tags there that match the ones from Windows like Title, Subtitle, Tags, Comments. Maybe a table like the JPEG & Tif table from StarGeek is need here too or cant exiftool handle .mp4 files? I used tags like "Title<" , "Comment<", "Keywords<" , it seems they get embedded but dont show up in the Windows Detail Pane. Don't know what im doing wrong here.

hanso5

Quote from: StarGeek on October 23, 2017, 10:08:01 PM
I was tempted to post "Wait, I'm typing" or split each answer up into a separate post.

You did it perfectly. I never thought that i get answers that quickly and detailed. So no need to split up the post. Or did Phil mean that you shouldnt spend so much of your precious time for Newbies like me?  ;D

StarGeek

Warning - while you were typing a new reply has been posted. You may wish to review your post.

I don't care, I already typed out this wall of text, I'm posting it!!  :D

edit: Oh, ok, no big deal.  Ignore the above.

Quote from: hanso5 on October 24, 2017, 12:37:21 AM
Thank you. If i want to learn more i will google it. I also put the site into my bookmarks. I think I understand the regex you have placed there, but there are some symbols missing like the starting "s/" or the ending "/S1/".

That's not /S1/, it's /$1/ (DollarSignOne).  If you look at the Regex101 site, you'll notice that it already puts slashes on either side of the part in the text box.  You'll also notice the $1 is in the lower halve of the page, under substitution.

To break it down, in Perl (which exiftool was written in), the RegEx Substitution command is s/Search/Replace/Options.  No options were used in this command so that can be ignored.  In this command the search part is ^(.*).{11}\..*$ and the replace part is $1.  Without getting too deep into regex, the parens around the .* are a capture and will save what ever matches.  The $1 is the variable the first capture (you can have multiple) is saved in and it is used to replace the whole thing.

QuoteAnd if i put them into regex101 it displays an error.

To play with the site, just use the parts between the first and second slashes (as long as the second slash isn't following a backslash, which is a sign to escape it) and then again between the second and third for the substitution part.

Most every language has some form of regex and not all of them use slashes as the separator.

QuoteThe 3 code lines from my first post end also differently, two of them with "\..*?$//" , one time with "\..*$/$1/".

Partially, the second one is incomplete and needs the capture parens part that should be before it.  But pop \..*?$ into Regex101, put text that looks like a filename with extension below it and you can read the details by mousing over each part.


QuoteOh my god i was so close to finding it out already. I didnt mention it because i thought i was heading in the wrong direction anyway. I only had to change "%1" to your "%*".

Yeah, batch file writers love their for loops.  But they also don't tell you about some gotchas that can happen depending upon how you run the bat file.

QuoteOk, i didnt had the "-P -overwrite_original" part there too. Im going to borrow them  ;) . But first, what does the "-P" command/option do?

The -overwrite_original will prevent the creation of "_original" backup files.  Best not to use it until you have the command perfect.

The use of the -P option can be esoteric.  It preserves the FileModifyDate of the filesystem.  For most people, they shouldn't care about it.  The fact that it changes when the file changes helps programs like backup software detect files that have changed since the last backup.  But some people don't want this.  It could be something about their system or their backup software.  Or maybe it's an old file from before the time when digital cameras wrote the time the picture was taken into the EXIF data.  One of my very old Mavica cameras was like that.  Either that or I stupidly removed EXIF chucks without realizing back in the late 90s when I was playing around with image formats.  That's one reason why I keep that option.

QuoteI also just found out that when you make an entry into the Title property directly in the Windows Detail Pane of a file that has no metadata yet, it adds tags to 4 of the 5 Tags shown in the table, except the "IPTC:Caption-Abstract" one.

I'll have to double check but I think I have a note that if the file doesn't already have IPTC data, Windows won't write it.  Oh, there it is on that page under notes.  I never followed up on it though. *Puts it back on the very long to do list*

QuoteThat means if you would execute exiftool "-XPTitle<Filename..." the files that got an entry previously through the Windows Detail Pane wouldn't show the new tag in Windows, since the XMP:Title tag is still there.
Quote

That sounds correct.

QuoteThats good to know. But how comes that exiftool(-k).exe doesn't show the -XMP:UserComment entry there?

FAQ 3.  Without the -a option, exiftool will suppress tags with duplicate names.  In this case, EXIF:UserComment has priority over XMP:UserComment.  Hmmm...  I'm not sure if that follows the same EXIF/IPTC/XMP priority or not.  Never thought about it before.
* 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).

hanso5

Warning - while you were typing a new reply has been posted. You may wish to review your post.

QuoteI don't care, I already typed out this wall of text, I'm posting it!!  :D

edit: Oh, ok, no big deal.  Ignore the above.

You might have missed my EDIT, asking about .mp4 files, but i will repost it at the end of this post :)


Quote
Quote from: hanso5The 3 code lines from my first post end also differently, two of them with "\..*?$//" , one time with "\..*$/$1/".
Partially, the second one is incomplete and needs the capture parens part that should be before it.  But pop \..*?$ into Regex101, put text that looks like a filename with extension below it and you can read the details by mousing over each part.

Ok i have played a bit around. Yes the second is missing the capture part. I think i understand it better now, the second one at least. For the first one, it seems the question mark (I dont understand the explanation for it on the site ;D) is not necessary to have the same result, correct? Seems to work anyway. And since it doesn't need a substitution (because the code "-title<${filename;s/\..*?$//}" is not meant to capture something -> only to delete the extension) , it is also missing the "$1/"-part. But why does it have two slashes at the end? After answering that i think the beginner teaching lessons were quite successful and I at least know what the different parts of the code do.

QuoteThe -overwrite_original will prevent the creation of "_original" backup files.  Best not to use it until you have the command perfect.

The use of the -P option can be esoteric.  It preserves the FileModifyDate of the filesystem.

Ok. I need to see how my backup tool handles it first before using it. Good to know.

Quote from: hanso5
QuoteThats good to know. But how comes that exiftool(-k).exe doesn't show the -XMP:UserComment entry there?

FAQ 3.  Without the -a option, exiftool will suppress tags with duplicate names.  In this case, EXIF:UserComment has priority over XMP:UserComment.  Hmmm...  I'm not sure if that follows the same EXIF/IPTC/XMP priority or not.  Never thought about it before.

Nice that a noob like me can make an expert think too  :) . I'm not sure about it but doesn't your table
https://exiftool.org/forum/index.php/topic,6591.msg32875.html#msg32875
suggest otherwise? When you look at the Rating property's Duplicate Tags in the "Tags Read" column, XMP:RatingPercent has priority. I was interested to know which one exiftool shows without the -a option. I wrote:
exiftool -P -overwrite_original -XMP:Ratingpercent="75" -EXIF:Ratingpercent="25" FILE
exiftool(-k).exe showed the XMP:Ratingpercent with "75" and the stars in Windows Detail Pane became 4 of 5 stars, although the "Rating" tag which indicates the amount of stars didn't appear in exiftool(-k).exe, means not automatically created. When you manually set the stars in Windows Detail Pane to 4 of 5, it creates two "Rating" and two "RatingPercent" tags when you check it with exiftool(-k -a).exe. Just like Windows creates all EXIF and XMP "Title" entries when you manually write into the Windows Detail Pane's "Title"-Tag, it creates here also all Tags. So no, the "EXIF/IPTC/XMP priority" seems not to have an effect here. I have no questions left regarding this.

Let me ask you the question regarding .mp4 again: Is it possible to do the same filename to metadata stuff with .mp4 files? I checked the Tag Table Index for MPEG and H264, but i can't find tags that are matching. Like "MP4:subtitle" . Maybe a table like the JPEG & Tif table from you is needed here too or cant exiftool handle .mp4 files? I did entries in the Windows Detail Pane calling them all "ccccccccc1", "ccccccccc2" etc. With help of the -a option i could find the following tag entries in exiftool(-k).exe:
"Title", "Comment", "Subtitle", "Category" (which seems to be the equivalent of JPEG's Tag property "keywords"). So I can do entries manually in Windows and find them in exiftool. But to use those tags in cmd/batch and make them appear in Windows does not work like it does with .jpgs. Not sure what to do next.

Take your time to answer. I'm really happy with the help here and those last questions are minor problems that are not so important.

StarGeek

Quote from: hanso5 on October 24, 2017, 05:09:43 AM
For the first one, it seems the question mark (I dont understand the explanation for it on the site ;D) is not necessary to have the same result, correct?

It depends upon your incoming data.  To break it down.

\. - The slash is the escape character.  It escapes the next character, the dot, so it will be treated as a dot, not the wild card (see next).

$ - Skipping ahead to the dollar sign, it anchors to the end of the string.

.*? - The dot . is a wild card for a single character (a few exceptions, but not getting into that).  It's the similar to a question mark in a Windows CMD.  The asterisk says that the previous character will be repeated Zero or more times.  It's important to remember that "Zero or more" for letter, but no need to worry about it here.  Normally, regex is "Greedy".  It will grab as much as possible.  For most filenames, dot \. plus anything else .* until the end of the string $ is just going to be the extension.

But what if there's another dot in the file.  If your first file was "Family_Photo.jpg", then you edited it and named the new photo "Family_Photo_Ver2.0.jpg"?  Now Regex finds the first dot, and the grabs everything else until the end ".0.jpg".  You've grabbed more than just the extension.

The Question Mark after the DotAsterisk .*? is the Non-Greedy modifier.  This tells regex to just grab the extention in the case of "Family_Photo_Ver2.0.jpg".


QuoteBut why does it have two slashes at the end?

Remember, the command is s/Search/Replace/Options.  Your search part is \..*?$ (find the extension).  And you're replacing it with nothing.  So you put nothing between the slashes that surround Replace.

QuoteNice that a noob like me can make an expert think too  :) . I'm not sure about it but doesn't your table
https://exiftool.org/forum/index.php/topic,6591.msg32875.html#msg32875
suggest otherwise? When you look at the Rating property's Duplicate Tags in the "Tags Read" column, XMP:RatingPercent has priority.

Sorry if I wasn't clear.  The "EXIF/IPTC/XMP" priorty ONLY applies to exiftool when it is writing tags.  All other programs figure out their own priorities on reading and writing, which is something that prompted me to try and document their behavior and end up thoroughly frustrated.

QuoteIs it possible to do the same filename to metadata stuff with .mp4 files?

To a degree, yes.  Exiftool has limited ability to write to video files.  It can write XMP data and a few other tags, but most programs don't read XMP data.  Adobe (Lightroom and Bridge) do, and will write XMP as well.  Windows doesn't.

QuoteI checked the Tag Table Index for MPEG and H264, but i can't find tags that are matching. Like "MP4:subtitle" . Maybe a table like the JPEG & Tif table from you is needed here too or cant exiftool handle .mp4 files?

A table is needed, but then comes the problem of finding a way to write/remove that data so as to figure out priorities.  Windows doesn't read XMP data.  Additionally, when you write those items through Windows Properties, it writes a lot of them to Microsoft XTRA tags.  The problem there is that as far as I can tell, almost NOTHING writes to those tags.  I found one program that will write some of those tags (not all of them), but it isn't obvious that it can do so because it's marketed as an MP3 editor, even though it can write MP4 tags.

QuoteSo I can do entries manually in Windows and find them in exiftool. But to use those tags in cmd/batch and make them appear in Windows does not work like it does with .jpgs. Not sure what to do next.

Which, unfortunately, seems to be the only way.
* 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).

hanso5

Thanks again.

QuoteBut what if there's another dot in the file.  If your first file was "Family_Photo.jpg", then you edited it and named the new photo "Family_Photo_Ver2.0.jpg"?  Now Regex finds the first dot, and the grabs everything else until the end ".0.jpg".  You've grabbed more than just the extension.

The Question Mark after the DotAsterisk .*? is the Non-Greedy modifier.  This tells regex to just grab the extention in the case of "Family_Photo_Ver2.0.jpg".

That's very weird. Because i tried it out now with and without the ?, and in both cases the filename was deleted from the first dot on till the end.
From "family_2.0_photo.jpg" to "family_2". I used those both:

exiftool "-title<${filename;s/\..*$//}"
exiftool "-title<${filename;s/\..*?$//}"


This one works fine and shows "family_2.0_photo" even without ?:

"-title<${Filename;s/^(.*).{0}\..*$/$1/}"

Why aren't the first working no matter the ? but the third works all the time even without ? (except you put it next to the first asterisk inside the brackets). I mean you don't need to explain the code to me in detail, I was just wondering if i better use a ? in the code i use from now on (third one) if the filename ever contains something like "ver2.0" or so. Seems i can leave it like that.


Quote

Remember, the command is s/Search/Replace/Options.  Your search part is \..*?$ (find the extension).  And you're replacing it with nothing.  So you put nothing between the slashes that surround Replace.

Ah, now i kinda get it.

QuoteSorry if I wasn't clear.  The "EXIF/IPTC/XMP" priorty ONLY applies to exiftool when it is writing tags.  All other programs figure out their own priorities on reading and writing, which is something that prompted me to try and document their behavior and end up thoroughly frustrated.

Im a bit confused and still don't get why writing priority does matter at all for the end user experience. Isn't it per se irrelevant in which priority it writes tags? In which case would it important? Reading priority can be important as we've seen it with dublicate tags like "UserComment" or "RatingPercent", because that determines what is being displayed (or not displayed) to the user at the end. How did you even manage to find out the writing priorities of Windows Properties in your table? Maybe im just to dumb to understand the concept of writing.


QuoteA table is needed, but then comes the problem of finding a way to write/remove that data so as to figure out priorities.  Windows doesn't read XMP data.  Additionally, when you write those items through Windows Properties, it writes a lot of them to Microsoft XTRA tags.  The problem there is that as far as I can tell, almost NOTHING writes to those tags.  I found one program that will write some of those tags (not all of them), but it isn't obvious that it can do so because it's marketed as an MP3 editor, even though it can write MP4 tags.

Isn't there a standard metadata format for .mp4? So when i write something into the .mp4 "Subtitle" tag in Windows, it uses the XTRA format? And on other Operating Systems they couldnt be read anymore? Can you tell the name of the MP3 editor? Not that im gonna use it, i bet it can't mass rename filenames to metadata tags like exiftool.

StarGeek

Quote from: hanso5 on October 25, 2017, 12:37:04 AM
That's very weird. Because i tried it out now with and without the ?, and in both cases the filename was deleted from the first dot on till the end.
From "family_2.0_photo.jpg" to "family_2".

Yep, you're right.  See how complex regex is? I consider myself decent with regex and I still get caught by something like this.

So here is a better one.
s/\.[^.]*$//

\. - Find a dot, same as before.
[^.]* - The brackets indicate a list of characters.  Not a string, individual characters.  The caret negates the characters in this list.  So this means zero or more (that's the asterisk) Non Dot characters until the end of the string.

At this point it's like I'm messing with you, but really, I'm not doing it on purpose.

QuoteSorry if I wasn't clear.  The "EXIF/IPTC/XMP" priorty ONLY applies to exiftool when it is writing tags.  All other programs figure out their own priorities on reading and writing, which is something that prompted me to try and document their behavior and end up thoroughly frustrated.

To reiterate the docs:
"If no group name is specified, the tag is created in the preferred group, and updated in any other location where a same-named tag already exists. The preferred group is the first group in the following list where TAG is valid: 1) EXIF, 2) IPTC, 3) XMP."

Using the case of UserComment.  In a clean file that has no metadata, if you write to UserComment, only EXIF:UserComment will be created.  XMP:UserComment will not be created unless you are specific about writing to XMP.  This would especially become important to remember in the case of RatingPercent.  If run exiftool -RatingPercent=25 CleanFile.jpg then exiftool is only going to write to EXIF:RatingPercent (assuming no RatingPercent tags previously exist).  If some other program comes along, is ignorant of the EXIF tag, and only writes to XMP:RatingPercent, let's say setting it to 75, then Windows is going to read XMP:RatingPercent and not the EXIF:RatingPercent because Windows gives each of these tags a different priority.

There are a couple of powerful ways exiftool can deal with such craziness, but those are advanced subjects
*insert Starship Troopers Would You Like to Know More? Meme here*

QuoteIm a bit confused and still don't get why writing priority does matter at all for the end user experience.

There is no writing priority for windows.  I don't mention priority in the tags written column.

QuoteIsn't there a standard metadata format for .mp4?

I believe Phil has said, many times, that video metadata formats are very inconsistent.  And I'm pretty sure he uses stronger language in private.

QuoteSo when i write something into the .mp4 "Subtitle" tag in Windows, it uses the XTRA format?

Where was that file I was using to test.  Ah, writing Subtitle in Windows Property Details writes to both Quicktime:SUBTITLE (strange, comes back as all caps) and Microsoft:Subtitle (which is in the XTRA atom of the video).  Video Atoms are something you'll have to research on your own.  That's where I pulled all my hair out and ran screaming down the hall.

QuoteCan you tell the name of the MP3 editor? Not that im gonna use it, i bet it can't mass rename filenames to metadata tags like exiftool.

There's nothing wrong with using it, it's a pretty respected MP3 metadata editor from what I recall.  But that was after over an hour of forum rabbit hole after rabbit hole (xkdc : Wisdom of the Ancients).  Dang it, Google history used to show me what links I clicked.  That would have been so useful. 

I think this is it
MP3Tag.
* 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).

hanso5


QuoteYep, you're right.  See how complex regex is? I consider myself decent with regex and I still get caught by something like this.

Please don't throw any new code at me, my head is steaming already. But could you find out what the purpose of the ? was when Phil put it in the code? Other than that, all my questions regarding regex are answered :)

QuoteUsing the case of UserComment.  In a clean file that has no metadata, if you write to UserComment, only EXIF:UserComment will be created.  XMP:UserComment will not be created unless you are specific about writing to XMP.  This would especially become important to remember in the case of RatingPercent.  If run exiftool -RatingPercent=25 CleanFile.jpg then exiftool is only going to write to EXIF:RatingPercent (assuming no RatingPercent tags previously exist).  If some other program comes along, is ignorant of the EXIF tag, and only writes to XMP:RatingPercent, let's say setting it to 75, then Windows is going to read XMP:RatingPercent and not the EXIF:RatingPercent because Windows gives each of these tags a different priority.

There are a couple of powerful ways exiftool can deal with such craziness, but those are advanced subjects
*insert Starship Troopers Would You Like to Know More? Meme here*
QuoteThere is no writing priority for windows.  I don't mention priority in the tags written column

Now everything makes sense! https://i.giphy.com/media/TnLAlrs7f0DMQ/source.gif
No need to know more, except if there is the slightest chance that they don't mess up the Starship Troopers reboot that got announced last year  ;D


QuoteWhere was that file I was using to test.  Ah, writing Subtitle in Windows Property Details writes to both Quicktime:SUBTITLE (strange, comes back as all caps) and Microsoft:Subtitle (which is in the XTRA atom of the video).  Video Atoms are something you'll have to research on your own.  That's where I pulled all my hair out and ran screaming down the hall.

How can you find out the name of the format when a tag is written on a file? I mean the "Quicktime:" and "Microsoft:". Exiftool only shows the tag name "Subtitle", so how do you do this wizardry?

QuoteThere's nothing wrong with using it, it's a pretty respected MP3 metadata editor from what I recall.  But that was after over an hour of forum rabbit hole after rabbit hole (xkdc : Wisdom of the Ancients).  Dang it, Google history used to show me what links I clicked.  That would have been so useful. 

I think this is it
MP3Tag.

lol. Oh nice, i actually use MP3Tag myself. I tried .mp4 now and it works, at least for the "Title" and "Comment" tags that i might need. Just like you said not all, "Subtitle" i can't get to work for example. On the "converter" tab in mp3tag you can  convert "filename - tag" (mark all the files you want to convert at once before), put %title% into the box and press ok. It copies it without the extension and without substracting characters. Maybe there is a way but i don't need it for .mp4 files for the moment.

Phil Harvey

#12
Quote from: StarGeek on October 25, 2017, 01:40:31 AM
Quote from: hanso5 on October 25, 2017, 12:37:04 AM
That's very weird. Because i tried it out now with and without the ?, and in both cases the filename was deleted from the first dot on till the end.
From "family_2.0_photo.jpg" to "family_2".

Yep, you're right.  See how complex regex is? I consider myself decent with regex and I still get caught by something like this.

As you see, I've fallen for this one too.  But the "\." will match the first dot.  It doesn't look for another dot as long as the rest of the expression is satisfied.  I've updated the old post to fix this.

I got this right in one of the copying examples in the exiftool documentation:

       exiftool "-Description<${FileName;s/\.[^.]*$//}" dir
            Set the image Description from the file name after removing the
            extension.  This example uses the "Advanced formatting feature" to
            perform a substitution operation to remove the last dot and
            subsequent characters from the file 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 ($).

StarGeek

Quote from: hanso5 on October 25, 2017, 05:14:04 AM
Please don't throw any new code at me, my head is steaming already. But could you find out what the purpose of the ? was when Phil put it in the code?

Since the code wasn't quite working as intended anyway for the situation of multiple dots, it wasn't needed.

QuoteHow can you find out the name of the format when a tag is written on a file? I mean the "Quicktime:" and "Microsoft:". Exiftool only shows the tag name "Subtitle", so how do you do this wizardry?

Add -g1 (or -G1) to the command.  They both add the group name to the listing, but in slightly different formats.  Remember, you'll also need the -a option to show duplicates.

C:\>exiftool -g1 -a -s -subtitle  Y:/!temp/Test5.mp4
---- QuickTime ----
SUBTITLE                        : Subtitle
---- Microsoft ----
Subtitle                        : Subtitle

C:\>exiftool -G1 -a -s -subtitle  Y:/!temp/Test5.mp4
[QuickTime]     SUBTITLE                        : Subtitle
[Microsoft]     Subtitle                        : Subtitle


* 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).

hanso5

Thank you both. I got the feeling that we are almost done here :) Except :

Quotewriting Subtitle in Windows Property Details writes to both Quicktime:SUBTITLE (strange, comes back as all caps) and Microsoft:Subtitle (which is in the XTRA atom of the video)

QuoteAdd -g1 (or -G1) to the command.  They both add the group name to the listing, but in slightly different formats.  Remember, you'll also need the -a option to show duplicates.

C:\>exiftool -g1 -a -s -subtitle  Y:/!temp/Test5.mp4
---- QuickTime ----
SUBTITLE                        : Subtitle
---- Microsoft ----
Subtitle                        : Subtitle

C:\>exiftool -G1 -a -s -subtitle  Y:/!temp/Test5.mp4
[QuickTime]     SUBTITLE                        : Subtitle
[Microsoft]     Subtitle                        : Subtitle


There are four Windows Detail Pane properties on .mp4 files i might wanna use: Title, Subtitle, Comment and Tags (which is the "category" tag in exiftool).
I filled the properties of a file without metadata in Windows manually with "zzzzzzzzzzzzz1/2/3/4".
When i used this exiftool -g1 -a -subtitle -title -category -comment on the file, it showed me the following:

---- QuickTime ----
Title                    : zzzzzzzzzzzzzzzzzzz1
Comment                  : zzzzzzzzzzzzzzzzzzz4
---- Microsoft ----
Subtitle                  : zzzzzzzzzzzzzzzzzzz2
Category                  : zzzzzzzzzzzzzzzzzzz3


No dublicates like in your case. Maybe you have added a "Quicktime:SUBTITLE" metadata already with another tool and didn't delete it before testing? Or because you are using a different Windows than me. I'm using Windows 10. Any ideas on this last question?