Patch for quicktime extended atom sizes

Started by cmcfadden, March 18, 2013, 10:02:42 AM

Previous topic - Next topic

cmcfadden

Here's a quick patch to add support for Quicktime Extended Size fields (see page 23 of QTFF) - this will allow exiftool to handle QT media over 4gig with the MDAT at the head of the file (IE, not faststart).


--- QuickTime.pm   2013-03-18 08:57:48.000000000 -0500
+++ /usr/local/Cellar/exiftool/9.23/libexec/lib/Image/ExifTool/QuickTime.pm   2013-03-18 08:57:59.000000000 -0500
@@ -2892,7 +2892,7 @@
     my $verbose = $exifTool->Options('Verbose');
     my $dataPos = $$dirInfo{Base} || 0;
     my $charsetQuickTime = $exifTool->Options('CharsetQuickTime');
-    my ($buff, $tag, $size, $track, $isUserData, %triplet);
+    my ($buff, $tag, $size, $size1, $size2, $track, $isUserData, %triplet);

     # more convenient to package data as a RandomAccess file
     $raf or $raf = new File::RandomAccess($dataPt);
@@ -2910,6 +2910,13 @@
         $tagTablePtr = GetTagTable('Image::ExifTool::QuickTime::Main');
     }
     ($size, $tag) = unpack('Na4', $buff);
+    if($size == 1) {
+        $raf->Read($buff, 8) == 8 or return 0;
+        $dataPos += 8;
+        ($size1, $size2) = unpack('Na4', $buff);
+        $size = $size1 << 32 | $size2;
+    }
+
     if ($dataPt) {
         $verbose and $exifTool->VerboseDir($$dirInfo{DirName});
     } else {

Phil Harvey

Thanks for this patch, but I thought that this should already work provided you enable the LargeFileSupport option (probably via the config file).  If you look a bit further down in the code, you will see this before $size is used:

        if ($size < 8) {
            last if $size == 0;
            $size == 1 or $exifTool->Warn('Invalid atom size'), last;
            $raf->Read($buff, 8) == 8 or last;
            $dataPos += 8;
            my ($hi, $lo) = unpack('NN', $buff);
            $size = $lo;
            if ($hi or $lo > 0x7fffffff) {
                if ($hi > 0x7fffffff) {
                    $exifTool->Warn('Invalid atom size');
                    last;
                } elsif (not $exifTool->Options('LargeFileSupport')) {
                    $exifTool->Warn('End of processing at large atom (LargeFileSupport not enabled)');
                    last;
                }
            }
            $size = $hi * 4294967296 + $lo;
        }


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

cmcfadden

Ah indeed - looks like there's just a bug with that code, so it doesn't actually work right now.  The extended size counts from the start of the atom, not from the start of the extended size, so you need to either remove 8 from the new size, or rewind 8:

$size = $hi * 4294967296 + $lo;
$dataPos -=8;
$raf->Seek(-8, 1);

(then 8 bytes get subtracted again a couple lines later to deal with the actual atom size / type)

Phil Harvey

Ah.  But doesn't your earlier patch suffer the same problem?

Does the original code work with this patch?: (I don't have a file that I can test this with)

-            $size = $hi * 4294967296 + $lo;
+            $size = $hi * 4294967296 + $lo - 8;

Thanks for helping with 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 ($).

cmcfadden

That code works too.  Here's a sample file that uses extended sizes, if you'd like to try locally:
https://www.dropbox.com/s/032mt1c7cpt5vu6/00003.mov?m

Phil Harvey

Great!  Thanks for the sample.  I can confirm that this works for me.

This patch will appear in ExifTool 9.24.

Thanks for improving ExifTool!

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

psterling

I'm very interested in the new version that incorporates this fix, as my workflow could greatly benefit from it as well.  Thanks for your great tool, and hopefully version 9.24 is released very soon!  I wish I could "subscribe" to this forum, but I guess I'll be checking back every day :-)

Phil Harvey

I plan to release version 9.24 this coming Saturday (March 23).

You can subscribe to receive emails from either a whole forum board, or from a specific topic.  This is what the "Notify" button does, but I probably won't post here when I issue the new version so this may not help anyway.

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