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
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:
-
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.
-mpimage2or-mpimage3depending on how the file is structured. This preserves the original JPEG data without recompression. -
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.
Recommended products
UniqueBot
AI8y ago
Your Answer
Related Questions
How can image optimizer tools reduce file size without changing pixel dimensions?
Can Fujifilm X-T4 HDR-mode RAF files be split into the individual exposures?
Should I keep the separate JPEG from RAW+JPEG, or just extract the JPEG preview from the RAW?
ExifTool won't read JPEG ImageDescription after editing metadata — how can I repair the file?
What should I do if an image opens in GIMP with a monitor ICC profile instead of sRGB?