I have a software program that I am using that uses the exif user comment for the data field. I would like to edit the date and time in the user comment(see highlighted area on screenshot) to match the datetimeorignal tag without changing the rest of the comment. Can you tell me what I can do?
I have also attached one of the photos.
You can do this with the advance formatting feature and this rather complicated command:
exiftool "-usercomment<${usercomment;s/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} .M/$self->GetValue('DateTimeOriginal')/e}" -d "%Y-%m-%d %l:%M:%S %p" FILEorDIR
The only thing is that when you are done the UserComment will be formatted properly, whereas in the original it is written incorrectly (lucky ExifTool is so smart, or it wouldn't have been read it in the first place).
- Phil
I am not getting a date and time. See attached
It appears that it would also need to be formatted the same way, because the software no longer recognizes the keywords in the comment.
I take it you figured out the problem resulting in the Screen.PNG output? What was it?
If so, and the software requires an incorrectly written EXIF:UserComment, then you will need to override the ExifTool definition with a user-defined tag to be able to write it improperly like this.
- Phil
No, I didn't figure out the problem in the screen.png. It is just when the comment was changed the software looked to the file modify date for a date instead of the incorrectly written EXIF:UserComment.
But the software does not see the keywords anymore that are in the correctly written EXIF:UserComment.
Ok, I tried it again with exiftool 10.78 now. It just removed the date completely from the usercomment.
Error in the date format string, I think.
Try -d "%Y-%m-%d %H:%M:%S %p" instead.
I used %l instead of %H because it gives a 12-hour clock. Didn't try to see if this works on Windows though. But even so, I don't understand the empty UserComment.
- Phil
Ah. I guess it doesn't work on windows then and the whole thing gets blanked.
C:\>exiftool -DateTimeOriginal -DateTimeOriginal# -d "%Y-%m-%d %l:%M:%S %p" "Y:\!temp\!abr\2016-04-20 19-39-36.jpg"
Date/Time Original :
Date/Time Original : 2016:04:20 19:39:36
On Windows it looks like it needs to be %I:
C:\>exiftool -DateTimeOriginal -DateTimeOriginal# -d "%Y-%m-%d %I:%M:%S %p" "Y:\!temp\!abr\2016-04-20 19-39-36.jpg"
Date/Time Original : 2016-04-20 07:39:36 PM
Date/Time Original : 2016:04:20 19:39:36
You're right. It should have been %I (capital I). I mis-read my documentation, but an odd coincidence that %l (lower case L) worked for me. However, it only gives a single digit for times less than 10, so it wasn't the right one to use anyway, especially since it doesn't work in Windows.
- Phil
Ok, I tested it and it did change the date now. But the software I am using does not see the keywords in the comment anymore. Apparently it need to have it in the same incorrect format that it was in before. Is there anyway to have exiftool keep it in the same format as before? I have attached a photo that was formatted by the software.
Yes. As I mentioned, you need to create a user-defined tag to do this. This config file will do it:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Exif::Main' => {
0x9286 => {
Name => 'UserComment',
Format => 'undef',
Writable => 'undef',
},
},
);
1; #end
- Phil
I am not sure how to use the config file. Do you have somewhere I can learn how to use it?
The sample config file (https://exiftool.org/config.html) contains instructions and examples.
Also, you could search the Appliction documentation (https://exiftool.org/exiftool_pod.html) for "config".
- Phil
Is there anyway that I can copy the format of the incorrect formatted image to a correctly formatted image?
This is what I have just shown you how to do using the config file I provided, which will write in the incorrect format to any type of file.
- Phil
I have tried the config file. It seems like does not change the format of the files. It just updates the values and keeps it in the same format.
You have to be more specific. The new config file will write the UserComment incorrectly as a string instead of the standard EXIF format. Is this the format you are talking about? If so, what do you mean when you say it isn't changed? And what are you doing to determine the format?
- Phil
I don't know alot about specific formats. But here is a screen shot of the config file. The only difference I can see is the ASCII in the user comment that is working for me.
If the ASCII UserComment works for you, then you don't need the config file. The config file writes the UserComment without the standard ASCII header.
- Phil
I meant that the ASCII header doesn't work. :-[
If I use the config file it doesn't always write it without the ASCII header.
The config file will write a new UserComment without the ASCII header, or copy an existing UserComment without changing its format. If you want to remove the ASCII header from a properly-formatted UserComment, use this config file:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Exif::Main' => {
0x9286 => {
Name => 'UserComment',
Format => 'undef',
Writable => 'undef',
ValueConv => '$val =~ s/^ASCII\0+//; $val',
},
},
);
1; #end