Index: main/trunk/greenstone2/perllib/cpan/Image/ExifTool/H264.pm
===================================================================
--- main/trunk/greenstone2/perllib/cpan/Image/ExifTool/H264.pm	(revision 24107)
+++ main/trunk/greenstone2/perllib/cpan/Image/ExifTool/H264.pm	(revision 34921)
@@ -13,4 +13,5 @@
 #               6) Dave Nicholson private communication
 #               7) http://www.freepatentsonline.com/20050076039.pdf
+#               8) Michael Reitinger private communication (RX100)
 #
 # Glossary:     RBSP = Raw Byte Sequence Payload
@@ -23,6 +24,7 @@
 use Image::ExifTool qw(:DataAccess :Utils);
 use Image::ExifTool::Exif;
-
-$VERSION = '1.06';
+use Image::ExifTool::GPS;
+
+$VERSION = '1.17';
 
 sub ProcessSEI($$);
@@ -35,4 +37,5 @@
     0x0108 => 'Sony',
     0x1011 => 'Canon',
+    0x1104 => 'JVC', #Rob Lewis
 );
 
@@ -62,5 +65,5 @@
         compared to the challenge of actually decoding the data!]>  This information
         may exist at regular intervals through the entire video, but only the first
-        occurrence is extracted unless the ExtractEmbedded (-ee) option is used (in
+        occurrence is extracted unless the L<ExtractEmbedded|../ExifTool.html#ExtractEmbedded> (-ee) option is used (in
         which case subsequent occurrences are extracted as sub-documents).
     },
@@ -82,6 +85,10 @@
     # 0x11 - TitleRemainTime (ref 7)
     # 0x12 - TitleChapterTotalNo (ref 7)
-    # 0x13 - TitleTimecode
-    # 0x14 - TitleBinaryGroup
+    0x13 => {
+        Name => 'TimeCode',
+        Notes => 'hours:minutes:seconds:frames',
+        ValueConv => 'sprintf("%.2x:%.2x:%.2x:%.2x",reverse unpack("C*",$val))',
+    },
+    # 0x14 - TitleBinaryGroup - val: 0x00000000,0x14200130
     # 0x15 - TitleCassetteNo (ref 7)
     # 0x16-0x17 - TitleSoftID (ref 7)
@@ -95,5 +102,5 @@
         # first byte is timezone information:
         #   0x80 - unused
-        #   0x40 - DST flag (not currently decoded)
+        #   0x40 - DST flag
         #   0x20 - TimeZoneSign
         #   0x1e - TimeZoneValue
@@ -101,7 +108,8 @@
         ValueConv => q{
             my ($tz, @a) = unpack('C*',$val);
-            return sprintf('%.2x%.2x:%.2x:%.2x %.2x:%.2x:%.2x%s%.2d:%s', @a,
+            return sprintf('%.2x%.2x:%.2x:%.2x %.2x:%.2x:%.2x%s%.2d:%s%s', @a,
                            $tz & 0x20 ? '-' : '+', ($tz >> 1) & 0x0f,
-                           $tz & 0x01 ? '30' : '00');
+                           $tz & 0x01 ? '30' : '00',
+                           $tz & 0x40 ? ' DST' : '');
         },
         PrintConv => '$self->ConvertDateTime($val)',
@@ -127,6 +135,6 @@
         SubDirectory => { TagTable => 'Image::ExifTool::H264::Camera2' },
     },
-    # 0x73 Lens - val: 0x75ffffd3,0x0effffd3,0x59ffffd3,0x79ffffd3,0xffffffd3...
-    # 0x74 Gain
+    # 0x73 Lens - val: 0x04ffffd3,0x0effffd3,0x15ffffd3,0x41ffffd3,0x52ffffd3,0x59ffffd3,0x65ffffd3,0x71ffffd3,0x75ffffd3,0x79ffffd3,0x7fffffd3,0xffffffd3...
+    # 0x74 Gain - val: 0xb8ffff0f
     # 0x75 Pedestal
     # 0x76 Gamma
