wanadev / mozjpeg-lossless-optimization

Python library to optimize JPEGs losslessly using MozJPEG
Other
34 stars 2 forks source link

Doesn't encode with Progressive DCT as advertised. #13

Closed ajslater closed 4 months ago

ajslater commented 7 months ago

In my testing of this code, output is larger than running the mozjpeg jpegtran command line tool with -optimize and -progressive. Additionally exiftool reports that it was encoded with the Baseline transform, not the Progressive transform.

Input

$ ls -l input.jpg
-rw-r--r--  1 aj  staff  97373 Jan 30 15:08 input.jpg

$ exiftool input.jpg | grep Encoding
Encoding Process                : Baseline DCT, Huffman coding

mozjpgeg-lossless-optimization

$ ls -l output_from_mozjpeg-lossless-optimization.jpg
-rw-r--r--  1 aj  staff  93057 Jan 30 15:14 output_from_mozjpeg-lossless-optimization.jpg

$ exiftool output_from_mozjpeg-lossless-optimization.jpg | grep Encoding
Encoding Process                : Baseline DCT, Huffman coding

mozjpeg cli

$ ls -l output_from_mozjpeg-cli.jpg
-rw-r--r--  1 aj  staff  83657 Jan 30 15:15 output_from_mozjpeg-cli.jpg

$ exiftool output_from_mozjpeg-cli.jpg | grep Encoding
Encoding Process                : Progressive DCT, Huffman coding
flozz commented 7 months ago

Hello,

I am not able to reproduce the issue. I encoded a JPEG with the following code:

#!/usr/bin/env python3

import mozjpeg_lossless_optimization

with open("./photo.jpg", "rb") as input_jpeg_file:
    input_jpeg_bytes = input_jpeg_file.read()

output_jpeg_bytes = mozjpeg_lossless_optimization.optimize(input_jpeg_bytes)

with open("./out.jpg", "wb") as output_jpeg_file:
    output_jpeg_file.write(output_jpeg_bytes)

Results for me are:

-rw-rw-r-- 1 fabien fabien 1,8M juin   8  2013 photo.jpg
-rw-rw-r-- 1 fabien fabien 1,6M janv. 31 14:45 out.jpg
$ exiftool photo.jpg | grep Encoding
Encoding Process                : Baseline DCT, Huffman coding

$ exiftool out.jpg | grep Encoding 
Encoding Process                : Progressive DCT, Huffman coding

I also tried to truncate the files to be sure, and we can see that there is a missing part on the input image (scanline) and that on the other one it is pixelated (progressive):

Capture d’écran du 2024-01-31 14-55-43

I tried with both my development version and a package on PyPI (mozjpeg_lossless_optimization-1.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl)


Can you tel me more to help me reproducing this?

:)

ajslater commented 4 months ago

My apologies for not noticing your response earlier this year. Got lost in my email.

I've just tried to to replicate the results of this issue with a couple different jpegs including the 97373 byte input file from the original issue and I cannot. I'm unsure if the 1.1.3 version of mozjpeg-lossless-optimization changed or (more likely) there was a flaw with my experiments that lead me to file this issue report.

Thanks for making these bindings and taking the time to try to reproduce.