News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Rewriting FNumber and FocalLength tags

Started by SkepticaLee, October 09, 2012, 03:23:09 AM

Previous topic - Next topic

SkepticaLee

With -tagsfromfile Exiftool rewrites the following tags:
FNumber: original, e.g. 40/10, after transfer 4/1
FocalLength: original, e.g. 6000/1000, after transfer 6/1

I was wondering whether this gratuitous behaviour could be omitted, since it corrupts the original information. There is no guarantee that evaluating the expressions that exiftool writes to these tags and the original expressions will result in equivalent numbers. I know that 6000/1000 = 6/1, but e.g. javascript may not. Can't the string expressions be left as they are?

Phil Harvey

Quote from: SkepticaLee on October 09, 2012, 03:23:09 AM
Can't the string expressions be left as they are?

Are you talking about XMP?  FNumber is stored as a string in XMP, but as a numerical rational in EXIF.

Unfortunately, this change is not trivial.  ExifTool's current behaviour is very useful because it allows easy translation between metadata stored in different formats.

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

SkepticaLee

I', talking about the exif tags. When compared to the original exif tags in the original image, the copied exif tags in the target image have been factored and the common factors removed from numerator and denominator; they are still strings, not decimal values, and I always have to rewrite them.

Phil Harvey

In EXIF, FNumber is stored as an 8 byte rational value, so some conversion is necessary since ExifTool presents values as strings.  In your example, the hex byte sequence would be

    00 00 00 28 00 00 00 0a

Which ExifTool converts to the string "4.0" when reading.

Your problem is that in converting "4.0" back to a rational, ExifTool generates this byte sequence:

    00 00 00 04 00 00 00 01

I understand your problem, but don't see an easy solution.  The translation to a string value is necessary, and "4.0" is more readable and more portable than "40/10", and it would break a lot of other things if I changed this.

- Phil

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

SkepticaLee

#4
I still don't get why this rewriting takes place. I am using the PHP function exif_read_data to extract the exif data and observe the following:

$exif = exif_read_data ($exif_source);
// $exif_source is the original; gives FNumber as string "40/10", FocalLength as string "6000/1000"
exec ("exiftool -tagsfromfile $exif_source $entry -overwrite_original");
exif_read_data ($entry);
//  $entry is the target; exif_read_data returns FNumber as string "4/1", FocalLength as string "6/1"
exec ("exiftool -FocalLength=$exif[FocalLength] -FNumber=$exif[FNumber] -overwrite_original $entry");
$exif = exif_read_data ($entry);
// FoclaLength and FNumber transferred directly from source to target; exif_read_data returns FNumber as string "40/10", FocalLength as string "6000/1000" again


Seems to me to require a lot of rewriting and concomitant calls to exiftool.

jozsi

I understand that it is not easy to change this behaviour, but I would also like this feature to appear. I know nothing about the code but there could be an option to store the numerator and the denominator and use these to rewrite rationals.

Phil Harvey

I'm working towards this goal, although I'm still not sure I'll be able to fully implement this.

In ExifTool 9.03 I added a feature to allow a Rational value to be extracted as a fraction.  In version 9.04 I will update the API to allow the Raw Rational value to be written.  So with ExifTool 9.04, the Rational value may be copied using the API with code like this:

#!/opt/local/bin/perl -w
use Image::ExifTool;

my $tag = 'ShutterSpeedValue';
my $src = 'a.jpg';
my $dst = 'b.jpg';

my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($src, $tag);

my $val = $exifTool->GetValue($tag, 'Rational');
$val or die "No Rational value for $tag in $src\n";

$exifTool->SetNewValue($tag => $val, Type => 'Raw');
my $result = $exifTool->WriteInfo($dst);

if ($result == 1) {
    print "Copied $tag of $val from $src to $dst\n";
} elsif ($result == 2) {
    print "$tag was not written\n";
} else {
    print "Error writing $dst\n";
}
# end


The problem will be figuring out how to do this via the command line where the user has the ability to move information between different tags and different metadata formats.

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

goproer

Quote from: Phil Harvey on October 23, 2012, 08:49:15 AM
I'm working towards this goal, although I'm still not sure I'll be able to fully implement this.

In ExifTool 9.03 I added a feature to allow a Rational value to be extracted as a fraction.  In version 9.04 I will update the API to allow the Raw Rational value to be written.  So with ExifTool 9.04, the Rational value may be copied using the API with code like this:

Do you plan that with the command line discussed here (https://exiftool.org/forum/index.php/topic,4519.0.html) that copying is done by the native type? (e.g. Rational value will be copyied exactly by the same rational)

That would mean if you could implement that the command line will make an exact value copy of all values. Guess that it shouldn't be to complicated that everything is done internally only and you store the types when read.
exiftool -P -all= -tagsfromfile @ -all:all -unsafe -exifbyteorder=little-endian *.jpg

Thank you.

goproer

Phil Harvey

Implementing this for rational types is one thing (an I am still not sure that I can do this), but I don't think that making an exact binary copy of all other types is reasonable.  Doing so would introduce a significant negative performance impact with no benefit to most users.  Also, there would be many other problems involved in implementing this.

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