@@ -292,4 +300,5 @@
         Notes => 'combined with tags 0xbc and 0xbd',
         ValueConv => 'Image::ExifTool::GPS::ConvertTimeStamp($val)',
+        PrintConv => 'Image::ExifTool::GPS::PrintTimeStamp($val)',
     },
     0xbe => {
@@ -368,4 +377,13 @@
     },
     # 0xc9-0xcf - GPSOption
+    # 0xc9 - val: 0x001d0203
+    0xca => { #PH (Sony DSC-HX7V)
+        Name => 'GPSDateStamp',
+        Format => 'string',
+        Groups => { 1 => 'GPS', 2 => 'Time' },
+        Combine => 2,    # the next 2 tags contain the rest of the string
+        Notes => 'combined with tags 0xcb and 0xcc',
+        ValueConv => 'Image::ExifTool::Exif::ExifDate($val)',
+    },
     0xe0 => {
         Name => 'MakeModel',
@@ -374,5 +392,4 @@
     # 0xe1-0xef - MakerOption
     # 0xe1 - val: 0x01000670,0x01000678,0x06ffffff,0x01ffffff,0x01000020,0x01000400...
-    # 0xe2-0xe8 - val: 0x00000000 in many samples
     0xe1 => { #6
         Name => 'RecInfo',
@@ -381,13 +398,19 @@
         SubDirectory => { TagTable => 'Image::ExifTool::H264::RecInfo' },
     },
+    # 0xe2-0xe8 - val: 0x00000000 in many samples
+    # 0xe2 - val: 0x00000000,0x01000000,0x01010000,0x8080900c,0x8080a074
+    # 0xe3 - val: 0x00801f89,0x00801f8b,0x00c01f89,0xc9c01f80
     0xe4 => { #PH
         Name => 'Model',
-        Condition => '$$self{Make} eq "Sony"',
+        Condition => '$$self{Make} eq "Sony"', # (possibly also Canon models?)
         Description => 'Camera Model Name',
-        Notes => 'Sony cameras only, combined with tags 0xe5 and 0xe6',
+        Notes => 'Sony only, combined with tags 0xe5 and 0xe6',
         Format => 'string',
         Combine => 2, # (not sure about 0xe6, but include it just in case)
         RawConv => '$val eq "" ? undef : $val',
     },
+    # 0xeb - val: 0x008a0a00,0x0a300000,0x508a0a00,0x52880a00,0x528a0a00
+    # 0xec - val: 0x0b700000
+    # 0xed - val: 0x0ce0f819
     0xee => { #6 (HFS200)
         Name => 'FrameInfo',
@@ -396,4 +419,5 @@
         SubDirectory => { TagTable => 'Image::ExifTool::H264::FrameInfo' },
     },
+    # 0xef - val: 0x01c00000,0x0e00000c
 );
 
@@ -417,17 +441,19 @@
         Name => 'Gain',
         Mask => 0x0f,
+        # (0x0f would translate to 42 dB, but this value is used by the Sony
+        #  HXR-NX5U for any out-of-range value such as -6 dB or "hyper gain" - PH)
         ValueConv => '($val - 1) * 3',
-        PrintConv => '"$val dB"',
+        PrintConv => '$val==42 ? "Out of range" : "$val dB"',
     },
     1.1 => {
         Name => 'ExposureProgram',
         Mask => 0xf0,
-        ValueConv => '$val == 0xf0 ? undef : $val',
-        PrintConv => {
-            0x00 => 'Program AE',
-            0x10 => 'Gain', #?
-            0x20 => 'Shutter speed priority AE',
-            0x30 => 'Aperture-priority AE',
-            0x40 => 'Manual',
+        ValueConv => '$val == 15 ? undef : $val',
+        PrintConv => {
+            0 => 'Program AE',
+            1 => 'Gain', #?
+            2 => 'Shutter speed priority AE',
+            3 => 'Aperture-priority AE',
+            4 => 'Manual',
         },
     },
@@ -435,10 +461,10 @@
         Name => 'WhiteBalance',
         Mask => 0xe0,
-        ValueConv => '$val == 0xe0 ? undef : $val',
-        PrintConv => {
-            0x00 => 'Auto',
-            0x20 => 'Hold',
-            0x40 => '1-Push',
-            0x60 => 'Daylight',
+        ValueConv => '$val == 7 ? undef : $val',
+        PrintConv => {
+            0 => 'Auto',
+            1 => 'Hold',
+            2 => '1-Push',
+            3 => 'Daylight',
         },
     },
@@ -448,5 +474,5 @@
         PrintConv => q{
             my $foc = ($val & 0x7e) / (($val & 0x01) ? 40 : 400);
-            return ($val & 0x80 ? 'Manual' : 'Auto') . " ($foc)";
+            return(($val & 0x80 ? 'Manual' : 'Auto') . " ($foc)");
         },
     },
