trying to edit the MakerNotes:Samsung:Time:Main:TimeStamp tag

Started by Matt Birkel, June 08, 2024, 12:44:23 PM

Previous topic - Next topic

Matt Birkel

Discolure: I'm relatively new to exiftool.

I discovered this thread because I'm trying to edit the MakerNotes:Samsung:Time:Main:TimeStamp tag (SamsungTrailer_0x0a01), but I'm having trouble getting it to work.  Given the TimeStamp is just an integer which represents ms since epoch, I thought it should be fairly easy and safe to edit this tag.

Here's my current script:

#!/usr/bin/perl
use warnings;
use strict;
use Image::ExifTool;

my $exiftool = Image::ExifTool->new;

sub check_exiftool_error {
  if (defined $exiftool->GetValue('Error')) {
    print 'EXIFTOOL ERROR: ' . $exiftool->GetValue('Error') . "\n";
    exit;
  }
}

sub get_updated_file ($) {
  my ($file) = @_;
  my ($file_without_extension) = $file =~ m/(.*)\.[^\\\/]+$/;
  my ($file_extension) = $file =~ m/.*(\.[^\\\/]+)$/;
  return $file_without_extension . '_updated' . $file_extension;
}

# See: Editing tags that claim to be non-writable by exiftool:
#   https://superuser.com/questions/1826169/is-it-possible-to-change-tags-that-are-not-writable-by-exiftool
# Source code where tags are defined:
#   https://github.com/exiftool/exiftool/tree/master/lib/Image/ExifTool
%Image::ExifTool::UserDefined = (
  'Image::ExifTool::Samsung::Trailer' => {
    '0x0a01' => { # https://exiftool.org/forum/index.php?topic=7161
      Name => 'TimeStamp',
      Groups => { 2 => 'Time' },
      ValueConv => 'ConvertUnixTime($val / 1e3, 1, 3)',
      ValueConvInv => 'GetUnixTime($val, 1) * 1e3',
      PrintConv => '$self->ConvertDateTime($val)',
      PrintConvInv => '$self->InverseDateTime($val)',
      Writable => 'int16u',
    },
  },
);

sub modify_samsung_makernotes ($) {
  my ($file) = @_;

  $exiftool->SetNewValue('MakerNotes:Samsung:TimeStamp' => '2024:07:01 12:00:00.000-05:00');
  # Also tried:
  # $exiftool->SetNewValue('MakerNotes:Samsung:TimeStamp');
  # $exiftool->SetNewValue('MakerNotes:*');
  check_exiftool_error();

  my $outfile = get_updated_file($file);
  unlink($outfile);
  $exiftool->WriteInfo($file, $outfile);
  check_exiftool_error();
  print("Successfully wrote file. Newly written file's tags:\n");

  my $tags_ref = $exiftool->ImageInfo($file);
  check_exiftool_error();
  foreach my $tag_key (sort {lc $a cmp lc $b} keys %$tags_ref) {
    my $tag_key_with_groups = $exiftool->GetGroup($tag_key, ':0:1:2:3') . ":$tag_key";
    check_exiftool_error();
    # Only print the tags in the MakerNotes:Samsung:Time group.
    next if ($tag_key_with_groups !~ m/MakerNotes:Samsung:Time/);
    print("  $tag_key_with_groups => $tags_ref->{$tag_key}\n");
  }
}
modify_samsung_makernotes('Test_Photo.jpg');

When I overrode the tag definition for '0x0a01', it failed at first because I didn't have a ValueConvInv and PrintConvInv.  I took my best stab at implementing these by looking through exiftool source code for examples.

When I run this script, the TimeStamp remains unchanged on the updated image file.  I'm not sure why... exiftool doesn't report any errors.

I also tried to delete the tag, but I get an error: "Can't delete Permanent tag Samsung:TimeStamp".

Last, I tried to delete the whole MakerNotes block.  The script finishes successfully, but again, it doesn't actually cause the desired change to occur.  The MakerNotes block is still present in the updated image file.

Am I missing something?

StarGeek

If you check the Samsung tags page, you will see that the Samsung:TimeStamp tag cannot be edited. Additionally, individual MakerNotes in general cannot be deleted or created.
* 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).

Matt Birkel

#2
Why can't the Samsung:TimeStamp tag be edited?  If I understand correctly, it's just a sequence of 13 bytes.  If exiftool knows the offset of those bytes in the file, then what's preventing it from rewriting those bytes?

My understanding was that the documentation which you linked is representative of the tag definitions in the source code. However, I've overwritten the tag definition for Samsung:TimeStamp in my script. Why doesn't that work?

Regarding deleting the entire MakerNotes block -- I found  this post from 2016.  Running this via the exiftool CLI similarly has no effect on my image file.

StarGeek

Quote from: Matt Birkel on June 08, 2024, 02:19:21 PMWhy can't the Samsung:TimeStamp tag be edited?  If I understand correctly, it's just a sequence of 13 bytes.  If exiftool knows the offset of those bytes in the file, then what's preventing it from rewriting those bytes?

Samsung decided not to use the standard MakerNotes location in the EXIF block.  Instead, they decide to add this data as a trailer to the file. And code hasn't been written for exiftool to write the Samsung trailer, only to read it.

QuoteMy understanding was that the documentation which you linked is representative of the tag definitions in the source code. However, I've overwritten the tag definition for Samsung:TimeStamp in my script. Why doesn't that work?

If you look at the entry for TimeStamp, you will see that it is listed with "no" in the "Writable" column. Exiftool can read it but cannot write it.
Clipboard_06-08-2024_01.png

QuoteRegarding deleting the entire MakerNotes block -- I found  this post from 2016.  Running this via the exiftool CLI similarly has no effect on my image file.

Because it is in the trailer rather than the standard MakerNotes location, it has to be deleted with
exiftool -Trailer:all= /path/to/files/

Overall, you shouldn't worry about this tag. Exiftool and exiv2 are probably the only programs that can actually read this data.

You can look at this StackOverflow answer for some help on how to edit the data with a hex editor.
* 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).