Fixing corrupted MPO files

Started by gemlion, October 01, 2013, 07:29:22 PM

Previous topic - Next topic

gemlion

Hi Phil,

I've been using exiftool several times for extracting left and right image from MPO files, thank you for this great tool. I was travelling for about a year and took many 3D photos with a Fujifilm W3. But after I organized (and editing captions, titles a.s.o.) all my photos with digiKam (which uses exiv2), my W3 camera and Geeqie where not able to display my MPO photos in stereo mode anymore.

Another software (StereoPhoto Maker) is still able to display them, therefore I know the images are still there.

This is what I get:

with a still working file

exiftool -all= --exif:all -o %f_right.jpg "working.MPO"
1 image files created

./exiftool -mpimage2 -b -w %f2_left.jpg "working.MPO"
1 image files created


with a corrupted file

exiftool -all= --exif:all -o %f_right.jpg "corrupted.MPO"
1 image files created

./exiftool -mpimage2 -b -w %f2_left.jpg "corrupted.MPO"
Warning: [minor] MPImage2 is not a valid JPEG image - corrupted.MPO
    0 output files created



Is there a way to fix these files with exiftool? Any help is very apreciated.

Cheers,
Gem

Attached:

working.MPO http://ubuntuone.com/6gdlv6gN3uIYCDtVKMenVI

currupted.MPO http://ubuntuone.com/5eaJXyUhtLT0EZhk7gHpU1

Edit: I had a look at both files with -htmldump. There seem to be differences at the end of them, but I don't know what they mean.

Phil Harvey

Hi Gem,

The MPF offsets have been invalidated due to a COM segment that was added.  The following command will fix this by deleting the comment:

exiftool -comment= corrupted.MPO

See my comments on the MPF format for more details about this problem.

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

gemlion

I think I might have found out what causes the problem:

MPO files contain MPF Exif Information.

The tag MPImageStart contains information where the second image in a MPO image begins. When adding a comment or GPS-Coordinates to a MPO image, the position of the second image changes and MPImageStart has to be updated. I think Exiv2 does not update this tag and therefore programs looking for a jpeg at the position provided by MPImageStart cannot find one.

I think to fix these files I would have to find out where the second jpeg starts and update the MPImageStart Tag - please correct me if I am mistaken. Is there a way to do this with ExifTool?

Cheers, Gem

gemlion

Oh, you where just answering, when I was updating :D Is what I was thinking correct?

Phil Harvey

Exactly.  Except that adding GPS coordinates should be OK because the EXIF segment comes before the MPF segment.

Actually, adding a comment with ExifTool is OK too, because ExifTool shouldn't add any segments after the MPF segment.

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

gemlion

Alright, thank you. Therefore I will add this to my Bugreport at Exiv2, since I am using digiKam which unforunately does not use ExifTool. Thank you so much, these pictues are very important to me.

Edit: is there a way to just move comments in a MPO file with ExifTool without deleting them?

Edit2: Tried your idea and it worked, thank you, thank you, thank you

Solution: exiftool -comment= corrupted.MPO

Phil Harvey

Quote from: gemlion on October 02, 2013, 07:48:22 AM
is there a way to just move comments in a MPO file with ExifTool without deleting them?

This must be done in 2 steps because ExifTool preserves the location of the COM segment if it already existed.

Step 1) copy the comment to another tag and delete the comment:

exiftool "-SOMETAG<comment" -comment= FILE

Step 2) re-create the comment and delete the temporary tag:

exiftool "-comment<SOMETAG" -SOMETAG= FILE

The SOMETAG I would have recommended for this purpose is EXIF:ImageDescription, which (not coincidentally) already contains the comment in the sample you posted.  So in this specific case, the file may be fixed like this (with the 2 commands combined into a single command line):

exiftool -comment= -execute "-comment<imagedescription" -common_args FILE

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

gemlion

Thank you. ;D You saved the day for me.