@@ -462,6 +488,9 @@
     1 => {
         Name => 'ImageStabilization',
+        PrintHex => 1,
         PrintConv => {
             0 => 'Off',
+            0x3f => 'On (0x3f)', #8
+            0xbf => 'Off (0xbf)', #8
             0xff => 'n/a',
             OTHER => sub {
@@ -485,5 +514,5 @@
         Mask => 0x7fff, # (what is bit 0x8000 for?)
         RawConv => '$val == 0x7fff ? undef : $val', #7
-        ValueConv => '$val / 33640', #PH (conversion factor determined empirically)
+        ValueConv => '$val / 28125', #PH (Vixia HF G30, ref forum5588) (was $val/33640 until 9.49)
         PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
     },
@@ -502,10 +531,21 @@
         PrintConv => \%convMake,
     },
-    # 1 => ModelIDCode according to ref 4/5 (I think not)
-    # vals: 0x3001 - Sony HDR-CX105E/TG3E/XR500V
+    # 1 => ModelIDCode according to ref 4/5 (I think not - PH)
+    # 1 => { Name => 'ModelIDCode', PrintConv => 'sprintf("%.4x",$val)' },
+    # vals: 0x0313 - various Pansonic HDC models
+    #       0x0345 - Panasonic HC-V7272
+    #       0x0414 - Panasonic AG-AF100
+    #       0x0591 - various Panasonic DMC models
+    #       0x0802 - Panasonic DMC-TZ60 with GPS information off
+    #       0x0803 - Panasonic DMC-TZ60 with GPS information on
+    #       0x3001 - various Sony DSC, HDR, NEX and SLT models
+    #       0x3003 - various Sony DSC models
+    #       0x3100 - various Sony DSC, ILCE, NEX and SLT models
     #       0x1000 - Sony HDR-UX1
+    #       0x2000 - Canon HF100 (60i)
     #       0x3000 - Canon HF100 (30p)
-    #       0x2000 - Canon HF100 (60i)
     #       0x3101 - Canon HFM300 (PH, all qualities and frame rates)
+    #       0x3102 - Canon HFS200
+    #       0x4300 - Canon HFG30
 );
 
@@ -686,13 +726,14 @@
 #------------------------------------------------------------------------------
 # Parse H.264 sequence parameter set RBSP (ref 1)
