ajslater / picopt

A multi format lossless image optimizer that uses external tools
GNU General Public License v3.0
108 stars 11 forks source link

Support MPO #11

Closed rallant92 closed 7 months ago

rallant92 commented 8 years ago

Almost all of my jpeg pictures from various cameras aren't compressing:

picopt -r *
Didn't optimize any files.

Stepping through the code the file is being recognized by PIL as MPO. These are jpeg files with a smaller photo embedded as a thumbnail, commonly done by cameras to speed viewing.

Here's some discussion: https://github.com/python-pillow/Pillow/issues/1138

  1. Can picopt be updated to compress these jpg files? I have tried jpegrescan and it successfully compresses the files.
  2. Figuring this out was a PITA because the error message is not helpful:
picopt -r P1000223.JPG
Didn't optimize any files.

Can picopt better describe why it won't optimize the file, at least when a single file targeted? Maybe something like one of "Not an image or "Image type foo not recognized"

ajslater commented 8 years ago

shouldn't be hard at all. But could you attach an unoptimized test MPO file to this issue report for me?

rallant92 commented 8 years ago

I've added a jpeg that does't optimize. My software to resize it smaller also strips the EXIF info, and therefore fails to demonstrate the problem. I"m hoping this comment system also doesn't strip the info.

p1020437

ajslater commented 8 years ago

Downloading it saves it as a .jpg and picopt/PIL detects it as type JPEG and then mozjpeg compresses it by 3.54%.

Maybe take your MPO file and conceal it in a zip or tarball so it's not processed by github.

ajslater commented 6 years ago

unreproduceable

ajslater commented 4 years ago

I just replicated this exact issue with some GoPro files that the camera exports with the .JPG suffix but PIL recognizes them as ANIMATED_MPO.

ajslater commented 2 years ago

I'd like to work on this, but I'm searching for a tool that explodes MPO files without losing any JPEG fidelity and a tool that creates MPO files from multiple JPEGS.

The python Pillow library can read MPOs, but it lacks a facility for saving these JPEGS without re-encoding them. Pillow cannot create MPOs.

ajslater commented 7 months ago

picopt 4.0.0 now supports converting MPOs to regular JPEGS if and only if the MPO has a "Baseline MP Primary Image" tagged.

MPOs contain a series of JPEGS and are used for many different purposes. I think the original conception was for stereo images. For stereo images there is a left and right JPEG, but no primary jpeg. Picopt should not convert these files.

Probably the largest actual usage of MPO is storing thumbnails inside the same file as the primary image. This is frequently done by digital cameras. When you convert MPOs to JPEG with picopt, the primary image is extracted and losslessly optimized and the thumbnails are discarded.