How can I losslessly extract a single 2D JPEG from a stereoscopic MPO/JPEG file on Linux?

Asked 8/18/2017

5 views

2 answers

0

I have images exported from a Nintendo 3DS that are stored as stereoscopic JPEG/MPO-style files containing two JPEG images. For web use, I only need one view and want to reduce file size without recompressing the image. Is there a Linux-compatible way to extract just one embedded JPEG losslessly, while optionally preserving or later stripping metadata?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

8y ago

2 Answers

2

Here is a bash script that extracts left-right stereo pairs from mpo files using exiftool. Depending on the source of the file, the right image may be stored within a different tag.

#!/usr/bin/env bash

for i in *.mpo ; do
    j="${i#*/}"
    k="${j%.mpo}"

    # extract left images
    exiftool -trailer:all= "$i" -o "${k}.left.jpg"
    exiftool -TagsFromFile "$i" "${k}.left.jpg"

    # extract right images
    if exiftool "$i" | grep "MP Image 3" ; then
        # Samsung NX 45mm f/1.8 2D/3D
        exiftool "$i" -mpimage3 -b > "${k}.right.jpg"
        exiftool -TagsFromFile "$i" "${k}.right.jpg"
    else
        # Fujifilm Real 3D W3
        exiftool "$i" -mpimage2 -b > "${k}.right.jpg"
        exiftool -TagsFromFile "$i" "${k}.right.jpg"
    fi
done

Originally by user75526. Source · Licensed CC BY-SA 4.0

user75526

7y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. To keep it lossless, don’t re-save the file through an editor; extract one of the embedded JPEG streams directly.

Two approaches mentioned:

  1. Use ExifTool on MPO/stereo files. You can extract the left image by removing the trailer, and the right image from the MP image tags, e.g. -mpimage2 or -mpimage3 depending on how the file is structured. This preserves the original JPEG data without recompression.

  2. Since JPEG images start with the marker FF D8 FF, you can also locate the second JPEG start marker in a hex editor or script and truncate the file before it. That leaves the first JPEG intact, again without quality loss.

This is preferable to opening the file in GIMP or ImageMagick and exporting again, which would normally recompress the JPEG and may reduce quality.

Also note: stereo files usually contain two similar but not identical views, not true duplicates, so you’re choosing one view rather than removing an exact copy. Metadata can be copied with ExifTool or stripped afterward with your usual EXIF tool.

UniqueBot

AI

8y ago

Your Answer