-# Inputs) 0) ExifTool ref, 1) tag table ref, 2) data ref
+# Inputs: 0) ExifTool ref, 1) tag table ref, 2) data ref
+# Notes: All this just to get the image size!
 sub ParseSeqParamSet($$$)
 {
-    my ($exifTool, $tagTablePtr, $dataPt) = @_;
+    my ($et, $tagTablePtr, $dataPt) = @_;
     # initialize our bitstream object
     my $bstr = NewBitStream($dataPt) or return;
     my ($t, $i, $j, $n);
     # the messy nature of H.264 encoding makes it difficult to use
-    # data-driven structure parsing, so I code it explicitely (yuck!)
+    # data-driven structure parsing, so I code it explicitly (yuck!)
     $t = GetIntN($bstr, 8);         # profile_idc
     GetIntN($bstr, 16);             # constraints and level_idc
@@ -746,6 +787,6 @@
     return unless $$bstr{Mask};
     if ($w>=160 and $w<=4096 and $h>=120 and $h<=3072) {
-        $exifTool->HandleTag($tagTablePtr, ImageWidth => $w);
-        $exifTool->HandleTag($tagTablePtr, ImageHeight => $h);
+        $et->HandleTag($tagTablePtr, ImageWidth => $w);
+        $et->HandleTag($tagTablePtr, ImageHeight => $h);
         # (whew! -- so much work just to get ImageSize!!)
     }
@@ -778,6 +819,6 @@
     if ($t) {
         return if BitsLeft($bstr) < 65;
-        $$exifTool{VUI_units} = GetIntN($bstr, 32); # num_units_in_tick
-        $$exifTool{VUI_scale} = GetIntN($bstr, 32); # time_scale
+        $$et{VUI_units} = GetIntN($bstr, 32); # num_units_in_tick
+        $$et{VUI_scale} = GetIntN($bstr, 32); # time_scale
         GetIntN($bstr, 1);          # fixed_frame_rate_flag
     }
@@ -786,5 +827,5 @@
         $t = GetIntN($bstr, 1);     # nal_/vcl_hrd_parameters_present_flag
         if ($t) {
-            $$exifTool{VUI_hard} = 1;
+            $$et{VUI_hard} = 1;
             $hard = 1;
             $n = GetGolomb($bstr);  # cpb_cnt_minus1
@@ -796,11 +837,11 @@
             }
             GetIntN($bstr, 5);      # initial_cpb_removal_delay_length_minus1
-            $$exifTool{VUI_clen} = GetIntN($bstr, 5); # cpb_removal_delay_length_minus1
-            $$exifTool{VUI_dlen} = GetIntN($bstr, 5); # dpb_output_delay_length_minus1
-            $$exifTool{VUI_toff} = GetIntN($bstr, 5); # time_offset_length
+            $$et{VUI_clen} = GetIntN($bstr, 5); # cpb_removal_delay_length_minus1
+            $$et{VUI_dlen} = GetIntN($bstr, 5); # dpb_output_delay_length_minus1
+            $$et{VUI_toff} = GetIntN($bstr, 5); # time_offset_length
         }
     }
     GetIntN($bstr, 1) if $hard;     # low_delay_hrd_flag
-    $$exifTool{VUI_pic} = GetIntN($bstr, 1);    # pic_struct_present_flag
+    $$et{VUI_pic} = GetIntN($bstr, 1);    # pic_struct_present_flag
     # (don't yet decode the rest of the vui data)
 }
@@ -808,8 +849,10 @@
 #------------------------------------------------------------------------------
 # Parse H.264 picture timing SEI message (payload type 1) (ref 1)
