ExifTool Forum

ExifTool => Newbies => Topic started by: Winston on February 09, 2018, 06:45:48 AM

Title: Exif User Comment Edit
Post by: Winston on February 09, 2018, 06:45:48 AM
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.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 09, 2018, 07:29:53 AM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 09, 2018, 12:55:57 PM
I am not getting a date and time. See attached
Title: Re: Exif User Comment Edit
Post by: Winston on February 09, 2018, 01:02:28 PM
It appears that it would also need to be formatted the same way, because the software no longer recognizes  the keywords in the comment.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 09, 2018, 02:26:10 PM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 09, 2018, 05:28:43 PM
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.
Title: Re: Exif User Comment Edit
Post by: Winston on February 09, 2018, 05:55:40 PM
Ok, I tried it again with exiftool 10.78 now. It just removed the date completely from the usercomment.
Title: Re: Exif User Comment Edit
Post by: StarGeek on February 09, 2018, 06:24:57 PM
Error in the date format string, I think.

Try -d "%Y-%m-%d %H:%M:%S %p" instead.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 09, 2018, 10:27:25 PM
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
Title: Re: Exif User Comment Edit
Post by: StarGeek on February 09, 2018, 10:35:30 PM
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
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 09, 2018, 10:46:50 PM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 12, 2018, 12:58:58 PM
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.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 12, 2018, 01:05:55 PM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 12, 2018, 05:59:58 PM
I am not sure how to use the config file. Do you have somewhere I can learn how to use it?
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 12, 2018, 09:20:35 PM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 15, 2018, 06:34:23 AM
Is there anyway that I can copy the format of the incorrect formatted image to a correctly formatted image?
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 15, 2018, 07:11:15 AM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 15, 2018, 08:26:08 AM
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.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 15, 2018, 08:29:02 AM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 15, 2018, 08:48:58 AM
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.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 15, 2018, 08:51:44 AM
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
Title: Re: Exif User Comment Edit
Post by: Winston on February 15, 2018, 12:40:44 PM
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.
Title: Re: Exif User Comment Edit
Post by: Phil Harvey on February 15, 2018, 12:47:27 PM
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