Author Topic: Deleting bad binary UserComment data  (Read 892 times)

jwdevel

  • Newbie
  • *
  • Posts: 3
Deleting bad binary UserComment data
« on: November 19, 2019, 05:49:47 AM »
I have a camera that sometimes produces binary junk in the UserComment EXIF tag (0x9286).

I have a program which processes images, and one of the things it does is (1) detect this junk and (2) remove it.

This was working in the past, but maybe I have a newer ExifTool or something else changed...

In my current state, I can detect the problem but the deletion is not working.
But maybe the way detection happens is having side-effects, so let me show that first:

I make this call early in my program:

Code: [Select]
    AddUserDefinedTags(
            'Image::ExifTool::Exif::Main',
            0x9286 => {
                Name => 'UserComment',
                Format => 'undef',
                # No RawConv, which normally would be there, thwarting our
                # attempts to look at the real data.
                },
        ); 

If I don't do this, then when I look at the 'UserComment' tag, I do *not* see the garbage binary data.
I forget where I learned this trick, so if it is not the right way, then please educate me.

I am reading the value with:

Code: [Select]
    $et->GetValue('UserComment', 'Raw');

And as I say, that part seems to work.

So, now I've detected it, and want to delete it.
So far, I had been using:

Code: [Select]
    $et->SetNewValue('UserComment');
    ...
    $et->WriteInfo($filename);

But the bad data is still there afterwards.

Some tidbits:

* This command does delete the tag fully:
Code: [Select]
exiftool -UserComment= file.jpg
If I run that with '-v4', I see in the output:

Code: [Select]
    Deleting XMP-exif:UserComment
    Deleting ExifIFD:UserComment

* However, when I run my own command with verbosity turned on, I only see:

Code: [Select]
    Deleting XMP-exif:UserComment

Perhaps this explains the discrepancy, but how do I accomplish the same in my code, rather than running exiftool?
I'm not sure what "-UserComment=" is really accomplishing, and it has been difficult deciphering that program ):

In case it is helpful, here is the (edited) output of "exiftool -v3 file.jpg", in one of the bad cases:

Code: [Select]
  ExifByteOrder = II
  + [IFD0 directory with 13 entries]
  | 0)  ImageWidth = 4032
  |     - Tag 0x0100 (4 bytes, int32u[1]):
...
  | + [ExifIFD directory with 31 entries]
  | | 0)  ExposureTime = 0.05882352941 (1/17)
  | |     - Tag 0x829a (8 bytes, rational64u[1]):
...
  | |   Found IFD at offset 0x02dc in maker notes:
  | | + [MakerNotes directory with 7 entries]
  | | | 0)  MakerNoteVersion = 0100
  | | |     - Tag 0x0001 (4 bytes, undef[4]):
  | | |         02e6: 30 31 30 30                                     [0100]
...
  | | | 6)  FaceDetect = 0
  | | |     - Tag 0x0100 (2 bytes, int16u[1]):
  | | |         032e: 00 00                                           [..]
  | | 18) UserComment = ASCII.JKJK'..|.........~..|..|......".......V..m...;.......H...[snip]
  | |     - Tag 0x9286 (4980 bytes, undef[4980]):
  | |         033e: 41 53 43 49 49 00 00 00 0a 00 00 00 4a 4b 4a 4b [ASCII.......JKJK]
  | |         034e: 27 10 1b 7c f2 fd 00 00 9d 07 01 00 07 a9 01 00 ['..|............]
  | |         035e: f0 7e 01 00 01 00 00 00 00 7c ff ff 00 7c ff ff [.~.......|...|..]
  | |         036e: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [................]
  | |         037e: 00 00 00 00 80 00 85 00 c9 11 22 8a 01 00 00 00 [..........".....]
  | |         [snip 4900 bytes]

At the end, you can see the garbage-filled UserComment tag.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3806
Re: Deleting bad binary UserComment data
« Reply #1 on: November 19, 2019, 11:08:09 AM »
Just to let you know, Phil, the author of exiftool, is away until some time next week.  It'll probably be a bit of a wait to get an answer on this.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

jwdevel

  • Newbie
  • *
  • Posts: 3
Re: Deleting bad binary UserComment data
« Reply #2 on: November 19, 2019, 02:27:48 PM »
Thanks for the heads up (:

jwdevel

  • Newbie
  • *
  • Posts: 3
Re: Deleting bad binary UserComment data
« Reply #3 on: November 19, 2019, 03:31:31 PM »
Well, after some experimentation today, I found that adding

Code: [Select]
    Writable => 'undef',

gets it working again.

I also added:

Code: [Select]
    Binary => 1,

since that seemed likely relevant, but I'm not 100% sure what that flag does.

I still would be interested in confirmation that this is all correct, though (:

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16734
    • ExifTool Home Page
Re: Deleting bad binary UserComment data
« Reply #4 on: November 25, 2019, 12:24:20 PM »
The "Binary => 1" definition just causes ExifTool to show the "Binary data XXX bytes" message instead of trying to print the data when extracting.

Yes.  Setting Writable to 'undef' will allow it to be written.  You don't need to set Format for reading since that is taken from the EXIF format type.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).