-# Inputs) 0) ExifTool ref, 1) data ref
+# Inputs: 0) ExifTool ref, 1) data ref
+# Notes: this routine is for test purposes only, and not called unless the
+#        $parsePictureTiming flag is set
 sub ParsePictureTiming($$)
 {
-    my ($exifTool, $dataPt) = @_;
+    my ($et, $dataPt) = @_;
     my $bstr = NewBitStream($dataPt) or return;
     my ($i, $t, $n);
@@ -817,9 +860,9 @@
     # exist if the VUI hardware parameters are present, or if
     # "determined by the application, by some means not specified" -- WTF??
-    if ($$exifTool{VUI_hard}) {
-        GetIntN($bstr, $$exifTool{VUI_clen} + 1);   # cpb_removal_delay
-        GetIntN($bstr, $$exifTool{VUI_dlen} + 1);   # dpb_output_delay
-    }
-    if ($$exifTool{VUI_pic}) {
+    if ($$et{VUI_hard}) {
+        GetIntN($bstr, $$et{VUI_clen} + 1);   # cpb_removal_delay
+        GetIntN($bstr, $$et{VUI_dlen} + 1);   # dpb_output_delay
+    }
+    if ($$et{VUI_pic}) {
         $t = GetIntN($bstr, 4);     # pic_struct
         # determine NumClockTS ($n)
@@ -853,6 +896,6 @@
                 }
             }
-            if ($$exifTool{VUI_toff}) {
-                $o = GetIntN($bstr, $$exifTool{VUI_toff});  # time_offset
+            if ($$et{VUI_toff}) {
+                $o = GetIntN($bstr, $$et{VUI_toff});  # time_offset
             }
             last;   # only parse the first clock timestamp found
@@ -863,9 +906,29 @@
 #------------------------------------------------------------------------------
 # Process H.264 Supplementary Enhancement Information (ref 1/PH)
-# Inputs: 0) Exiftool ref, 1) dirInfo ref, 2) tag table ref
+# Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
 # Returns: 1 if we processed payload type 5
+# Payload types:
+#   0 - buffer period
+#   1 - pic timing
+#   2 - pan scan rect
+#   3 - filler payload
+#   4 - user data registered itu t t35
+#   5 - user data unregistered
+#   6 - recovery point
+#   7 - dec ref pic marking repetition
+#   8 - spare pic
+#   9 - sene info
+#  10 - sub seq info
+#  11 - sub seq layer characteristics
+#  12 - sub seq characteristics
+#  13 - full frame freeze
+#  14 - full frame freeze release
+#  15 - full frame snapshot
+#  16 - progressive refinement segment start
+#  17 - progressive refinement segment end
+#  18 - motion constrained slice group set
 sub ProcessSEI($$)
 {
-    my ($exifTool, $dirInfo) = @_;
+    my ($et, $dirInfo) = @_;
     my $dataPt = $$dirInfo{DataPt};
     my $end = length($$dataPt);
@@ -891,8 +954,9 @@
         }
         return 0 if $pos + $size > $end;
+        $et->VPrint(1,"    (SEI type $type)\n");
         if ($type == 1) {                   # picture timing information
             if ($parsePictureTiming) {
                 my $buff = substr($$dataPt, $pos, $size);
-                ParsePictureTiming($exifTool, $dataPt);
+                ParsePictureTiming($et, $dataPt);
             }
         } elsif ($type == 5) {              # unregistered user data
@@ -904,11 +968,7 @@
     # look for our 16-byte UUID
     # - plus "MDPM" for "ModifiedDVPackMeta"
-    # - plus "GA94" for closed-caption data (not currently decoded)
+    # - plus "GA94" for closed-caption data (currently not decoded)
     return 0 unless $size > 20 and substr($$dataPt, $pos, 20) eq
         "\x17\xee\x8c\x60\xf8\x4d\x11\xd9\x8c\xd6\x08\0\x20\x0c\x9a\x66MDPM";
-
-    # load the GPS module because it contains conversion routines and
-    # Composite tags needed for a number of tags we may be extracting
-    require Image::ExifTool::GPS;
 #
 # parse the MDPM records in the UUID 17ee8c60f84d11d98cd60800200c9a66
@@ -916,16 +976,16 @@
 #
     my $tagTablePtr = GetTagTable('Image::ExifTool::H264::MDPM');
-    my $oldIndent = $$exifTool{INDENT};
-    $$exifTool{INDENT} .= '| ';
+    my $oldIndent = $$et{INDENT};
+    $$et{INDENT} .= '| ';
     $end = $pos + $size;    # end of payload
     $pos += 20;             # skip UUID + "MDPM"
     my $num = Get8u($dataPt, $pos++);   # get entry count
     my $lastTag = 0;
-    $exifTool->VerboseDir('MDPM', $num) if $exifTool->Options('Verbose');
+    $et->VerboseDir('MDPM', $num) if $et->Options('Verbose');
     # walk through entries in the MDPM payload
     for ($index=0; $index<$num and $pos<$end; ++$index) {
         my $tag = Get8u($dataPt, $pos);
         if ($tag <= $lastTag) { # should be in numerical order (PH)
-            $exifTool->Warn('Entries in MDPM directory are out of sequence');
+            $et->Warn('Entries in MDPM directory are out of sequence');
             last;
         }
@@ -933,5 +993,5 @@
         my $buff = substr($$dataPt, $pos + 1, 4);
         my $from;
-        my $tagInfo = $exifTool->GetTagInfo($tagTablePtr, $tag);
+        my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
         if ($tagInfo) {
             # use our own print conversion for Unknown tags
@@ -953,5 +1013,5 @@
                 --$combine;
             }
-            $exifTool->HandleTag($tagTablePtr, $tag, undef,
+            $et->HandleTag($tagTablePtr, $tag, undef,
                 TagInfo => $tagInfo,
                 DataPt  => \$buff,
@@ -962,5 +1022,5 @@
         $pos += 5;
     }
-    $$exifTool{INDENT} = $oldIndent;
+    $$et{INDENT} = $oldIndent;
     return 1;
 }
@@ -972,7 +1032,7 @@
 sub ParseH264Video($$)
 {
-    my ($exifTool, $dataPt) = @_;
-    my $verbose = $exifTool->Options('Verbose');
-    my $out = $exifTool->Options('TextOut');
+    my ($et, $dataPt) = @_;
+    my $verbose = $et->Options('Verbose');
+    my $out = $et->Options('TextOut');
     my $tagTablePtr = GetTagTable('Image::ExifTool::H264::Main');
     my %parseNalUnit = ( 0x06 => 1, 0x07 => 1 );    # NAL unit types to parse
@@ -996,5 +1056,5 @@
         ++$pos;
         # check forbidden_zero_bit
-        $nal_unit_type & 0x80 and $exifTool->Warn('H264 forbidden bit error'), last;
+        $nal_unit_type & 0x80 and $et->Warn('H264 forbidden bit error'), last;
         $nal_unit_type &= 0x1f;
         # ignore this NAL unit unless we will parse it
@@ -1011,7 +1071,5 @@
         if ($verbose > 1) {
             printf $out "  NAL Unit Type: 0x%x (%d bytes)\n",$nal_unit_type, length $buff;
-            my %parms = ( Out => $out );
-            $parms{MaxLen} = 96 if $verbose < 4;
-            Image::ExifTool::HexDump(\$buff, undef, %parms) if $verbose > 2;
+            $et->VerboseDump(\$buff);
         }
         pos($$dataPt) = $pos = $nextPos;
@@ -1019,21 +1077,21 @@
         if ($nal_unit_type == 0x06) {       # sei_rbsp (supplemental enhancement info)
 
-            if ($$exifTool{GotNAL06}) {
+            if ($$et{GotNAL06}) {
                 # process only the first SEI unless ExtractEmbedded is set
-                next unless $exifTool->Options('ExtractEmbedded');
-                $$exifTool{DOC_NUM} = $$exifTool{GotNAL06};
+                next unless $et->Options('ExtractEmbedded');
+                $$et{DOC_NUM} = $$et{GotNAL06};
             }
-            $foundUserData = ProcessSEI($exifTool, { DataPt => \$buff } );
-            delete $$exifTool{DOC_NUM};
+            $foundUserData = ProcessSEI($et, { DataPt => \$buff } );
+            delete $$et{DOC_NUM};
             # keep parsing SEI's until we find the user data
             next unless $foundUserData;
-            $$exifTool{GotNAL06} = ($$exifTool{GotNAL06} || 0) + 1;
+            $$et{GotNAL06} = ($$et{GotNAL06} || 0) + 1;
 
         } elsif ($nal_unit_type == 0x07) {  # sequence_parameter_set_rbsp
 
             # process this NAL unit type only once
-            next if $$exifTool{GotNAL07};
-            $$exifTool{GotNAL07} = 1;
-            ParseSeqParamSet($exifTool, $tagTablePtr, \$buff);
+            next if $$et{GotNAL07};
+            $$et{GotNAL07} = 1;
+            ParseSeqParamSet($et, $tagTablePtr, \$buff);
         }
         # we were successful, so don't parse this NAL unit type again
@@ -1042,6 +1100,6 @@
     # parse one extra H264 frame if we didn't find the user data in this one
     # (Panasonic cameras don't put the SEI in the first frame)
-    return 0 if $foundUserData or $$exifTool{ParsedH264};
-    $$exifTool{ParsedH264} = 1;
+    return 0 if $foundUserData or $$et{ParsedH264};
+    $$et{ParsedH264} = 1;
     return 1;
 }
@@ -1066,5 +1124,5 @@
 =head1 AUTHOR
 
-Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
+Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
 
 This library is free software; you can redistribute it and/or modify it
