[Originally posted by exiftool on 2007-12-18 17:22:53-08]The
-d option doesn't allow you to use subseconds, so
you have 2 other options:
1) create a user-defined tag to do exactly what you want. See
the
config file documentation for details on how to add user-defined
tags.
2) use the %c (copy number) format code available with the
-doption instead of sub seconds to distinguish images taken within the
same second. There is an example of this in the
RENAMING
EXAMPLES section of the application documentation.
- Phil
[Originally posted by ryand on 2007-12-21 03:17:57-08]I came up with this, and it will work. Any time SubSecTimeOriginal is undefined, it seems to default to 0, but, I think it would be better to define it to 00 (or 99 or whatever) if it is undefined. I don't know Perl so this is the best I could hack together. I hashed out the line that should define SubSec if it is undefined. Can someone tell me how to do this?
%Image::ExifTool::UserDefined = (
# Composite tags are added to the Composite table:
'Image::ExifTool::Composite' => {
SubSecDTO => {
Description => 'Date/Time Original with Sub Seconds',
Require => {
0 => 'DateTimeOriginal',
},
Desire => {
1 => 'SubSecTimeOriginal',
},
# be careful here in case there is a timezone following the seconds
ValueConv => '$_=$val[0];s/(.*:\d{2})/;$_',
#### I want to define SubSec to 00 if it is undefined. The following line
#### is not working (changed 00 to 99 for testing)
# ValueConv => '$val[1] = defined $val[1] ? $val[1] : 99',
ValueConv => '$self->ConvertDateTime($val)',
PrintConv => 'sprintf("%s%0.2i",$val,$val[1])',
},
},
);
1; #end
[Originally posted by exiftool on 2007-12-21 12:32:44-08]Your main problem seems to be the %0.2i format code,
since it specifies a zero field width so it won't print
anything. The following will work if there is no timezone.
SubSecDTO => {
Description => 'Date/Time Original with Sub Seconds',
Require => {
0 => 'DateTimeOriginal',
},
Desire => {
1 => 'SubSecTimeOriginal',
},
ValueConv => 'sprintf("%s.%.2d", $val[0], $val[1] || 0)',
},
(Here I use the logical "or" operator to set the sub-seconds to zero
if it isn't defined (or is already zero))
But if you expect a timezone, or pre-existing sub-seconds, it
is a bit more work:
ValueConv => q{
return $val[0] if $val[0] =~ /\.\d+/; # return if we already have sub-seconds
my $subSec = sprintf(".%.2d", $val[1] || 0);
$val[0] =~ s/( \d+:\d+:\d+)/$1$subSec/; # insert sub-seconds after time
return $val[0];
},
If you haven't ever used regular expressions, they can be very
cryptic. Here the first regular expression checks for the existence
of sub-seconds in the original date/time value, and the second
substitution expression inserts the new sub seconds after the
time (keying off the space before the time value so they aren't
added after the date instead).
- Phil