Force UNICODE encoding for UserComment

Started by WolfWalker, October 22, 2022, 10:59:21 AM

Previous topic - Next topic

WolfWalker

I would like to force UNICODE encoding (UCS-2 Big Endian to be exact) for the content of the UserComment tag, even when it doesn't contain any special character.

Is there a command line option or any other chance of doing this?

StarGeek

* 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

The bottom line is that you can't force ExifTool to use UNICODE encoding when writing UserComment if the string contains all ASCII characters.

- Phil

Edit:  Wait.  Strike that.  You could override ExifTool's UserComment tag with a user-defined tag that does exactly what you want. Take a look at the UserComment definition here.  You would copy this definition and change the RawConvInv to this:

        RawConvInv => '"UNICODE\0" . $self->Encode($val,"UTF16",$self->GetNewValue("ExifUnicodeByteOrder"))',
...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

So would this be correct for a stand alone config file?
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Exif::Main' => {
0x9286 => {
Name => 'UserComment',
# I have seen other applications write it incorrectly as 'string' or 'int8u'
Format => 'undef',
Writable => 'undef',
RawConv => 'Image::ExifTool::Exif::ConvertExifText($self,$val,1,$tag)',
#  (starts with "ASCII\0\0\0", "UNICODE\0", "JIS\0\0\0\0\0" or "\0\0\0\0\0\0\0\0")
RawConvInv => '"UNICODE\0" . $self->Encode($val,"UTF16",$self->GetNewValue("ExifUnicodeByteOrder"))',
# SHOULD ADD SPECIAL LOGIC TO ALLOW CONDITIONAL OVERWRITE OF
# "UNKNOWN" VALUES FILLED WITH SPACES
},
},
);
* 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

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